Class: Ey::Hmac::Adapter::Faraday
Constant Summary
AUTHORIZATION_REGEXP, DEFAULT_CANONICALIZE_WITH
Instance Attribute Summary
#accept_digests, #authorization_header, #canonicalize_with, #include_query_string, #options, #request, #service, #sign_with
Instance Method Summary
collapse
#authenticated!, #authenticated?, #authorization, #canonicalize, #initialize, #signature
Instance Method Details
#authorization_signature ⇒ Object
60
61
62
|
# File 'lib/ey-hmac/adapter/faraday.rb', line 60
def authorization_signature
('Authorization', 'AUTHORIZATION')
end
|
#body ⇒ Object
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_digest ⇒ Object
14
15
16
17
18
|
# File 'lib/ey-hmac/adapter/faraday.rb', line 14
def content_digest
@content_digest ||= (
'CONTENT-DIGEST', 'CONTENT_DIGEST', 'Content-Digest', 'Content_Digest'
)
end
|
#content_type ⇒ Object
8
9
10
11
12
|
# File 'lib/ey-hmac/adapter/faraday.rb', line 8
def content_type
@content_type ||= (
'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
('DATE', 'Date')
end
|
#method ⇒ Object
4
5
6
|
# File 'lib/ey-hmac/adapter/faraday.rb', line 4
def method
request[:method].to_s.upcase
end
|
#path ⇒ Object
47
48
49
|
# File 'lib/ey-hmac/adapter/faraday.rb', line 47
def path
request[:url].path
end
|
#set_content_digest ⇒ Object
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_date ⇒ Object
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(key_id, key_secret)
end
|