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 52 53 54 |
# File 'lib/peddler/headers.rb', line 46 def content_charset match_data = headers['Content-Type']&.match(/charset=(.*);?/) return unless match_data string = match_data[1] string = 'UTF-8' if string == 'UTF8' Encoding.find(string) 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
58 59 60 61 62 |
# File 'lib/peddler/headers.rb', line 58 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
66 67 68 69 70 |
# File 'lib/peddler/headers.rb', line 66 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
74 75 76 77 78 |
# File 'lib/peddler/headers.rb', line 74 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
82 83 84 |
# File 'lib/peddler/headers.rb', line 82 def mws_request_id headers['x-mws-request-id'] end |
#mws_response_context ⇒ String?
The context of the response
96 97 98 |
# File 'lib/peddler/headers.rb', line 96 def mws_response_context headers['x-mws-response-context'] end |
#mws_timestamp ⇒ Time?
The timestamp of the request
88 89 90 91 92 |
# File 'lib/peddler/headers.rb', line 88 def return unless headers['x-mws-timestamp'] Time.parse(headers['x-mws-timestamp']) end |