Class: LedgerSync::Adaptors::NetSuite::Token
- Inherits:
-
Object
- Object
- LedgerSync::Adaptors::NetSuite::Token
- Defined in:
- lib/ledger_sync/adaptors/netsuite/token.rb
Constant Summary collapse
- DEFAULT_SIGNATURE_METHOD =
'HMAC-SHA256'
- OAUTH_VERSION =
'1.0'
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#body_json_string ⇒ Object
readonly
Returns the value of attribute body_json_string.
-
#consumer_key ⇒ Object
readonly
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
readonly
Returns the value of attribute consumer_secret.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#signature_method ⇒ Object
readonly
Returns the value of attribute signature_method.
-
#token_id ⇒ Object
readonly
Returns the value of attribute token_id.
-
#token_secret ⇒ Object
readonly
Returns the value of attribute token_secret.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #alphanumerics ⇒ Object
- #headers(realm:) ⇒ Object
-
#initialize(body: {}, consumer_key:, consumer_secret:, method:, nonce: nil, signature_method: nil, timestamp: nil, token_id:, token_secret:, url:) ⇒ Token
constructor
A new instance of Token.
- #nonce ⇒ Object
- #signature ⇒ Object
- #signature_data_string ⇒ Object
- #signature_key ⇒ Object
- #timestamp ⇒ Object
Constructor Details
#initialize(body: {}, consumer_key:, consumer_secret:, method:, nonce: nil, signature_method: nil, timestamp: nil, token_id:, token_secret:, url:) ⇒ Token
Returns a new instance of Token.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 22 def initialize(body: {}, consumer_key:, consumer_secret:, method:, nonce: nil, signature_method: nil, timestamp: nil, token_id:, token_secret:, url:) @body = body || {} @body_json_string = body.to_json @consumer_key = consumer_key @consumer_secret = consumer_secret @method = method.to_s.upcase @nonce = nonce @signature_method = signature_method || DEFAULT_SIGNATURE_METHOD @timestamp = @token_id = token_id @token_secret = token_secret @url = url end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 12 def body @body end |
#body_json_string ⇒ Object (readonly)
Returns the value of attribute body_json_string.
12 13 14 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 12 def body_json_string @body_json_string end |
#consumer_key ⇒ Object (readonly)
Returns the value of attribute consumer_key.
12 13 14 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 12 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object (readonly)
Returns the value of attribute consumer_secret.
12 13 14 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 12 def consumer_secret @consumer_secret end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
12 13 14 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 12 def method @method end |
#signature_method ⇒ Object (readonly)
Returns the value of attribute signature_method.
12 13 14 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 12 def signature_method @signature_method end |
#token_id ⇒ Object (readonly)
Returns the value of attribute token_id.
12 13 14 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 12 def token_id @token_id end |
#token_secret ⇒ Object (readonly)
Returns the value of attribute token_secret.
12 13 14 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 12 def token_secret @token_secret end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
12 13 14 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 12 def url @url end |
Instance Method Details
#alphanumerics ⇒ Object
36 37 38 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 36 def alphanumerics [*'0'..'9', *'A'..'Z', *'a'..'z'] end |
#headers(realm:) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 40 def headers(realm:) @headers ||= begin = [ [:realm, realm], [:oauth_consumer_key, escape(consumer_key)], [:oauth_token, escape(token_id)], [:oauth_signature_method, signature_method], [:oauth_timestamp, ], [:oauth_nonce, escape(nonce)], [:oauth_version, OAUTH_VERSION], [:oauth_signature, escape(signature)] ] ret = { 'Authorization' => "OAuth #{.map { |k, v| "#{k}=\"#{v}\"" }.join(',')}" } ret end end |
#nonce ⇒ Object
61 62 63 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 61 def nonce @nonce ||= Array.new(20) { alphanumerics.sample }.join end |
#signature ⇒ Object
65 66 67 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 65 def signature @signature ||= compute_digest(signature_data_string) end |
#signature_data_string ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 70 def signature_data_string @signature_data_string ||= begin [ method, escape(url_without_params), escape(parameters_string) ].join('&') end end |
#signature_key ⇒ Object
80 81 82 83 84 85 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 80 def signature_key @signature_key ||= [ consumer_secret, token_secret ].join('&') end |
#timestamp ⇒ Object
87 88 89 |
# File 'lib/ledger_sync/adaptors/netsuite/token.rb', line 87 def @timestamp ||= Time.now.to_i end |