class Juno::Authorization

Public Class Methods

refresh_token() click to toggle source
# File lib/juno/authorization.rb, line 12
def refresh_token
  @token = access_token
end
token() click to toggle source
# File lib/juno/authorization.rb, line 8
def token
  @token ||= access_token
end

Private Class Methods

access_token() click to toggle source
# File lib/juno/authorization.rb, line 18
def access_token
  url = Juno.configuration.endpoint_for(:authorization)

  response = HTTP.headers(headers).post("#{url}/oauth/token", form: { grant_type: :client_credentials })

  case response.code
  when 200
    JSON.parse(response.body.to_s)['access_token']
  else
    raise 'Invalid authorization'
  end
end
headers() click to toggle source
# File lib/juno/authorization.rb, line 31
def headers
  credentials = [Juno.configuration.client_id, Juno.configuration.client_secret].map(&:to_s).join(':')

  encoded_credentials = Base64.encode64(credentials).tr("\n", '')

  {
    'Content-Type' => 'application/x-www-form-urlencoded',
    'Authorization' => "Basic #{encoded_credentials}"
  }
end