Module: Peddler::Headers
- Defined in:
- lib/peddler/headers.rb
Overview
Parses useful metadata returned in response headers
Instance Method Summary collapse
-
#content_charset ⇒ Encoding?
The character encoding of the response.
-
#content_length ⇒ String?
The size of the response body in bytes.
-
#content_md5 ⇒ String?
The MD5 digest of the response body.
-
#content_media_type ⇒ String?
The MIME type of the response.
-
#content_subtype ⇒ String?
The exact kind of data of the specified type the MIME type represents.
-
#content_type ⇒ String?
The general category into which the MIME type falls.
-
#mws_quota_max ⇒ Integer?
The max hourly request quota for the requested operation.
-
#mws_quota_remaining ⇒ Integer?
The remaining hourly request quota for the requested operation.
-
#mws_quota_resets_on ⇒ Time?
When the hourly request quota for the requested operation resets.
-
#mws_request_id ⇒ String?
The ID of the request.
-
#mws_response_context ⇒ String?
The context of the response.
-
#mws_timestamp ⇒ Time?
The timestamp of the request.
Instance Method Details
#content_charset ⇒ Encoding?
The character encoding of the response
46 47 48 49 50 51 |
# File 'lib/peddler/headers.rb', line 46 def content_charset match_data = headers['Content-Type']&.match(/charset=(.*);?/) return unless match_data Encoding.find(match_data[1]) end |
#content_length ⇒ String?
The size of the response body in bytes
8 9 10 11 12 |
# File 'lib/peddler/headers.rb', line 8 def content_length return unless headers['Content-Length'] headers['Content-Length'].to_i end |
#content_md5 ⇒ String?
The MD5 digest of the response body
16 17 18 |
# File 'lib/peddler/headers.rb', line 16 def content_md5 headers['Content-MD5'] end |
#content_media_type ⇒ String?
The MIME type of the response
22 23 24 25 26 |
# File 'lib/peddler/headers.rb', line 22 def content_media_type return unless headers['Content-Type'] headers['Content-Type'].split(';').first end |
#content_subtype ⇒ String?
The exact kind of data of the specified type the MIME type represents
38 39 40 41 42 |
# File 'lib/peddler/headers.rb', line 38 def content_subtype return unless content_media_type content_media_type.split('/').last end |
#content_type ⇒ String?
The general category into which the MIME type falls
30 31 32 33 34 |
# File 'lib/peddler/headers.rb', line 30 def content_type return unless content_media_type content_media_type.split('/').first end |
#mws_quota_max ⇒ Integer?
The max hourly request quota for the requested operation
55 56 57 58 59 |
# File 'lib/peddler/headers.rb', line 55 def mws_quota_max return unless headers['x-mws-quota-max'] headers['x-mws-quota-max'].to_i end |
#mws_quota_remaining ⇒ Integer?
The remaining hourly request quota for the requested operation
63 64 65 66 67 |
# File 'lib/peddler/headers.rb', line 63 def mws_quota_remaining return unless headers['x-mws-quota-remaining'] headers['x-mws-quota-remaining'].to_i end |
#mws_quota_resets_on ⇒ Time?
When the hourly request quota for the requested operation resets
71 72 73 74 75 |
# File 'lib/peddler/headers.rb', line 71 def mws_quota_resets_on return unless headers['x-mws-quota-resetsOn'] Time.parse(headers['x-mws-quota-resetsOn']) end |
#mws_request_id ⇒ String?
The ID of the request
79 80 81 |
# File 'lib/peddler/headers.rb', line 79 def mws_request_id headers['x-mws-request-id'] end |
#mws_response_context ⇒ String?
The context of the response
93 94 95 |
# File 'lib/peddler/headers.rb', line 93 def mws_response_context headers['x-mws-response-context'] end |
#mws_timestamp ⇒ Time?
The timestamp of the request
85 86 87 88 89 |
# File 'lib/peddler/headers.rb', line 85 def return unless headers['x-mws-timestamp'] Time.parse(headers['x-mws-timestamp']) end |