Class: Ey::Hmac::Adapter::Faraday
Constant Summary
AUTHORIZATION_REGEXP
Instance Attribute Summary
#accept_digests, #authorization_header, #options, #request, #service, #sign_with
Instance Method Summary
collapse
#authenticated!, #authenticated?, #authorization, #canonicalize, #initialize, #signature
Instance Method Details
#authorization_signature ⇒ Object
64
65
66
|
# File 'lib/ey-hmac/adapter/faraday.rb', line 64
def authorization_signature
(*%w[Authorization AUTHORIZATION])
end
|
#body ⇒ Object
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_digest ⇒ Object
12
13
14
15
16
|
# File 'lib/ey-hmac/adapter/faraday.rb', line 12
def content_digest
@content_digest ||= (
*%w[CONTENT-DIGEST CONTENT_DIGEST Content-Digest Content_Digest]
)
end
|
#content_type ⇒ Object
6
7
8
9
10
|
# File 'lib/ey-hmac/adapter/faraday.rb', line 6
def content_type
@content_type ||= (
*%w[CONTENT-TYPE CONTENT_TYPE Content-Type Content_Type]
)
end
|
#date ⇒ Object
39
40
41
|
# File 'lib/ey-hmac/adapter/faraday.rb', line 39
def date
(*%w[DATE Date])
end
|
#method ⇒ Object
2
3
4
|
# File 'lib/ey-hmac/adapter/faraday.rb', line 2
def method
request[:method].to_s.upcase
end
|
#path ⇒ Object
49
50
51
|
# File 'lib/ey-hmac/adapter/faraday.rb', line 49
def path
request[:url].path
end
|
#set_content_digest ⇒ Object
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_date ⇒ Object
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(key_id, key_secret)
end
|