Class: Monri::AccessTokens

Inherits:
Object
  • Object
show all
Defined in:
lib/monri/access_tokens.rb,
lib/monri/access_tokens/create_response.rb

Defined Under Namespace

Classes: CreateResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configMonri::Config

Returns:



5
6
7
# File 'lib/monri/access_tokens.rb', line 5

def config
  @config
end

#http_client=(value) ⇒ Monri::HttpClient (writeonly)

Returns:



8
9
10
# File 'lib/monri/access_tokens.rb', line 8

def http_client=(value)
  @http_client = value
end

Instance Method Details

#create(options) ⇒ Monri::AccessTokens::CreateResponse

Parameters:

  • options (Hash)

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/monri/access_tokens.rb', line 23

def create(options)
  Monri::AccessTokens::CreateResponse.create do
    body = {
      client_id: config.authenticity_token,
      client_secret: config.merchant_key,
      grant_type: 'client_credentials',
      scopes: options.delete(:scopes) || []
    }
    response = @http_client.post('/v2/oauth', body)
    if response.failed?
      raise response.exception
    elsif response.success?
      response.body
    else
      # TODO: handle this case
    end
  end

end

#create!(options) ⇒ Monri::AccessTokens::CreateResponse

Parameters:

  • options (Hash)

Returns:



12
13
14
15
16
17
18
19
# File 'lib/monri/access_tokens.rb', line 12

def create!(options)
  rv = create(options)
  if rv.failed?
    #noinspection RubyMismatchedArgumentType
    raise rv.exception
  end
  rv
end