Class: Fluidinfo::Response
- Inherits:
-
Object
- Object
- Fluidinfo::Response
- Defined in:
- lib/fluidinfo/response.rb
Overview
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
- String, nil
-
The raw response.
-
#error ⇒ Object
readonly
- String
-
The error, if any, returned by Fluidinfo.
-
#headers ⇒ Object
readonly
- Hash
-
The returned headers.
-
#status ⇒ Object
readonly
- Integer
-
The return code of the API call.
-
#value ⇒ Object
readonly
- Hash, String
-
The parsed response if the
Content-Type
was one of JSON_TYPES, otherwise equivalent to #content.
Instance Method Summary collapse
-
#[](key) ⇒ Object
A shortcut for Response.value#[].
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fluidinfo/response.rb', line 21 def initialize(response) @status = response.code @headers = response.headers @error = @headers[:x_fluiddb_error_class] @content = response.body @value = if JSON_TYPES.include? @headers[:content_type] Yajl.load @content else @content end end |
Instance Attribute Details
#content ⇒ Object (readonly)
- String, nil
-
The raw response
15 16 17 |
# File 'lib/fluidinfo/response.rb', line 15 def content @content end |
#error ⇒ Object (readonly)
- String
-
The error, if any, returned by Fluidinfo
19 20 21 |
# File 'lib/fluidinfo/response.rb', line 19 def error @error end |
#headers ⇒ Object (readonly)
- Hash
-
The returned headers.
13 14 15 |
# File 'lib/fluidinfo/response.rb', line 13 def headers @headers end |
#status ⇒ Object (readonly)
- Integer
-
The return code of the API call.
11 12 13 |
# File 'lib/fluidinfo/response.rb', line 11 def status @status end |
#value ⇒ Object (readonly)
- Hash, String
-
The parsed response if the
Content-Type
was one of JSON_TYPES, otherwise equivalent to #content.
17 18 19 |
# File 'lib/fluidinfo/response.rb', line 17 def value @value end |
Instance Method Details
#[](key) ⇒ Object
A shortcut for Response.value#[].
35 36 37 |
# File 'lib/fluidinfo/response.rb', line 35 def [](key) @value[key] end |