Class: Ey::Hmac::Adapter::Faraday

Inherits:
Ey::Hmac::Adapter show all
Defined in:
lib/ey-hmac/adapter/faraday.rb

Constant Summary

Constants inherited from Ey::Hmac::Adapter

AUTHORIZATION_REGEXP

Instance Attribute Summary

Attributes inherited from Ey::Hmac::Adapter

#accept_digests, #authorization_header, #options, #request, #service, #sign_with

Instance Method Summary collapse

Methods inherited from Ey::Hmac::Adapter

#authenticated!, #authenticated?, #authorization, #canonicalize, #initialize, #secure_compare, #signature

Constructor Details

This class inherits a constructor from Ey::Hmac::Adapter

Instance Method Details

#authorization_signatureObject



44
45
46
# File 'lib/ey-hmac/adapter/faraday.rb', line 44

def authorization_signature
  %w[Authorization AUTHORIZATION].inject(nil){|r, h| r || request[:request_headers][h]}
end

#bodyObject



19
20
21
22
23
24
# File 'lib/ey-hmac/adapter/faraday.rb', line 19

def body
  if request[:body] && request[:body].to_s != ""
    request[:body]
  else nil
  end
end

#content_digestObject



10
11
12
13
14
15
16
17
# File 'lib/ey-hmac/adapter/faraday.rb', line 10

def content_digest
  if existing = %w[CONTENT-DIGEST CONTENT_DIGEST Content-Digest Content_Digest].inject(nil) { |r,h| r || request[:request_headers][h] }
    existing
  elsif digestable = body && Digest::MD5.hexdigest(body)
    request[:request_headers]['Content-Digest'] = digestable
  else nil
  end
end

#content_typeObject



6
7
8
# File 'lib/ey-hmac/adapter/faraday.rb', line 6

def content_type
  %w[CONTENT-TYPE CONTENT_TYPE Content-Type Content_Type].inject(nil) { |r,h| r || request[:request_headers][h] }
end

#dateObject



26
27
28
29
# File 'lib/ey-hmac/adapter/faraday.rb', line 26

def date
  existing = %w[DATE Date].inject(nil) { |r,h| r || request[h] }
  existing || (request[:request_headers]['Date'] = Time.now.httpdate)
end

#methodObject



2
3
4
# File 'lib/ey-hmac/adapter/faraday.rb', line 2

def method
  request[:method].to_s.upcase
end

#pathObject



31
32
33
# File 'lib/ey-hmac/adapter/faraday.rb', line 31

def path
  request[:url].path
end

#sign!(key_id, key_secret) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/ey-hmac/adapter/faraday.rb', line 35

def sign!(key_id, key_secret)
  %w[CONTENT-TYPE CONTENT_TYPE Content-Type Content_Type].inject(nil){|r,h| request[:request_headers][h]}
  if options[:version]
    request[:request_headers]['X-Signature-Version'] = options[:version]
  end

  request[:request_headers][authorization_header] = authorization(key_id, key_secret)
end