Class: Justifi::JustifiResponse

Inherits:
Object
  • Object
show all
Includes:
JustifiResponseBase
Defined in:
lib/justifi/justifi_response.rb

Overview

JustifiResponse encapsulates some vitals of a response that came back from the Justifi API.

Instance Attribute Summary collapse

Attributes included from JustifiResponseBase

#http_headers, #http_status, #request_id

Class Method Summary collapse

Methods included from JustifiResponseBase

populate_for_net_http

Instance Attribute Details

#dataObject

The data contained by the HTTP body of the response deserialized from JSON.



63
64
65
# File 'lib/justifi/justifi_response.rb', line 63

def data
  @data
end

#error_messageObject

The error error_message from JustiFi API



69
70
71
# File 'lib/justifi/justifi_response.rb', line 69

def error_message
  @error_message
end

#http_bodyObject

The raw HTTP body of the response.



66
67
68
# File 'lib/justifi/justifi_response.rb', line 66

def http_body
  @http_body
end

#successObject

The boolean flag based on Net::HTTPSuccess



72
73
74
# File 'lib/justifi/justifi_response.rb', line 72

def success
  @success
end

Class Method Details

.from_net_http(http_resp) ⇒ Object

Initializes a JustifiResponse object from a Net::HTTP::HTTPResponse object.



76
77
78
79
80
81
82
83
84
# File 'lib/justifi/justifi_response.rb', line 76

def self.from_net_http(http_resp)
  resp = JustifiResponse.new
  resp.data = JSON.parse(http_resp.body, symbolize_names: true)
  resp.http_body = http_resp.body
  resp.success = http_resp.is_a? Net::HTTPSuccess
  resp.error_message = resp.data.dig(:error, :message)
  JustifiResponseBase.populate_for_net_http(resp, http_resp)
  resp
end