Search code examples
ruby-on-railsrubyauthorize.net

Ruby / Rails : How can I format this dense data structure in a legible way?


I'm forced to work with the inhumane Authorize.net Ruby SDK for work.

The response I'm getting back from my request @response.transactionResponse when entered into the console yields the following unforgivable mess:

#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 @responseCode="1", @rawResponseCode=nil, @authCode="", @avsResultCode="Y", @cvvResultCode="P", @cavvResultCode="2", @transId="xxx", @refTransID="", @transHash="", @testRequest="0", @accountNumber="XXXX4242", @accountType="Visa", @splitTenderId=nil, @prePaidCard=nil, @messages=#<AuthorizeNet::API::TransactionResponse::Messages:0x00007ff79e756c08 @messages=[#<AuthorizeNet::API::TransactionResponse::Messages::Message:0x00007ff79e74c320 @code="1", @description="This transaction has been approved.", @roxml_references=[#<ROXML::XMLTextRef:0x00007ff79e74c0f0 @opts=#<ROXML::Definition:0x00007ff7981bd680 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="code", @array=false, @blocks=[], @sought_type=:text, @attr_name="code", @name="code">, @instance=#<AuthorizeNet::API::TransactionResponse::Messages::Message:0x00007ff79e74c320 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79e74c0a0 @opts=#<ROXML::Definition:0x00007ff7981bc4b0 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="description", @array=false, @blocks=[], @sought_type=:text, @attr_name="description", @name="description">, @instance=#<AuthorizeNet::API::TransactionResponse::Messages::Message:0x00007ff79e74c320 ...>, @default_namespace="xmlns">]>], @roxml_references=[#<ROXML::XMLObjectRef:0x00007ff79e756140 @opts=#<ROXML::Definition:0x00007ff79aae7ba0 @default=[], @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="messages", @array=true, @blocks=[], @sought_type=AuthorizeNet::API::TransactionResponse::Messages::Message, @attr_name="messages", @name="message">, @instance=#<AuthorizeNet::API::TransactionResponse::Messages:0x00007ff79e756c08 ...>, @default_namespace="xmlns">]>, @errors=nil, @splitTenderPayments=nil, @userFields=nil, @shipTo=nil, @secureAcceptance=nil, @emvResponse=nil, @transHashSha2="", @profile=#<AuthorizeNet::API::CustomerProfileIdType:0x00007ff79e6eb7c8 @customerProfileId="1516819837", @customerPaymentProfileId="1515258810", @customerAddressId=nil, @roxml_references=[#<ROXML::XMLTextRef:0x00007ff79e6eb6d8 @opts=#<ROXML::Definition:0x00007ff79aab73b0 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="customerProfileId", @array=false, @blocks=[], @sought_type=:text, @attr_name="customerProfileId", @name="customerProfileId">, @instance=#<AuthorizeNet::API::CustomerProfileIdType:0x00007ff79e6eb7c8 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79e6eb6b0 @opts=#<ROXML::Definition:0x00007ff79aab6c80 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="customerPaymentProfileId", @array=false, @blocks=[], @sought_type=:text, @attr_name="customerPaymentProfileId", @name="customerPaymentProfileId">, @instance=#<AuthorizeNet::API::CustomerProfileIdType:0x00007ff79e6eb7c8 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79e6eb688 @opts=#<ROXML::Definition:0x00007ff79aab65c8 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="customerAddressId", @array=false, @blocks=[], @sought_type=:text, @attr_name="customerAddressId", @name="customerAddressId">, @instance=#<AuthorizeNet::API::CustomerProfileIdType:0x00007ff79e6eb7c8 ...>, @default_namespace="xmlns">]>, @networkTransId="8N6BXPMY1PG3W833NZWYZRZ", @roxml_references=[#<ROXML::XMLTextRef:0x00007ff79af16d70 @opts=#<ROXML::Definition:0x00007ff7981a7da8 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="responseCode", @array=false, @blocks=[], @sought_type=:text, @attr_name="responseCode", @name="responseCode">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16d48 @opts=#<ROXML::Definition:0x00007ff7981a7178 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="rawResponseCode", @array=false, @blocks=[], @sought_type=:text, @attr_name="rawResponseCode", @name="rawResponseCode">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16d20 @opts=#<ROXML::Definition:0x00007ff7981a6368 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="authCode", @array=false, @blocks=[], @sought_type=:text, @attr_name="authCode", @name="authCode">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16cf8 @opts=#<ROXML::Definition:0x00007ff7981a5698 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="avsResultCode", @array=false, @blocks=[], @sought_type=:text, @attr_name="avsResultCode", @name="avsResultCode">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16cd0 @opts=#<ROXML::Definition:0x00007ff7981a48b0 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="cvvResultCode", @array=false, @blocks=[], @sought_type=:text, @attr_name="cvvResultCode", @name="cvvResultCode">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16ca8 @opts=#<ROXML::Definition:0x00007ff791e0bc18 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="cavvResultCode", @array=false, @blocks=[], @sought_type=:text, @attr_name="cavvResultCode", @name="cavvResultCode">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16c80 @opts=#<ROXML::Definition:0x00007ff791e0b560 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="transId", @array=false, @blocks=[], @sought_type=:text, @attr_name="transId", @name="transId">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16c30 @opts=#<ROXML::Definition:0x00007ff791e0aed0 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="refTransID", @array=false, @blocks=[], @sought_type=:text, @attr_name="refTransID", @name="refTransID">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16be0 @opts=#<ROXML::Definition:0x00007ff791e0a818 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="transHash", @array=false, @blocks=[], @sought_type=:text, @attr_name="transHash", @name="transHash">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16b90 @opts=#<ROXML::Definition:0x00007ff791e0a160 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="testRequest", @array=false, @blocks=[], @sought_type=:text, @attr_name="testRequest", @name="testRequest">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16b40 @opts=#<ROXML::Definition:0x00007ff791e09aa8 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="accountNumber", @array=false, @blocks=[], @sought_type=:text, @attr_name="accountNumber", @name="accountNumber">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16af0 @opts=#<ROXML::Definition:0x00007ff791e09418 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="accountType", @array=false, @blocks=[], @sought_type=:text, @attr_name="accountType", @name="accountType">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16aa0 @opts=#<ROXML::Definition:0x00007ff791e08d88 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="splitTenderId", @array=false, @blocks=[], @sought_type=:text, @attr_name="splitTenderId", @name="splitTenderId">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLObjectRef:0x00007ff79af16a50 @opts=#<ROXML::Definition:0x00007ff791e086f8 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="prePaidCard", @array=false, @blocks=[], @sought_type=AuthorizeNet::API::TransactionResponse::PrePaidCard, @attr_name="prePaidCard", @name="prePaidCard">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLObjectRef:0x00007ff79af16a00 @opts=#<ROXML::Definition:0x00007ff791e08090 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="messages", @array=false, @blocks=[], @sought_type=AuthorizeNet::API::TransactionResponse::Messages, @attr_name="messages", @name="messages">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLObjectRef:0x00007ff79af169d8 @opts=#<ROXML::Definition:0x00007ff79819f1f8 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="errors", @array=false, @blocks=[], @sought_type=AuthorizeNet::API::TransactionResponse::Errors, @attr_name="errors", @name="errors">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLObjectRef:0x00007ff79af169b0 @opts=#<ROXML::Definition:0x00007ff79819dba0 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="splitTenderPayments", @array=false, @blocks=[], @sought_type=AuthorizeNet::API::TransactionResponse::SplitTenderPayments, @attr_name="splitTenderPayments", @name="splitTenderPayments">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLObjectRef:0x00007ff79af16988 @opts=#<ROXML::Definition:0x00007ff79819cf98 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="userFields", @array=false, @blocks=[], @sought_type=AuthorizeNet::API::UserFields, @attr_name="userFields", @name="userFields">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLObjectRef:0x00007ff79af16960 @opts=#<ROXML::Definition:0x00007ff79819c200 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="shipTo", @array=false, @blocks=[], @sought_type=AuthorizeNet::API::NameAndAddressType, @attr_name="shipTo", @name="shipTo">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLObjectRef:0x00007ff79af16938 @opts=#<ROXML::Definition:0x00007ff791e13af8 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="secureAcceptance", @array=false, @blocks=[], @sought_type=AuthorizeNet::API::TransactionResponse::SecureAcceptance, @attr_name="secureAcceptance", @name="secureAcceptance">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLObjectRef:0x00007ff79af16910 @opts=#<ROXML::Definition:0x00007ff791e13490 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="emvResponse", @array=false, @blocks=[], @sought_type=AuthorizeNet::API::TransactionResponse::EmvResponse, @attr_name="emvResponse", @name="emvResponse">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af168e8 @opts=#<ROXML::Definition:0x00007ff791e12e28 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="transHashSha2", @array=false, @blocks=[], @sought_type=:text, @attr_name="transHashSha2", @name="transHashSha2">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLObjectRef:0x00007ff79af168c0 @opts=#<ROXML::Definition:0x00007ff791e12770 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="profile", @array=false, @blocks=[], @sought_type=AuthorizeNet::API::CustomerProfileIdType, @attr_name="profile", @name="profile">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">, #<ROXML::XMLTextRef:0x00007ff79af16870 @opts=#<ROXML::Definition:0x00007ff791e12158 @default=nil, @to_xml=nil, @name_explicit=false, @cdata=nil, @required=nil, @frozen=nil, @wrapper=nil, @namespace=nil, @accessor="networkTransId", @array=false, @blocks=[], @sought_type=:text, @attr_name="networkTransId", @name="networkTransId">, @instance=#<AuthorizeNet::API::TransactionResponse:0x00007ff79af16eb0 ...>, @default_namespace="xmlns">]>

I often use the awesome_print gem or something simlar to format data structures but it has no effect here.

Is there any parsing lib/algorithm that can take was looks like an internal dump format from ruby and display it in some kind of humane/human format?

I'm forced to read the source code for any idea of the interfaces of these classes, so some formatting would be a god send.

Please... my eyes are bleeding.


Solution

  • You can use pretty_inspect from stdlib pretty print(require 'pp') instead of regular inspect, that adds some formatting.

    Classes from AuthorizeNet are huge and no formatting is the silver bullet. A more aggressive way is to monkeypatch inspect method for those to output only fields that are of interest to you