class Hubspot::OAuth

Constants

DEFAULT_OAUTH_HEADERS

Public Class Methods

authorize_url(scopes, params={}) click to toggle source
# File lib/hubspot/oauth.rb, line 20
def authorize_url(scopes, params={})
  client_id = params[:client_id] || Hubspot::Config.client_id
  redirect_uri = params[:redirect_uri] || Hubspot::Config.redirect_uri
  scopes = Array.wrap(scopes)

  "https://app.hubspot.com/oauth/authorize?client_id=#{client_id}&scope=#{scopes.join("%20")}&redirect_uri=#{redirect_uri}"
end
create(code, params={}, options={}) click to toggle source
# File lib/hubspot/oauth.rb, line 15
def create(code, params={}, options={})
  oauth_post(token_url, { grant_type: "authorization_code", code: code }.merge(params),
    options)
end
oauth_post(url, params, options={}) click to toggle source
# File lib/hubspot/oauth.rb, line 32
def oauth_post(url, params, options={})
  no_parse = options[:no_parse] || false

  body = {
    client_id: Hubspot::Config.client_id,
    client_secret: Hubspot::Config.client_secret,
    redirect_uri: Hubspot::Config.redirect_uri,
  }.merge(params)

  response = post(url, body: body, headers: DEFAULT_OAUTH_HEADERS)
  log_request_and_response url, response, body

  raise(Hubspot::RequestError.new(response)) unless response.success?

  no_parse ? response : response.parsed_response
end
refresh(token, params={}, options={}) click to toggle source
# File lib/hubspot/oauth.rb, line 10
def refresh(token, params={}, options={})
  oauth_post(token_url, { grant_type: "refresh_token", refresh_token: token }.merge(params),
    options)
end
token_url() click to toggle source
# File lib/hubspot/oauth.rb, line 28
def token_url
  token_url = Hubspot::Config.base_url + "/oauth/v1/token"
end