Class: SimpleSDKBuilder::Response
- Inherits:
-
Object
- Object
- SimpleSDKBuilder::Response
- Defined in:
- lib/simple_sdk_builder/response.rb
Instance Method Summary collapse
- #body ⇒ Object
- #build(type) ⇒ Object
- #build_search_results(type) ⇒ Object
- #code ⇒ Object
- #headers ⇒ Object
-
#initialize(typhoeus_response) ⇒ Response
constructor
A new instance of Response.
- #parsed_body ⇒ Object
- #time ⇒ Object
Constructor Details
#initialize(typhoeus_response) ⇒ Response
Returns a new instance of Response.
6 7 8 |
# File 'lib/simple_sdk_builder/response.rb', line 6 def initialize(typhoeus_response) @typhoeus_response = typhoeus_response end |
Instance Method Details
#body ⇒ Object
22 23 24 |
# File 'lib/simple_sdk_builder/response.rb', line 22 def body @typhoeus_response.body end |
#build(type) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/simple_sdk_builder/response.rb', line 30 def build(type) if parsed_body.is_a?(Array) parsed_body.collect { |value| type.new.from_json(value.to_json) } else type.new.from_json(body) end end |
#build_search_results(type) ⇒ Object
38 39 40 |
# File 'lib/simple_sdk_builder/response.rb', line 38 def build_search_results(type) SearchResults.new(self, type) end |
#code ⇒ Object
10 11 12 |
# File 'lib/simple_sdk_builder/response.rb', line 10 def code @typhoeus_response.code end |
#headers ⇒ Object
18 19 20 |
# File 'lib/simple_sdk_builder/response.rb', line 18 def headers @typhoeus_response.headers_hash end |
#parsed_body ⇒ Object
26 27 28 |
# File 'lib/simple_sdk_builder/response.rb', line 26 def parsed_body @parsed_body ||= JSON.parse(body) end |
#time ⇒ Object
14 15 16 |
# File 'lib/simple_sdk_builder/response.rb', line 14 def time @typhoeus_response.time end |