class Iterable::Response

Response class is used to get access to raw HTTP request info

Attributes

body[R]

Public Class Methods

new(resp) click to toggle source

@!visibility private

# File lib/iterable/response.rb, line 15
def initialize(resp) # @private
  @resp = resp
  @body = parsed_body
end

Public Instance Methods

success?() click to toggle source

Convenience method to determine if request was successfull or not @return [Boolean]

# File lib/iterable/response.rb, line 24
def success?
  case @resp.code.to_i
  when (200..299) then true
  else
    false
  end
end

Private Instance Methods

parsed_body() click to toggle source

Attempts to parse the response as JSON. Will rescue and return original if unable to parse.

@return [Hash,Array,String] A parsed JSON object or the original response body

# File lib/iterable/response.rb, line 39
def parsed_body
  response_body = @resp.body
  MultiJson.load response_body
rescue MultiJson::ParseError
  response_body
end