class Projector::Transport::HTTP::Response
Response
class responsible for deserializing API calls @attr [Object] body The parsed response @attr [Hash] headers HTTP
headers returned as part of the response @attr [String] code The HTTP
response code
Attributes
body[RW]
code[RW]
headers[RW]
Public Class Methods
new(http_response)
click to toggle source
Initializes a new result
@param http_response [Net::HTTPResponse] the raw response to parse
# File lib/projector/transport/http.rb, line 214 def initialize(http_response) @code = http_response.code parse_headers(http_response.to_hash) parse_body(http_response.body) end
Private Instance Methods
parse_body(response_body)
click to toggle source
Parses the raw body in to a hash
# File lib/projector/transport/http.rb, line 232 def parse_body(response_body) # Parse JSON begin self.body = JSON.parse(response_body) rescue JSON::ParserError self.body = response_body end end
parse_headers(raw_headers)
click to toggle source
Parses raw headers in to a reasonable hash
# File lib/projector/transport/http.rb, line 223 def parse_headers(raw_headers) # raw headers from net_http have an array for each result. Flatten them out. @headers = raw_headers.inject({}) do |remainder, (k, v)| remainder[k] = [v].flatten.first remainder end end