Class: FizzyApiClient::Response
- Inherits:
-
Object
- Object
- FizzyApiClient::Response
- Defined in:
- lib/fizzy_api_client/response.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#raw_body ⇒ Object
readonly
Returns the value of attribute raw_body.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #created_with_location? ⇒ Boolean
- #etag ⇒ Object
-
#initialize(status:, headers:, raw_body:) ⇒ Response
constructor
A new instance of Response.
- #location ⇒ Object
- #next_page_url ⇒ Object
- #no_content? ⇒ Boolean
- #not_modified? ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(status:, headers:, raw_body:) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 12 |
# File 'lib/fizzy_api_client/response.rb', line 7 def initialize(status:, headers:, raw_body:) @status = status @headers = normalize_headers(headers) @raw_body = raw_body @body = parse_body(raw_body) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/fizzy_api_client/response.rb', line 5 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/fizzy_api_client/response.rb', line 5 def headers @headers end |
#raw_body ⇒ Object (readonly)
Returns the value of attribute raw_body.
5 6 7 |
# File 'lib/fizzy_api_client/response.rb', line 5 def raw_body @raw_body end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'lib/fizzy_api_client/response.rb', line 5 def status @status end |
Instance Method Details
#created_with_location? ⇒ Boolean
34 35 36 |
# File 'lib/fizzy_api_client/response.rb', line 34 def created_with_location? status == 201 && location && (raw_body.nil? || raw_body.empty?) end |
#etag ⇒ Object
26 27 28 |
# File 'lib/fizzy_api_client/response.rb', line 26 def etag headers["etag"] end |
#location ⇒ Object
30 31 32 |
# File 'lib/fizzy_api_client/response.rb', line 30 def location headers["location"] end |
#next_page_url ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/fizzy_api_client/response.rb', line 38 def next_page_url link_header = headers["link"] return nil unless link_header match = link_header.match(/<([^>]+)>;\s*rel="next"/) match ? match[1] : nil end |
#no_content? ⇒ Boolean
18 19 20 |
# File 'lib/fizzy_api_client/response.rb', line 18 def no_content? status == 204 end |
#not_modified? ⇒ Boolean
22 23 24 |
# File 'lib/fizzy_api_client/response.rb', line 22 def not_modified? status == 304 end |
#success? ⇒ Boolean
14 15 16 |
# File 'lib/fizzy_api_client/response.rb', line 14 def success? status >= 200 && status < 300 end |