Module: K2ConnectRuby::K2Utilities::K2ProcessResult
- Extended by:
- K2ProcessResult
- Included in:
- K2ProcessResult
- Defined in:
- lib/k2-connect-ruby/k2_utilities/k2_process_result.rb
Instance 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.
Instance Method Details
#check_type(payload) ⇒ Object
Check the Event Type.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_result.rb', line 12 def check_type(payload) result_type = payload.dig('data', 'type') case result_type # Incoming Payments when 'incoming_payment' incoming_payments = K2ConnectRuby::K2Services::Payloads::Transactions::IncomingPayment.new(payload) return incoming_payments # Outgoing Payments when 'payment' outgoing_payments = K2ConnectRuby::K2Services::Payloads::Transactions::OutgoingPayment.new(payload) return outgoing_payments when 'settlement_transfer' transfer = K2ConnectRuby::K2Services::Payloads::Transactions::Transfer.new(payload) return transfer else raise ArgumentError, 'No Other Specified Payment Type!' end end |
#process(payload, secret_key, signature) ⇒ Object
6 7 8 9 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_result.rb', line 6 def process(payload, secret_key, signature) raise ArgumentError, 'Empty/Nil Request Body Argument!' if payload.blank? check_type(payload) if K2ConnectRuby::K2Utilities::K2Authenticator.authenticate(payload, secret_key, signature) end |
#return_obj_array(instance_array = [], obj) ⇒ Object
Returns an Array Object
40 41 42 43 44 45 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_result.rb', line 40 def 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
32 33 34 35 36 37 |
# File 'lib/k2-connect-ruby/k2_utilities/k2_process_result.rb', line 32 def 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 |