Class: Justifi::JustifiResponse

Inherits:
Object
  • Object
show all
Extended by:
Gem::Deprecate
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.



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

def data
  @data
end

#error_detailsObject

The error hash from JustiFi API



77
78
79
# File 'lib/justifi/justifi_response.rb', line 77

def error_details
  @error_details
end

#error_messageObject

The error error_message from JustiFi API



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

def error_message
  @error_message
end

#http_bodyObject

The raw HTTP body of the response.



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

def http_body
  @http_body
end

#successObject

The boolean flag based on Net::HTTPSuccess



74
75
76
# File 'lib/justifi/justifi_response.rb', line 74

def success
  @success
end

Class Method Details

.from_net_http(http_resp) ⇒ Object

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



81
82
83
84
85
86
87
88
89
90
# File 'lib/justifi/justifi_response.rb', line 81

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)
  resp.error_details = resp.data.dig(:error)
  JustifiResponseBase.populate_for_net_http(resp, http_resp)
  resp
end