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, #signature

Constructor Details

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

Instance Method Details

#authorization_signatureObject



64
65
66
# File 'lib/ey-hmac/adapter/faraday.rb', line 64

def authorization_signature
  find_header(*%w[Authorization AUTHORIZATION])
end

#bodyObject



33
34
35
36
37
# File 'lib/ey-hmac/adapter/faraday.rb', line 33

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

#content_digestObject



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

def content_digest
  @content_digest ||= find_header(
    *%w[CONTENT-DIGEST CONTENT_DIGEST Content-Digest Content_Digest]
  )
end

#content_typeObject



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

def content_type
  @content_type ||= find_header(
    *%w[CONTENT-TYPE CONTENT_TYPE Content-Type Content_Type]
  )
end

#dateObject



39
40
41
# File 'lib/ey-hmac/adapter/faraday.rb', line 39

def date
  find_header(*%w[DATE Date])
end

#methodObject



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

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

#pathObject



49
50
51
# File 'lib/ey-hmac/adapter/faraday.rb', line 49

def path
  request[:url].path
end

#set_content_digestObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ey-hmac/adapter/faraday.rb', line 18

def set_content_digest
  return if content_digest

  digestable = if body.respond_to?(:rewind)
                 body.rewind
                 body.read.tap { |_| body.rewind }
               else
                 body.to_s
               end

  if digestable && digestable != ""
    @content_digest = request[:request_headers]['Content-Digest'] = Digest::MD5.hexdigest(digestable)
  end
end

#set_dateObject



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

def set_date
  unless date
    request[:request_headers]['Date'] = Time.now.httpdate
  end
end

#sign!(key_id, key_secret) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/ey-hmac/adapter/faraday.rb', line 53

def sign!(key_id, key_secret)
  set_content_digest
  set_date

  if options[:version]
    request[:request_headers]['X-Signature-Version'] = options[:version]
  end

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