Class: Roqua::CoreApi::Sessions::HmacAuthRequest

Inherits:
AuthSession
  • Object
show all
Defined in:
lib/roqua/core_api/sessions/hmac_auth_request.rb

Overview

Make a single hmac signed request. HmacAuthRequest.new(consumer_key: ‘mykey’, consumer_secret: ‘…’) HmacAuthRequest.new(consumer_key: ‘mykey’, hmac: ‘…’, nonce: ‘…’, timestamp: 1467704698)

Instance Attribute Summary collapse

Attributes inherited from AuthSession

#core_site, #default_timeout

Instance Method Summary collapse

Methods inherited from AuthSession

#delete, #get, #patch, #post

Constructor Details

#initialize(consumer_key: ENV.fetch('CORE_CONSUMER_KEY'), consumer_secret: ENV.fetch('CORE_CONSUMER_SECRET'), timestamp: Time.now.to_i, nonce: SecureRandom.urlsafe_base64(32), hmac: nil, **additional_arguments) ⇒ HmacAuthRequest

Returns a new instance of HmacAuthRequest.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/roqua/core_api/sessions/hmac_auth_request.rb', line 10

def initialize(consumer_key: ENV.fetch('CORE_CONSUMER_KEY'),
               consumer_secret: ENV.fetch('CORE_CONSUMER_SECRET'),
               timestamp: Time.now.to_i,
               nonce: SecureRandom.urlsafe_base64(32),
               hmac: nil,
               **additional_arguments)
  @consumer_key = consumer_key
  @consumer_secret = consumer_secret
  @timestamp = timestamp
  @nonce = nonce
  @hmac = hmac
  super(**additional_arguments)
end

Instance Attribute Details

#consumer_keyObject (readonly)

Returns the value of attribute consumer_key.



8
9
10
# File 'lib/roqua/core_api/sessions/hmac_auth_request.rb', line 8

def consumer_key
  @consumer_key
end

#consumer_secretObject (readonly)

Returns the value of attribute consumer_secret.



8
9
10
# File 'lib/roqua/core_api/sessions/hmac_auth_request.rb', line 8

def consumer_secret
  @consumer_secret
end

#nonceObject (readonly)

Returns the value of attribute nonce.



8
9
10
# File 'lib/roqua/core_api/sessions/hmac_auth_request.rb', line 8

def nonce
  @nonce
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



8
9
10
# File 'lib/roqua/core_api/sessions/hmac_auth_request.rb', line 8

def timestamp
  @timestamp
end

Instance Method Details

#access_denied(response) ⇒ Object

handle 401 response.



29
30
31
# File 'lib/roqua/core_api/sessions/hmac_auth_request.rb', line 29

def access_denied(response)
  fail Unauthorized, response
end

#headers(request_method, path, params) ⇒ Object



24
25
26
# File 'lib/roqua/core_api/sessions/hmac_auth_request.rb', line 24

def headers(request_method, path, params)
  {'Authorization' => "HMAC #{consumer_key}:#{hmac(request_method, path, params)}:#{nonce}:#{timestamp}"}
end