Class: Suretax::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_response) ⇒ Response

Returns a new instance of Response.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/suretax/response.rb', line 8

def initialize(api_response)
  @response = api_response
  sanitized_body = remove_xml_brackets(api_response.body)
  if sanitized_body == 'invalid request'
    @body = sanitized_body
    @status = 400
    @api = nil
    log_response

    return self
  end
  @body = JSON.parse(sanitized_body)
  @api = Api::Response.new(@body)
  @status = map_response_code_to_http_status(api.status)

  log_response
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



6
7
8
# File 'lib/suretax/response.rb', line 6

def api
  @api
end

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/suretax/response.rb', line 6

def body
  @body
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/suretax/response.rb', line 6

def response
  @response
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/suretax/response.rb', line 6

def status
  @status
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/suretax/response.rb', line 26

def success?
  status == 200
end