class HmacSignature::Credentials
Constants
- HEADER_CREDENTIAL_REGEXES
- PARAM_CREDENTIAL_REGEX
Attributes
expiry[R]
key[R]
signature[R]
version[R]
Public Class Methods
from_headers(headers={})
click to toggle source
# 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={})
click to toggle source
# 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
new(key, expiry, version, signature)
click to toggle source
# File lib/hmac_signature/credentials.rb, line 34 def initialize key, expiry, version, signature @key = key @expiry = expiry @version = version @signature = signature end
Public Instance Methods
to_hash()
click to toggle source
# 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()
click to toggle source
# 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