Class: HmacSignature::Credentials
- Inherits:
-
Object
- Object
- HmacSignature::Credentials
- Defined in:
- lib/hmac_signature/credentials.rb
Constant Summary collapse
- HEADER_CREDENTIAL_REGEXES =
[/^x-auth-(.+)$/i, /^http_x_auth_(.+)$/i]
- PARAM_CREDENTIAL_REGEX =
/^auth_(.+)$/
Instance Attribute Summary collapse
-
#expiry ⇒ Object
readonly
Returns the value of attribute expiry.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(key, expiry, version, signature) ⇒ Credentials
constructor
A new instance of Credentials.
- #to_hash ⇒ Object
- #to_headers ⇒ Object
Constructor Details
#initialize(key, expiry, version, signature) ⇒ Credentials
Returns a new instance of Credentials.
34 35 36 37 38 39 |
# File 'lib/hmac_signature/credentials.rb', line 34 def initialize key, expiry, version, signature @key = key @expiry = expiry @version = version @signature = signature end |
Instance Attribute Details
#expiry ⇒ Object (readonly)
Returns the value of attribute expiry.
32 33 34 |
# File 'lib/hmac_signature/credentials.rb', line 32 def expiry @expiry end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
32 33 34 |
# File 'lib/hmac_signature/credentials.rb', line 32 def key @key end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
32 33 34 |
# File 'lib/hmac_signature/credentials.rb', line 32 def signature @signature end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
32 33 34 |
# File 'lib/hmac_signature/credentials.rb', line 32 def version @version end |
Class Method Details
.from_headers(headers = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hmac_signature/credentials.rb', line 17 def from_headers headers={} hash = headers.inject({}) do |memo, (k,v)| HEADER_CREDENTIAL_REGEXES.each do |regex| if match = k.match(regex) new_key = match[1].downcase.gsub('-', '_') memo[new_key] = v break end end memo end new hash['key'], hash['expiry'], hash['version'], hash['signature'] end |
.from_params(params = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/hmac_signature/credentials.rb', line 7 def from_params params={} hash = params.inject({}) do |memo, (k,v)| if match = k.to_s.match(PARAM_CREDENTIAL_REGEX) memo[match[1]] = v end memo end new hash['key'], hash['expiry'], hash['version'], hash['signature'] end |
Instance Method Details
#to_hash ⇒ Object
41 42 43 |
# File 'lib/hmac_signature/credentials.rb', line 41 def to_hash {'auth_key' => key, 'auth_expiry' => expiry, 'auth_version' => version, 'auth_signature' => signature} end |
#to_headers ⇒ Object
45 46 47 |
# File 'lib/hmac_signature/credentials.rb', line 45 def to_headers {'X-Auth-Key' => key, 'X-Auth-Expiry' => expiry, 'X-Auth-Version' => version, 'X-Auth-Signature' => signature} end |