Class: Springboard::Client::Response

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

Overview

An API response including body, headers, and status information.

Instance Method Summary collapse

Constructor Details

#initialize(response, client) ⇒ Response

Returns a new instance of Response

Parameters:


9
10
11
12
# File 'lib/springboard/client/response.rb', line 9

def initialize(response, client)
  @response = response
  @client = client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Delegates missing methods to the underlying Patron::Response.


50
51
52
# File 'lib/springboard/client/response.rb', line 50

def method_missing(method, *args, &block)
  @response.respond_to?(method) ? @response.__send__(method, *args, &block) : super
end

Instance Method Details

#[](key) ⇒ Object

Returns the corresponding key from “body”.


16
17
18
# File 'lib/springboard/client/response.rb', line 16

def [](key)
  body[key]
end

#bodyBody

Returns the parsed response body as a Body object.

Returns:

  • (Body)

    The parsed response body

Raises:

  • (BodyError)

    If the body is not parseable


34
35
36
# File 'lib/springboard/client/response.rb', line 34

def body
  @data ||= parse_body
end

#raw_bodyString

Returns the raw response body as a String.

Returns:

  • (String)

    The raw response body


24
25
26
# File 'lib/springboard/client/response.rb', line 24

def raw_body
  @response.body
end

#resourceResource

If the response included a 'Location' header, returns a new Resource with a URI set to its value, else nil.

Returns:


59
60
61
62
63
64
65
# File 'lib/springboard/client/response.rb', line 59

def resource
  if location = headers['Location']
    @client[headers['Location']]
  else
    nil
  end
end

#success?Boolean

Returns true if the request was successful, else false.

Returns:

  • (Boolean)

42
43
44
# File 'lib/springboard/client/response.rb', line 42

def success?
  status < 400
end