Class: OffsitePayments::Integrations::Mollie::API

Inherits:
Object
  • Object
show all
Includes:
ActiveUtils::NetworkConnectionRetries, ActiveUtils::PostsData
Defined in:
lib/offsite_payments/integrations/mollie.rb

Constant Summary collapse

MOLLIE_API_V1_URI =
'https://api.mollie.nl/v1/'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ API

Returns a new instance of API.



12
13
14
# File 'lib/offsite_payments/integrations/mollie.rb', line 12

def initialize(token)
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



8
9
10
# File 'lib/offsite_payments/integrations/mollie.rb', line 8

def token
  @token
end

Instance Method Details

#get_request(resource, params = nil) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/offsite_payments/integrations/mollie.rb', line 16

def get_request(resource, params = nil)
  retry_exceptions({retry_safe: true}) do
    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
end

#post_request(resource, params = nil) ⇒ Object



25
26
27
28
29
30
# File 'lib/offsite_payments/integrations/mollie.rb', line 25

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