Class: Fluidinfo::Response

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

Overview

An instance of Response is returned by all of the Client calls. There’s no reason to instantiate one yourself.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject (readonly)

String, nil

The raw response



15
16
17
# File 'lib/fluidinfo/response.rb', line 15

def content
  @content
end

#errorObject (readonly)

String

The error, if any, returned by Fluidinfo



19
20
21
# File 'lib/fluidinfo/response.rb', line 19

def error
  @error
end

#headersObject (readonly)

Hash

The returned headers.



13
14
15
# File 'lib/fluidinfo/response.rb', line 13

def headers
  @headers
end

#statusObject (readonly)

Integer

The return code of the API call.



11
12
13
# File 'lib/fluidinfo/response.rb', line 11

def status
  @status
end

#valueObject (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