Module: StarkitBanking::ApiClient
- Included in:
- RBL::Account::GetBalance, RBL::Account::GetMiniStatement, RBL::Payment::ByFT2, RBL::Payment::GetStatus, YBL::Account::GetBalance, YBL::Account::GetMiniStatement, YBL::Beneficiary::IMT::Add, YBL::Beneficiary::IMT::Delete, YBL::Payment::ByFT2, YBL::Payment::ByIMT, YBL::Payment::GetStatus
- Defined in:
- lib/starkit_banking/api/client.rb
Instance Method Summary collapse
Instance Method Details
#callbacks(model, req) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/starkit_banking/api/client.rb', line 37 def callbacks(model, req) req_reference_no = req.respond_to?(:uniqueRequestNo) ? req.uniqueRequestNo : nil ApiBanking::Callbacks.new do |c| c.before_send do |r| model.api_step = ApiStep.new( auditable_type: model.class, auditable_id: model.id, star_id: model.star_id, step_name: @step_name, req_reference: req_reference_no, req_timestamp: Time.current, req_bitstream: r.[:body] ) end c.on_complete do |r| model.api_step.assign_attributes( status_code: r.response_code, rep_timestamp: Time.current, rep_bitstream: r.body ) end end end |
#exec(model) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/starkit_banking/api/client.rb', line 10 def exec(model) env = Environment.build(credentials(model)) subscription = subscription(model) raise ApiFault.new(OpenStruct.new(code: 'sb:412', subCode: nil, reasonText: "#{service_name} is not subscribed")) if subscription.nil? req = request(subscription, model) res = invoke(env, req, callbacks(model, req)) if res.instance_of?ApiBanking::Fault # log fault details model.api_step.assign_attributes( fault_code: res.code, fault_subcode: res.subCode, fault_reason: res.reasonText ) # for certain API calls, certain faults are expected, for example, when a retry is made it is not an error raise ApiFault.new(res) else rep_reference_no = res.respond_to?(:uniqueResponseNo) ? res.uniqueResponseNo : nil # log fault details model.api_step.assign_attributes( rep_reference: rep_reference_no ) response(res) end end |
#initialize(step_name = nil) ⇒ Object
6 7 8 |
# File 'lib/starkit_banking/api/client.rb', line 6 def initialize(step_name = nil) @step_name = step_name end |