Class: LedgerSync::NetSuite::Token
- Inherits:
-
Object
- Object
- LedgerSync::NetSuite::Token
- Defined in:
- lib/ledger_sync/netsuite/token.rb
Constant Summary collapse
- DEFAULT_SIGNATURE_METHOD =
'HMAC-SHA256'
- OAUTH_VERSION =
'1.0'
Instance Attribute Summary collapse
-
#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.
-
#oauth_version ⇒ Object
readonly
Returns the value of attribute oauth_version.
-
#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(args = {}) ⇒ Token
constructor
A new instance of Token.
- #nonce ⇒ Object
- #signature ⇒ Object
- #signature_data_string ⇒ Object
- #signature_key ⇒ Object
- #timestamp ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Token
Returns a new instance of Token.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ledger_sync/netsuite/token.rb', line 20 def initialize(args = {}) @consumer_key = args.fetch(:consumer_key) @consumer_secret = args.fetch(:consumer_secret) @method = args.fetch(:method).to_s.upcase @nonce = args.fetch(:nonce, nil) @oauth_version = args.fetch(:oauth_version, nil) || self.class::OAUTH_VERSION @signature_method = args.fetch(:signature_method, nil) || self.class::DEFAULT_SIGNATURE_METHOD @timestamp = args.fetch(:timestamp, nil) @token_id = args.fetch(:token_id) @token_secret = args.fetch(:token_secret) @url = args.fetch(:url) end |
Instance Attribute Details
#consumer_key ⇒ Object (readonly)
Returns the value of attribute consumer_key.
11 12 13 |
# File 'lib/ledger_sync/netsuite/token.rb', line 11 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object (readonly)
Returns the value of attribute consumer_secret.
11 12 13 |
# File 'lib/ledger_sync/netsuite/token.rb', line 11 def consumer_secret @consumer_secret end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
11 12 13 |
# File 'lib/ledger_sync/netsuite/token.rb', line 11 def method @method end |
#oauth_version ⇒ Object (readonly)
Returns the value of attribute oauth_version.
11 12 13 |
# File 'lib/ledger_sync/netsuite/token.rb', line 11 def oauth_version @oauth_version end |
#signature_method ⇒ Object (readonly)
Returns the value of attribute signature_method.
11 12 13 |
# File 'lib/ledger_sync/netsuite/token.rb', line 11 def signature_method @signature_method end |
#token_id ⇒ Object (readonly)
Returns the value of attribute token_id.
11 12 13 |
# File 'lib/ledger_sync/netsuite/token.rb', line 11 def token_id @token_id end |
#token_secret ⇒ Object (readonly)
Returns the value of attribute token_secret.
11 12 13 |
# File 'lib/ledger_sync/netsuite/token.rb', line 11 def token_secret @token_secret end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
11 12 13 |
# File 'lib/ledger_sync/netsuite/token.rb', line 11 def url @url end |
Instance Method Details
#alphanumerics ⇒ Object
33 34 35 |
# File 'lib/ledger_sync/netsuite/token.rb', line 33 def alphanumerics [*'0'..'9', *'A'..'Z', *'a'..'z'] end |
#headers(realm:) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ledger_sync/netsuite/token.rb', line 37 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
58 59 60 |
# File 'lib/ledger_sync/netsuite/token.rb', line 58 def nonce @nonce ||= Array.new(20) { alphanumerics.sample }.join end |
#signature ⇒ Object
62 63 64 |
# File 'lib/ledger_sync/netsuite/token.rb', line 62 def signature @signature ||= compute_digest(signature_data_string) end |
#signature_data_string ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/ledger_sync/netsuite/token.rb', line 67 def signature_data_string @signature_data_string ||= [ method, escape(url_without_params), escape(parameters_string) ].join('&') end |
#signature_key ⇒ Object
75 76 77 78 79 80 |
# File 'lib/ledger_sync/netsuite/token.rb', line 75 def signature_key @signature_key ||= [ consumer_secret, token_secret ].join('&') end |
#timestamp ⇒ Object
82 83 84 |
# File 'lib/ledger_sync/netsuite/token.rb', line 82 def @timestamp ||= Time.now.to_i end |