Class: Kentaa::Api::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/kentaa/api/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



10
11
12
13
# File 'lib/kentaa/api/response.rb', line 10

def initialize(response)
  @response = response
  @body = response.body ? parse_body(response.body) : {}
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/kentaa/api/response.rb', line 8

def body
  @body
end

#responseObject (readonly)

Returns the value of attribute response.



8
9
10
# File 'lib/kentaa/api/response.rb', line 8

def response
  @response
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/kentaa/api/response.rb', line 19

def error?
  !success?
end

#errorsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/kentaa/api/response.rb', line 35

def errors
  @errors ||= begin
    errors = []

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

    errors
  end
end

#http_codeObject



23
24
25
# File 'lib/kentaa/api/response.rb', line 23

def http_code
  response.code.to_i
end

#messageObject



31
32
33
# File 'lib/kentaa/api/response.rb', line 31

def message
  body[:message]
end

#request_uriObject



27
28
29
# File 'lib/kentaa/api/response.rb', line 27

def request_uri
  response.uri
end

#success?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/kentaa/api/response.rb', line 15

def success?
  (http_code == 200 || http_code == 201 || http_code == 204) && !message
end