class Gocoin::Auth

Constants

REQUIRED_CODE_PARAMS

Attributes

client[R]

Public Class Methods

new(client) click to toggle source
# File lib/gocoin/auth.rb, line 8
def initialize(client)
  @client = client
end

Public Instance Methods

authenticate(options = {}) click to toggle source
# File lib/gocoin/auth.rb, line 12
def authenticate(options = {})
  @client.logger.debug 'Gocoin::Auth#authenticate method called.'

  headers = @client.headers.merge(options[:headers] || {})
  options = @client.options.merge options
  verify_required_params options
  route = '/oauth/token'

  config = {
    url: "#{@client.http_prefix}#{@client.options[:host]}#{@client.port}#{@client.options[:path]}/#{@client.options[:api_version]}#{route}",
    method: 'POST',
    headers: headers,
    payload: options.to_json
  }

  @client.raw_request config
end
construct_code_url(params) click to toggle source
# File lib/gocoin/auth.rb, line 30
def construct_code_url(params)
  "https://#{@client.options[:dashboard_host]}/auth?#{Util.hash_to_url_params(params)}"
end

Private Instance Methods

verify_required_params(options) click to toggle source
# File lib/gocoin/auth.rb, line 36
def verify_required_params(options)
  if options[:grant_type] == 'authorization_code'
    required = REQUIRED_CODE_PARAMS
  else
    raise 'Gocoin::Auth#authenticate: grant_type was not defined properly or is unsupported'
  end      

  @client.logger.debug "Required params: #{required}"
  required.each do |required_attribute|
    raise "Gocoin::Auth#authenticate requires '#{required_attribute}' option." unless options[required_attribute.to_sym]
  end
  options
end