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.



19
20
21
22
23
24
25
26
27
28
# File 'lib/fluidinfo/response.rb', line 19

def initialize(response)
  @status   = response.code
  @headers  = response.headers
  @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

#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#[].



32
33
34
# File 'lib/fluidinfo/response.rb', line 32

def [](key)
  @value[key]
end