Module: K2ProcessResult
- Defined in:
- lib/k2-connect-ruby/k2_utilities/k2_process_result.rb
Overview
Processes Results
Class Method Summary collapse
-
.check_type(payload) ⇒ Object
Check the Event Type.
- .process(payload, secret_key, signature) ⇒ Object
-
.return_obj_array(instance_array = [], obj) ⇒ Object
Returns an Array Object.
-
.return_obj_hash(instance_hash = HashWithIndifferentAccess.new, obj) ⇒ Object
Returns a Hash Object.
Class Method Details
.check_type(payload) ⇒ Object
Check the Event Type.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_result.rb', line 9 def self.check_type(payload) result_type = payload.dig('data', 'type') case result_type # Incoming Payments when 'incoming_payment' incoming_payments = IncomingPayments.new(payload) return incoming_payments # Outgoing Payments when 'payment' outgoing_payments = OutgoingPayment.new(payload) return outgoing_payments when 'settlement_transfer' transfer = Transfer.new(payload) return transfer else raise ArgumentError, 'No Other Specified Payment Type!' end end |
.process(payload, secret_key, signature) ⇒ Object
3 4 5 6 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_result.rb', line 3 def self.process(payload, secret_key, signature) raise ArgumentError, 'Empty/Nil Request Body Argument!' if payload.blank? self.check_type(payload) if K2Authenticator.authenticate(payload, secret_key, signature) end |
.return_obj_array(instance_array = [], obj) ⇒ Object
Returns an Array Object
37 38 39 40 41 42 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_result.rb', line 37 def self.return_obj_array(instance_array = [], obj) obj.instance_variables.each do |value| instance_array << obj.instance_variable_get(value) end instance_array.each(&:freeze).freeze end |
.return_obj_hash(instance_hash = HashWithIndifferentAccess.new, obj) ⇒ Object
Returns a Hash Object
29 30 31 32 33 34 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_result.rb', line 29 def self.return_obj_hash(instance_hash = HashWithIndifferentAccess.new, obj) obj.instance_variables.each do |value| instance_hash[:"#{value.to_s.tr('@', '')}"] = obj.instance_variable_get(value) end instance_hash.each(&:freeze).freeze end |