class Openlive::Response

Attributes

response[R]

@return [Faraday::Response]

Public Class Methods

new(faraday_response) click to toggle source

Initialize the response object

@param [Faraday::Response] faraday_response

# File lib/openlive/response.rb, line 9
def initialize(faraday_response)
  @response = faraday_response
end

Public Instance Methods

body() click to toggle source

Parse the response from the server

@return [Hash,Nil]

# File lib/openlive/response.rb, line 30
def body
  @body ||= (
    JSON.parse(response.body) if response.body.length > 0
  )
end
error_message() click to toggle source

Convenience method for fetching the error message

@return [String]

# File lib/openlive/response.rb, line 39
def error_message
  if !success?
    body
  end
rescue JSON::ParserError => ex
  ex.message
end
method_missing(method_name, *opts, &block) click to toggle source

Simple method missing accessor for reading returned attributes

@return [String] the raw returned string from the API

# File lib/openlive/response.rb, line 50
def method_missing(method_name, *opts, &block)
  body[method_name.to_s] if body.is_a?(Hash)
end
status() click to toggle source

Return the response status

@return [Integer]

# File lib/openlive/response.rb, line 23
def status
  response.status
end
success?() click to toggle source

Was the request successful?

@return [Truthy]

# File lib/openlive/response.rb, line 16
def success?
  response.success?
end