Class: SolscanApiRuby::Client::Response

Inherits:
Object
  • Object
show all
Includes:
HttpCodes
Defined in:
lib/solscan_api_ruby/client/response.rb

Overview

Response class parses response from the API to the more convenient format.

Constant Summary

Constants included from HttpCodes

HttpCodes::HTTP_BAD_REQUEST_CODE, HttpCodes::HTTP_FORBIDDEN_CODE, HttpCodes::HTTP_INTERNAL_SERVER_ERROR, HttpCodes::HTTP_NOT_FOUND_CODE, HttpCodes::HTTP_OK_CODE, HttpCodes::HTTP_UNAUTHORIZED_CODE, HttpCodes::HTTP_UNPROCESSABLE_ENTITY_CODE

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Initialize object with response body in json format.

Parameters:

  • response (Hash)

    hash with response from the API.



15
16
17
# File 'lib/solscan_api_ruby/client/response.rb', line 15

def initialize(response)
  @response = response
end

Instance Method Details

#bodyHash

Returns parsed response body.

Returns:

  • (Hash)

    parsed response body.



20
21
22
23
24
25
# File 'lib/solscan_api_ruby/client/response.rb', line 20

def body
  @body ||= Oj.load(@response.body)

rescue Oj::ParseError
  @response.body
end

#headersHash

Returns response headers.

Returns:

  • (Hash)

    response headers.



28
29
30
# File 'lib/solscan_api_ruby/client/response.rb', line 28

def headers
  @response.headers
end

#statusInteger

Returns response status.

Returns:

  • (Integer)

    response status.



33
34
35
# File 'lib/solscan_api_ruby/client/response.rb', line 33

def status
  @response.status
end

#successfull?Boolean

Returns response success.

Returns:

  • (Boolean)

    response success.



38
39
40
# File 'lib/solscan_api_ruby/client/response.rb', line 38

def successfull?
  @response.success?
end