Class: OffsitePayments::Integrations::Mollie::API
- Inherits:
-
Object
- Object
- OffsitePayments::Integrations::Mollie::API
- Includes:
- 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
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #get_request(resource, params = nil) ⇒ Object
-
#initialize(token) ⇒ API
constructor
A new instance of API.
- #post_request(resource, params = nil) ⇒ Object
Constructor Details
#initialize(token) ⇒ API
Returns a new instance of API.
11 12 13 |
# File 'lib/offsite_payments/integrations/mollie.rb', line 11 def initialize(token) @token = token end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/offsite_payments/integrations/mollie.rb', line 7 def token @token end |
Instance Method Details
#get_request(resource, params = nil) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/offsite_payments/integrations/mollie.rb', line 15 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
22 23 24 25 26 27 |
# File 'lib/offsite_payments/integrations/mollie.rb', line 22 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 |