Class: AuthorizeNetReporting::Response
- Inherits:
-
Object
- Object
- AuthorizeNetReporting::Response
- Defined in:
- lib/authorize_net_reporting/response.rb
Overview
AuthorizeNetReporting::Response parses the response from Authorize.net API and turns results into objects setting attributes for easy integration
Class Method Summary collapse
-
.create_class(class_name, params) ⇒ Object
Create objects dinamically.
-
.parse_batch_statistics(response) ⇒ Object
Parse response for batch_statistics.
-
.parse_settled_batch_list(response) ⇒ Object
Parse response for settled_batch_list.
-
.parse_transaction_details(response) ⇒ Object
Parse response transaction_details.
-
.parse_transaction_list(response) ⇒ Object
Parse response for transaction_list.
-
.parse_unsettled_transaction_list(response) ⇒ Object
Parse response unsettled_transaction.
-
.to_single_hash(hash, first_iteration = nil) ⇒ Object
Convert response nested hash into a single hash param hash.
Class Method Details
.create_class(class_name, params) ⇒ Object
Create objects dinamically
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/authorize_net_reporting/response.rb', line 73 def self.create_class(class_name, params) params = to_single_hash(params, true) if AuthorizeNetReporting.const_defined?(class_name) klass = AuthorizeNetReporting.const_get(class_name) else klass = AuthorizeNetReporting.const_set(class_name, Class.new) klass.class_eval do define_method(:initialize) do |params| params.each do |key, value| self.class.__send__(:attr_accessor, key) instance_variable_set("@#{key}", value) end end end end klass.new(params) end |
.parse_batch_statistics(response) ⇒ Object
Parse response for batch_statistics
19 20 21 22 23 24 |
# File 'lib/authorize_net_reporting/response.rb', line 19 def self.parse_batch_statistics(response) return nil if response[:get_batch_statistics_response][:batch].nil? batch = response[:get_batch_statistics_response][:batch] batch.merge!(:statistics => [batch[:statistics][:statistic]].flatten) unless batch[:statistics].nil? create_class("Batch", batch) end |
.parse_settled_batch_list(response) ⇒ Object
Parse response for settled_batch_list
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/authorize_net_reporting/response.rb', line 6 def self.parse_settled_batch_list(response) batches = [] unless response[:get_settled_batch_list_response][:batch_list].nil? batch_list = [response[:get_settled_batch_list_response][:batch_list][:batch]].flatten batch_list.each do |batch| batch.merge!(:statistics => [batch[:statistics][:statistic]].flatten) unless batch[:statistics].nil? batches << create_class("Batch", batch) end end batches end |
.parse_transaction_details(response) ⇒ Object
Parse response transaction_details
53 54 55 56 57 |
# File 'lib/authorize_net_reporting/response.rb', line 53 def self.parse_transaction_details(response) return nil if response[:get_transaction_details_response][:transaction].nil? transaction = response[:get_transaction_details_response][:transaction] create_class("AuthorizeNetTransaction", transaction) end |
.parse_transaction_list(response) ⇒ Object
Parse response for transaction_list
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/authorize_net_reporting/response.rb', line 27 def self.parse_transaction_list(response) transactions = [] unless response[:get_transaction_list_response][:transactions].nil? transaction_list = [response[:get_transaction_list_response][:transactions][:transaction]].flatten transaction_list.each do |transaction| transactions << create_class("AuthorizeNetTransaction", transaction) end end transactions end |
.parse_unsettled_transaction_list(response) ⇒ Object
Parse response unsettled_transaction
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/authorize_net_reporting/response.rb', line 40 def self.parse_unsettled_transaction_list(response) transactions = [] unless response[:get_unsettled_transaction_list_response][:transactions].nil? unsettled_transactions = [response[:get_unsettled_transaction_list_response][:transactions][:transaction]].flatten unsettled_transactions.each do |transaction| transactions << create_class("AuthorizeNetTransaction", transaction) end end transactions end |
.to_single_hash(hash, first_iteration = nil) ⇒ Object
Convert response nested hash into a single hash param hash
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/authorize_net_reporting/response.rb', line 61 def self.to_single_hash(hash, first_iteration = nil) @temp_hash = {} if first_iteration == true hash.each do |key, value| case value when Hash then to_single_hash(value) when String, Integer, Array then @temp_hash[key] = value end end @temp_hash end |