Module: Veritrans::Client

Included in:
Veritrans
Defined in:
lib/veritrans/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._json_decode(params) ⇒ Object

If you using Rails then it will call ActiveSupport::JSON.decode Otherwise JSON.parse



27
28
29
30
31
32
33
34
# File 'lib/veritrans/client.rb', line 27

def self._json_decode(params)
  if defined?(ActiveSupport) && defined?(ActiveSupport::JSON)
    ActiveSupport::JSON.decode(params)
  else
    require 'json' unless defined?(JSON)
    JSON.parse(params)
  end
end

._json_encode(params) ⇒ Object

If you using Rails then it will call ActiveSupport::JSON.encode Otherwise JSON.pretty_generate



12
13
14
15
16
17
18
19
# File 'lib/veritrans/client.rb', line 12

def self._json_encode(params)
  if defined?(ActiveSupport) && defined?(ActiveSupport::JSON)
    ActiveSupport::JSON.encode(params)
  else
    require 'json' unless defined?(JSON)
    JSON.pretty_generate(params)
  end
end

Instance Method Details

#_json_encode(params) ⇒ Object



21
22
23
# File 'lib/veritrans/client.rb', line 21

def _json_encode(params)
  Veritrans::Client._json_encode(params)
end

#request_with_logging(method, url, params) ⇒ Object

This is proxy method for make_request to save request and response to logfile



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/veritrans/client.rb', line 37

def request_with_logging(method, url, params)
  short_url = url.sub(config.api_host, '')
  file_logger.info("Perform #{short_url} \nSending: " + _json_encode(params))

  result = make_request(method, url, params)

  if result.status_code < 300
    file_logger.info("Success #{short_url} \nGot: " + _json_encode(result.data) + "\n")
  else
    file_logger.warn("Failed #{short_url} \nGot: " + _json_encode(result.data) + "\n")
  end

  result
end