Class: PuntoPagos::Executioner

Inherits:
Object
  • Object
show all
Defined in:
lib/puntopagos/executioner.rb

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ Executioner

Returns a new instance of Executioner.



6
7
8
9
# File 'lib/puntopagos/executioner.rb', line 6

def initialize env = nil
  @@config ||= PuntoPagos::Config.new(env)
  @@puntopagos_base_url ||= @@config.puntopagos_base_url
end

Instance Method Details

#call_api(data, path, method, signature, timestamp) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/puntopagos/executioner.rb', line 11

def call_api data, path, method, signature, timestamp
  #hack fix: JSON.unparse doesn't work in Rails 2.3.5; only {}.to_json does..
  headers          = set_headers(signature, timestamp)
  #api_request_data = JSON.unparse(data) rescue data.to_json
  if method == :post
    resp             = RestClient.method(method).call(@@puntopagos_base_url+path, data.to_json, headers)
  elsif method == :get
    puts "METHOD: #{method} URL:#{@@puntopagos_base_url} PATH:#{path}"
    resp             = RestClient.method(method).call(@@puntopagos_base_url+path+"/"+data, headers)
  end
  JSON.parse(resp)
end