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, DEFAULT_CANONICALIZE_WITH

Instance Attribute Summary

Attributes inherited from Ey::Hmac::Adapter

#accept_digests, #authorization_header, #canonicalize_with, #include_query_string, #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



60
61
62
# File 'lib/ey-hmac/adapter/faraday.rb', line 60

def authorization_signature
  find_header('Authorization', 'AUTHORIZATION')
end

#bodyObject



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

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

#content_digestObject



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

def content_digest
  @content_digest ||= find_header(
    'CONTENT-DIGEST', 'CONTENT_DIGEST', 'Content-Digest', 'Content_Digest'
  )
end

#content_typeObject



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

def content_type
  @content_type ||= find_header(
    '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('DATE', 'Date')
end

#methodObject



4
5
6
# File 'lib/ey-hmac/adapter/faraday.rb', line 4

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

#pathObject



47
48
49
# File 'lib/ey-hmac/adapter/faraday.rb', line 47

def path
  request[:url].path
end

#set_content_digestObject



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

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
# File 'lib/ey-hmac/adapter/faraday.rb', line 43

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

#sign!(key_id, key_secret) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/ey-hmac/adapter/faraday.rb', line 51

def sign!(key_id, key_secret)
  set_content_digest
  set_date

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

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