Class: Omnipay::Adapters::Mangopay::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/omnipay/adapters/mangopay/client.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, opts = {}) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
25
26
27
28
29
# File 'lib/omnipay/adapters/mangopay/client.rb', line 20

def initialize(key, secret, opts = {})
  @key = key
  @secret = secret

  if opts[:sandbox]
    @base_uri = 'https://api.sandbox.mangopay.com/v2'
  else
    @base_uri = 'https://api.mangopay.com/v2'
  end
end

Instance Method Details

#get(path) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/omnipay/adapters/mangopay/client.rb', line 31

def get(path)
  response = self.class.get "/#{@key}#{path}", 
    :basic_auth => {:username => @key, :password => @secret}, 
    :base_uri => @base_uri

  check_errors(response)

  response.parsed_response.merge("code" => response.code)
end

#post(path, params = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/omnipay/adapters/mangopay/client.rb', line 41

def post(path, params = {})
  response = self.class.post "/#{@key}#{path}", 
    :body => params.to_json,
    :basic_auth => {:username => @key, :password => @secret},
    :base_uri => @base_uri

  check_errors(response)

  response.parsed_response.merge("code" => response.code)
end