Class: Croesus::WebResponse
- Includes:
- Utils, Net::HTTPHeader
- Defined in:
- lib/croesus/web_client/web_response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#cookies ⇒ Object
readonly
Returns the value of attribute cookies.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#raw_body ⇒ Object
readonly
Returns the value of attribute raw_body.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(response) ⇒ WebResponse
constructor
A new instance of WebResponse.
- #inspect ⇒ Object
- #method_missing(name, *args, &block) ⇒ Object
- #respond_to?(method) ⇒ Boolean
Methods included from Utils
#callable, #caller_name, #camelize, #class_name, #classify, #command_in_path?, #demodulize, #pluralize, #request_id, #retrier, #singularize, #terminal_dimensions, #twenty_four_hours_ago, #underscore, #utc_httpdate, #verify_options
Constructor Details
#initialize(response) ⇒ WebResponse
Returns a new instance of WebResponse.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/croesus/web_client/web_response.rb', line 29 def initialize(response) @code = response.code; @headers = response.headers @raw_body = response @body = @raw_body @cookies = response. Croesus.last_response = { code: response.code, headers: response.headers, body: JSON.parse(response.body), cookies: response., description: response.description }.recursively_normalize_keys begin @body = JSON.parse(@raw_body) rescue Exception end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/croesus/web_client/web_response.rb', line 58 def method_missing(name, *args, &block) if @headers.respond_to?(name) @headers.send(name, *args, &block) else super end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
27 28 29 |
# File 'lib/croesus/web_client/web_response.rb', line 27 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
27 28 29 |
# File 'lib/croesus/web_client/web_response.rb', line 27 def code @code end |
#cookies ⇒ Object (readonly)
Returns the value of attribute cookies.
27 28 29 |
# File 'lib/croesus/web_client/web_response.rb', line 27 def @cookies end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
27 28 29 |
# File 'lib/croesus/web_client/web_response.rb', line 27 def headers @headers end |
#raw_body ⇒ Object (readonly)
Returns the value of attribute raw_body.
27 28 29 |
# File 'lib/croesus/web_client/web_response.rb', line 27 def raw_body @raw_body end |
Instance Method Details
#==(other) ⇒ Object
50 51 52 |
# File 'lib/croesus/web_client/web_response.rb', line 50 def ==(other) @headers == other end |
#inspect ⇒ Object
54 55 56 |
# File 'lib/croesus/web_client/web_response.rb', line 54 def inspect @headers.inspect end |
#respond_to?(method) ⇒ Boolean
66 67 68 |
# File 'lib/croesus/web_client/web_response.rb', line 66 def respond_to?(method) super || @headers.respond_to?(method) end |