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
48 49 50 51 52 53 54 55 56 |
# File 'lib/peddler/headers.rb', line 48 def content_charset match_data = headers['Content-Type']&.match(/charset=(.*);?/) return unless match_data string = match_data[1].upcase string = 'UTF-8' if string == 'UTF8' Encoding.find(string) end |
#content_length ⇒ String?
The size of the response body in bytes
10 11 12 13 14 |
# File 'lib/peddler/headers.rb', line 10 def content_length return unless headers['Content-Length'] headers['Content-Length'].to_i end |
#content_md5 ⇒ String?
The MD5 digest of the response body
18 19 20 |
# File 'lib/peddler/headers.rb', line 18 def content_md5 headers['Content-MD5'] end |
#content_media_type ⇒ String?
The MIME type of the response
24 25 26 27 28 |
# File 'lib/peddler/headers.rb', line 24 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
40 41 42 43 44 |
# File 'lib/peddler/headers.rb', line 40 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
32 33 34 35 36 |
# File 'lib/peddler/headers.rb', line 32 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
60 61 62 63 64 |
# File 'lib/peddler/headers.rb', line 60 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
68 69 70 71 72 |
# File 'lib/peddler/headers.rb', line 68 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
76 77 78 79 80 |
# File 'lib/peddler/headers.rb', line 76 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
84 85 86 |
# File 'lib/peddler/headers.rb', line 84 def mws_request_id headers['x-mws-request-id'] end |
#mws_response_context ⇒ String?
The context of the response
98 99 100 |
# File 'lib/peddler/headers.rb', line 98 def mws_response_context headers['x-mws-response-context'] end |
#mws_timestamp ⇒ Time?
The timestamp of the request
90 91 92 93 94 |
# File 'lib/peddler/headers.rb', line 90 def return unless headers['x-mws-timestamp'] Time.parse(headers['x-mws-timestamp']) end |