Class: OffsitePayments::Integrations::MollieIdeal::API

Inherits:
Object
  • Object
show all
Includes:
ActiveMerchant::PostsData
Defined in:
lib/offsite_payments/integrations/mollie_ideal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ API


9
10
11
# File 'lib/offsite_payments/integrations/mollie_ideal.rb', line 9

def initialize(token)
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token


7
8
9
# File 'lib/offsite_payments/integrations/mollie_ideal.rb', line 7

def token
  @token
end

Instance Method Details

#get_request(resource, params = nil) ⇒ Object


13
14
15
16
17
18
# File 'lib/offsite_payments/integrations/mollie_ideal.rb', line 13

def get_request(resource, params = nil)
  uri = URI.parse(MOLLIE_API_V1_URI + resource)
  uri.query = params.map { |k,v| "#{CGI.escape(k)}=#{CGI.escape(v)}}"}.join('&') if params
  headers = { "Authorization" => "Bearer #{token}", "Content-Type" => "application/json" }
  JSON.parse(ssl_get(uri.to_s, headers))
end

#post_request(resource, params = nil) ⇒ Object


20
21
22
23
24
25
# File 'lib/offsite_payments/integrations/mollie_ideal.rb', line 20

def post_request(resource, params = nil)
  uri = URI.parse(MOLLIE_API_V1_URI + resource)
  headers = { "Authorization" => "Bearer #{token}", "Content-Type" => "application/json" }
  data = params.nil? ? nil : JSON.dump(params)
  JSON.parse(ssl_post(uri.to_s, data, headers))
end