Class: SlimpayClient::Base
- Inherits:
-
Object
- Object
- SlimpayClient::Base
- Defined in:
- lib/slimpay_client/base.rb
Overview
Defines constants, main variables, requests options.
Connect to the API through OAuth2 and generates API’s first resources GET methods.
Usage:
slimpay = SlimpayClient::Base.new(client_id = '1234', client_secret = '987654321', creditor_reference = 'azerty')
slimpay.api_methods
=>
{ "post_token"=>"https://api-sandbox.slimpay.net/oauth/token",
"create_orders"=>"https://api-sandbox.slimpay.net/orders",
"get_creditors"=>"https://api-sandbox.slimpay.net/creditors{?reference}",
"get_orders"=>"https://api-sandbox.slimpay.net/orders{?creditorReference,reference}",
"get_mandates"=>"https://api-sandbox.slimpay.net/mandates{?creditorReference,rum}",
"create_documents"=>"https://api-sandbox.slimpay.net/documents",
"get_documents"=>"https://api-sandbox.slimpay.net/documents{?creditorReference,entityReference,reference}",
"create_direct_debits"=>"https://api-sandbox.slimpay.net/direct-debits",
"get_direct_debits"=>"https://api-sandbox.slimpay.net/direct-debits{?id}",
"create_recurrent_direct_debits"=>"https://api-sandbox.slimpay.net/recurrent-direct-debits",
"get_recurrent_direct_debits"=>"https://api-sandbox.slimpay.net/recurrent-direct-debits{?id}",
"get_card_transactions"=>"https://api-sandbox.slimpay.net/card-transactions{?id}",
"get_card_transaction_issues"=>"https://api-sandbox.slimpay.net/card-transaction-issues{?id}",
"profile"=>"https://api-sandbox.slimpay.net/alps/v1"}
Arguments
client_id: (String)
client_secret: (String)
creditor_reference: (String)
Direct Known Subclasses
Instance Method Summary collapse
-
#generate_api_methods(response) ⇒ Object
Root endpoint provides GET links to resources.
-
#initialize ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
29 30 31 32 33 34 |
# File 'lib/slimpay_client/base.rb', line 29 def initialize init_config connect_api_with_oauth api_response = JSON.parse(request_to_api) generate_api_methods(api_response) end |
Instance Method Details
#generate_api_methods(response) ⇒ Object
Root endpoint provides GET links to resources. This methods create a method for each resources. It will also create new methods from future answers.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/slimpay_client/base.rb', line 39 def generate_api_methods(response) methods = {} links = response['_links'] links = links.merge(response['_embedded']['items'].first['_links']) if response['_embedded'] && response['_embedded']['items'] return if links.nil? links.each do |k, v| name = k.gsub('https://api.slimpay.net/alps#', '').underscore next if @methods && @methods.keys.include?(name) && !k.eql?('self') url = v['href'] api_args = url.scan(/{\?(.*),?}/).flatten.first methods[name] = generate_method(name, url, api_args) end list_api_methods(methods) end |