class Tikkie::Api::Response

Parses and wraps the response from the Tikkie API.

Attributes

body[R]
response[R]

Public Class Methods

new(response) click to toggle source
# File lib/tikkie/api/response.rb, line 12
def initialize(response)
  @response = response
  @body = response.body ? parse_body(response.body) : {}
end

Public Instance Methods

error?() click to toggle source
# File lib/tikkie/api/response.rb, line 21
def error?
  !success?
end
errors() click to toggle source
# File lib/tikkie/api/response.rb, line 41
def errors
  @errors ||= begin
    errors = []

    if body[:errors]
      body[:errors].each do |error|
        errors << Tikkie::Api::Resources::Error.new(error)
      end
    end

    errors
  end
end
http_code() click to toggle source
# File lib/tikkie/api/response.rb, line 33
def http_code
  response.code.to_i
end
http_message() click to toggle source
# File lib/tikkie/api/response.rb, line 37
def http_message
  response.message
end
invalid?() click to toggle source
# File lib/tikkie/api/response.rb, line 25
def invalid?
  body.nil?
end
request_uri() click to toggle source
# File lib/tikkie/api/response.rb, line 29
def request_uri
  response.uri
end
success?() click to toggle source
# File lib/tikkie/api/response.rb, line 17
def success?
  http_code == 200 || http_code == 201 || http_code == 204
end

Private Instance Methods

parse_body(body) click to toggle source
# File lib/tikkie/api/response.rb, line 57
def parse_body(body)
  JSON.parse(body, symbolize_names: true)
rescue JSON::ParserError
  nil
end