Class: NiceJsonApi::Response
- Inherits:
-
Object
- Object
- NiceJsonApi::Response
show all
- Defined in:
- lib/nice_json_api.rb
Overview
Response from a friendly API
Defined Under Namespace
Classes: NullResponse, SingleRequest
Instance Method Summary
collapse
Constructor Details
#initialize(url, method: :get, body: nil, auth: nil) ⇒ Response
Returns a new instance of Response.
13
14
15
16
17
18
|
# File 'lib/nice_json_api.rb', line 13
def initialize(url, method: :get, body: nil, auth: nil)
@url = url.to_s
@method = method
@body = body
@auth = auth
end
|
Instance Method Details
#body ⇒ Object
20
21
22
23
24
|
# File 'lib/nice_json_api.rb', line 20
def body
JSON.parse(raw_body) || {}
rescue JSON::ParserError
{}
end
|
#code ⇒ Object
26
27
28
|
# File 'lib/nice_json_api.rb', line 26
def code
raw.code
end
|
#message ⇒ Object
30
31
32
|
# File 'lib/nice_json_api.rb', line 30
def message
raw.message
end
|
#raw ⇒ Object
34
35
36
|
# File 'lib/nice_json_api.rb', line 34
def raw
@raw ||= fetch(initial_uri, method: @method, body: @body, auth: @auth)
end
|
#raw_body ⇒ Object
38
39
40
|
# File 'lib/nice_json_api.rb', line 38
def raw_body
raw.body
end
|