Class: Elevate::HTTP::JSONHTTPResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/elevate/http/http_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ JSONHTTPResponse

Returns a new instance of JSONHTTPResponse.



87
88
89
90
# File 'lib/elevate/http/http_client.rb', line 87

def initialize(response)
  @response = response
  @body = decode(response.body)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



98
99
100
# File 'lib/elevate/http/http_client.rb', line 98

def body
  @body
end

Instance Method Details

#decode(data) ⇒ Object



92
93
94
95
96
# File 'lib/elevate/http/http_client.rb', line 92

def decode(data)
  return nil if data.nil?

  NSJSONSerialization.JSONObjectWithData(data, options:0, error:nil)
end

#errorObject

TODO: delegate



101
102
103
# File 'lib/elevate/http/http_client.rb', line 101

def error
  @response.error
end

#headersObject



105
106
107
# File 'lib/elevate/http/http_client.rb', line 105

def headers
  @response.headers
end

#status_codeObject



109
110
111
# File 'lib/elevate/http/http_client.rb', line 109

def status_code
  @response.status_code
end