Class: Mpayer::Client
- Defined in:
- lib/mpayer/endpoints/client.rb
Instance Attribute Summary collapse
-
#account(account_id = nil, client_id = id) ⇒ Object
Mpayer::Client.find(id:20284).account(accountsid).
-
#accounts(per: 1, per_page: 100) ⇒ Object
Mpayer::Client.find(26, fetch:false).accounts(per:1,per_page:100).
-
#payables(per: 1, per_page: 100) ⇒ Object
Mpayer::Client.find(26, fetch:false).payables(per:1,per_page:100).
-
#transactions(account_id, per: 1, per_page: 100) ⇒ Object
Mpayer::Client.find(26, fetch:false).transactions(account_id, per:1,per_page:100).
Attributes inherited from Endpoint
#attributes, #config, #endpoint, #id, #pagination, #response
Class Method Summary collapse
-
.all(per: 1, per_page: 100) ⇒ Object
Mpayer::Client.all.
-
.create(options = {}) ⇒ Object
client_attributes = { client_name: “Kiki Lolo”, client_birthday: Time.now.iso8601, client_type: “ext”, ac_type: “cu”,client_mobile: ‘073373932’, client_email: ‘[email protected]’,currency: “kes”, mandate:“s”, sub_type: “od” } Mpayer::Client.create(client_attributes).
-
.find(client_id, fetch: true) ⇒ Object
Mpayer::Client.find(id).
Instance Method Summary collapse
-
#create_account(options = {}) ⇒ Object
Mpayer::Client.find(id:20284).create_account(options).
Methods inherited from Endpoint
Constructor Details
This class inherits a constructor from Mpayer::Endpoint
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Mpayer::Endpoint
Instance Attribute Details
#account(account_id = nil, client_id = id) ⇒ Object
Mpayer::Client.find(id:20284).account(accountsid)
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mpayer/endpoints/client.rb', line 31 def account(account_id=nil,client_id=id) account_id ||= @account.id rescue nil raise ArgumentError if client_id.nil? or account_id.nil? url = "/clients/#{client_id}/accounts/#{account_id}" if (@account.id == account_id rescue false) @account ||= Mpayer::Fetch.get(url) else @account = Mpayer::Fetch.get(url) end end |
#accounts(per: 1, per_page: 100) ⇒ Object
Mpayer::Client.find(26, fetch:false).accounts(per:1,per_page:100)
50 51 52 |
# File 'lib/mpayer/endpoints/client.rb', line 50 def accounts(per:1,per_page:100) find_all(per:per,per_page:per_page) end |
#payables(per: 1, per_page: 100) ⇒ Object
Mpayer::Client.find(26, fetch:false).payables(per:1,per_page:100)
55 56 57 |
# File 'lib/mpayer/endpoints/client.rb', line 55 def payables(per:1,per_page:100) find_all(per:per,per_page:per_page) end |
#transactions(account_id, per: 1, per_page: 100) ⇒ Object
Mpayer::Client.find(26, fetch:false).transactions(account_id, per:1,per_page:100)
60 61 62 |
# File 'lib/mpayer/endpoints/client.rb', line 60 def transactions(account_id,per:1,per_page:100) find_all(per:per,per_page:per_page,account_id:account_id) end |
Class Method Details
.all(per: 1, per_page: 100) ⇒ Object
Mpayer::Client.all
8 9 10 11 |
# File 'lib/mpayer/endpoints/client.rb', line 8 def all(per:1,per_page:100) url = "/clients/all_clients" Mpayer::Fetch.get(url,query:{per:per,per_page:per_page}) end |
.create(options = {}) ⇒ Object
client_attributes = { client_name: “Kiki Lolo”, client_birthday: Time.now.iso8601, client_type: “ext”, ac_type: “cu”,client_mobile: ‘073373932’, client_email: ‘[email protected]’,currency: “kes”, mandate:“s”, sub_type: “od” } Mpayer::Client.create(client_attributes)
22 23 24 25 26 |
# File 'lib/mpayer/endpoints/client.rb', line 22 def create(={}) url = "/clients" response = Mpayer::Fetch.post(url,body: .to_json) client = new(.merge!(id:response.id ,response:response)) end |
.find(client_id, fetch: true) ⇒ Object
Mpayer::Client.find(id)
14 15 16 17 18 |
# File 'lib/mpayer/endpoints/client.rb', line 14 def find(client_id,fetch: true) url = "/clients/#{client_id}" response = Mpayer::Fetch.get(url) if fetch client = new(id:client_id,response:response) end |
Instance Method Details
#create_account(options = {}) ⇒ Object
Mpayer::Client.find(id:20284).create_account(options)
44 45 46 47 |
# File 'lib/mpayer/endpoints/client.rb', line 44 def create_account(={}) url = "/clients/#{self.id}/accounts/new" @account = Mpayer::Fetch.post(url,body: .to_json) end |