Class: Mpayer::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mpayer/client.rb

Constant Summary collapse

@@base_uri =
"https://app.mpayer.co.ke/api"

Instance Method Summary collapse

Constructor Details

#initialize(user_no, token) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
# File 'lib/mpayer/client.rb', line 9

def initialize(user_no, token)
  @user_no = user_no
  @token   = token
  @auth    = WSSE::header(@user_no, @token)
  @header  = { 'Content-Type'=> 'application/json', 'Accept' => 'application/json', 'X-WSSE' => "#{@auth}" }
end

Instance Method Details

#all_clientsObject



16
17
18
19
# File 'lib/mpayer/client.rb', line 16

def all_clients
  @all_url = "#{@@base_uri}/clients/all_clients.json?"
  HTTParty.get(@all_url.to_str, headers: @header)
end

#client_accounts(client_id) ⇒ Object



26
27
28
29
# File 'lib/mpayer/client.rb', line 26

def client_accounts(client_id)
  @client_accounts_url = "#{@@base_uri}/clients/#{client_id}/accounts.json"
  HTTParty.get(@client_accounts_url.to_str, headers: @header)
end

#client_payables(client_id) ⇒ Object



41
42
43
44
# File 'lib/mpayer/client.rb', line 41

def client_payables(client_id)
  @client_payables_url ="#{@@base_uri}/clients/#{client_id}/payables"
  HTTParty.get(@client_payables_url.to_str, headers: @header)
end

#client_transactions(ac_id, client_id) ⇒ Object



36
37
38
39
# File 'lib/mpayer/client.rb', line 36

def client_transactions(ac_id, client_id)
  @transactions_url ="#{@@base_uri}/clients/#{client_id}/accounts/#{ac_id}/transactions"
  HTTParty.get(@transactions_url.to_str, headers: @header)
end

#find_account(client_id, account_id) ⇒ Object



31
32
33
34
# File 'lib/mpayer/client.rb', line 31

def (client_id, )
   ="#{@@base_uri}/clients/#{client_id}/accounts/#{account_id}"
  HTTParty.get(.to_str, headers: @header)
end

#new_account(json_msg, client_id) ⇒ Object



46
47
48
49
# File 'lib/mpayer/client.rb', line 46

def (json_msg, client_id)
   ="#{@@base_uri}/clients/#{client_id}/accounts/new.json"
  HTTParty.post(.to_str, body: json_msg.to_json, headers: @header)
end

#new_client(json_msg) ⇒ Object



21
22
23
24
# File 'lib/mpayer/client.rb', line 21

def new_client(json_msg)
  @new_client_url = "#{@@base_uri}/clients.json"
  HTTParty.post(@new_client_url.to_str, body: json_msg.to_json, headers: @header)
end