Class: SimpleSDKBuilder::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_sdk_builder/response.rb

Instance Method Summary collapse

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

#bodyObject



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

#codeObject



10
11
12
# File 'lib/simple_sdk_builder/response.rb', line 10

def code
  @typhoeus_response.code
end

#headersObject



18
19
20
# File 'lib/simple_sdk_builder/response.rb', line 18

def headers
  @typhoeus_response.headers_hash
end

#parsed_bodyObject



26
27
28
# File 'lib/simple_sdk_builder/response.rb', line 26

def parsed_body
  @parsed_body ||= JSON.parse(body)
end

#timeObject



14
15
16
# File 'lib/simple_sdk_builder/response.rb', line 14

def time
  @typhoeus_response.time
end