Class: ApiBanking::JsonClient

Inherits:
Object
  • Object
show all
Defined in:
lib/api_banking/json/json_client.rb

Class Method Summary collapse

Class Method Details

.do_remote_call(env, dataHash, callbacks = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/api_banking/json/json_client.rb', line 6

def self.do_remote_call(env, dataHash, callbacks = nil)
  options = {}
  options[:method] = :post

  add_signature(dataHash)
  options[:body] = JSON.generate(dataHash)

  options[:headers] = {'Content-Type' => "application/json; charset=utf-8", 'User-Agent' => "Quantiguous; API Banking, Ruby Gem #{ApiBanking::VERSION}"}

  set_options_for_environment(env, options)
  set_params_for_environment(env, options)

  request = Typhoeus::Request.new(env.endpoints[self.name.split('::').last.to_sym], options)

  callbacks.before_send.call(request) if (callbacks && callbacks.before_send.respond_to?(:call))
  response = request.run
  callbacks.on_complete.call(request.response) if (callbacks && callbacks.on_complete.respond_to?(:call))
  
  Thread.current[:last_response] = response

  parse_response(response)
end