Class: CoreLibrary::ApiResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/apimatic-core/http/response/api_response.rb

Overview

The class to hold the complete HTTP response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response, data: nil, errors: nil) ⇒ ApiResponse

The constructor

Parameters:

  • The (HttpResponse)

    original, raw response from the api.

  • The (Object)

    data field specified for the response.

  • Any (Array<String>)

    errors returned by the server.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/apimatic-core/http/response/api_response.rb', line 13

def initialize(http_response,
               data: nil,
               errors: nil)
  @status_code = http_response.status_code
  @reason_phrase = http_response.reason_phrase
  @headers = http_response.headers
  @raw_body = http_response.raw_body
  @request = http_response.request
  @data = data
  @errors = errors
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/apimatic-core/http/response/api_response.rb', line 5

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/apimatic-core/http/response/api_response.rb', line 5

def errors
  @errors
end

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/apimatic-core/http/response/api_response.rb', line 5

def headers
  @headers
end

#raw_bodyObject (readonly)

Returns the value of attribute raw_body.



5
6
7
# File 'lib/apimatic-core/http/response/api_response.rb', line 5

def raw_body
  @raw_body
end

#reason_phraseObject (readonly)

Returns the value of attribute reason_phrase.



5
6
7
# File 'lib/apimatic-core/http/response/api_response.rb', line 5

def reason_phrase
  @reason_phrase
end

#requestObject (readonly)

Returns the value of attribute request.



5
6
7
# File 'lib/apimatic-core/http/response/api_response.rb', line 5

def request
  @request
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



5
6
7
# File 'lib/apimatic-core/http/response/api_response.rb', line 5

def status_code
  @status_code
end

Instance Method Details

#error?Boolean

Returns true if status_code is between 400-600

Returns:

  • (Boolean)


31
32
33
# File 'lib/apimatic-core/http/response/api_response.rb', line 31

def error?
  status_code >= 400 && status_code < 600
end

#success?Boolean

Returns true if status_code is between 200-300

Returns:

  • (Boolean)


26
27
28
# File 'lib/apimatic-core/http/response/api_response.rb', line 26

def success?
  status_code >= 200 && status_code < 300
end