Class: Transloadit::Response
- Inherits:
-
Object
- Object
- Transloadit::Response
- Defined in:
- lib/transloadit/response.rb
Defined Under Namespace
Modules: Assembly
Instance Attribute Summary collapse
-
#headers ⇒ Hash
readonly
Normalized response headers.
-
#status ⇒ Integer
(also: #code)
readonly
The HTTP response status.
Instance Method Summary collapse
-
#[](attribute) ⇒ String
Returns the attribute from the JSON response.
-
#body ⇒ Hash
Returns the parsed JSON body.
-
#extend!(mod) ⇒ Transloadit::Response
Chainably extends the response with additional methods.
-
#initialize(body:, headers:, status:) ⇒ Response
constructor
Creates a response without exposing the underlying HTTP client.
-
#inspect ⇒ String
Inspects the body of the response.
-
#replace(other) ⇒ Transloadit::Response
Replaces this response's HTTP data with another response's data.
Constructor Details
#initialize(body:, headers:, status:) ⇒ Response
Creates a response without exposing the underlying HTTP client.
13 14 15 16 17 |
# File 'lib/transloadit/response.rb', line 13 def initialize(body:, headers:, status:) @raw_body = body @headers = normalize_headers(headers) @status = status end |
Instance Attribute Details
#headers ⇒ Hash (readonly)
Returns normalized response headers.
20 21 22 |
# File 'lib/transloadit/response.rb', line 20 def headers @headers end |
#status ⇒ Integer (readonly) Also known as: code
Returns the HTTP response status.
23 24 25 |
# File 'lib/transloadit/response.rb', line 23 def status @status end |
Instance Method Details
#[](attribute) ⇒ String
Returns the attribute from the JSON response.
34 35 36 |
# File 'lib/transloadit/response.rb', line 34 def [](attribute) body[attribute.to_s] end |
#body ⇒ Hash
Returns the parsed JSON body.
43 44 45 |
# File 'lib/transloadit/response.rb', line 43 def body MultiJson.load @raw_body end |
#extend!(mod) ⇒ Transloadit::Response
Chainably extends the response with additional methods. Used to add context-specific functionality to a response.
63 64 65 66 67 |
# File 'lib/transloadit/response.rb', line 63 def extend!(mod) extend(mod) self end |
#inspect ⇒ String
Inspects the body of the response.
52 53 54 |
# File 'lib/transloadit/response.rb', line 52 def inspect body.inspect end |
#replace(other) ⇒ Transloadit::Response
Replaces this response's HTTP data with another response's data.
75 76 77 78 79 80 |
# File 'lib/transloadit/response.rb', line 75 def replace(other) @raw_body = other.raw_body @headers = other.headers @status = other.status self end |