mpayer 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 634a8252c3d8f79d63e6314b2046c881d47b5c2a
4
+ data.tar.gz: 1ed5df643cc31af828cffd4271dc0cd5e42dca7d
5
+ SHA512:
6
+ metadata.gz: 5ada4a1ddcd843af7b261e30efc8e9ee078b3c13767e58a33e8fa948854cc719925f984a09dfa7372a4c3390e5029fcc901f865b4dc03b758d3d6cc9c9f0e4be
7
+ data.tar.gz: 622b3b1bc85c51a987fbf88ff3ba60cdc1dfe7248e9ee79754a4eb244d15674d02e07900ae031f3df3780178386041e47c4b57797d56fe2c8cb6967f90c0c4ec
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 2.1.1
5
+ - 2.1.0
6
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mpayer.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Charlie Chuck
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ #Mpayer.
2
+ A fast lightweight and minimalist wrapper around the Mpayer api
3
+
4
+ [![Build Status](https://travis-ci.org/chalchuck/mpayer.svg?branch=master)](https://travis-ci.org/chalchuck/mpayer)
5
+ [![Code Climate](https://codeclimate.com/github/chalchuck/mpayer/badges/gpa.svg)](https://codeclimate.com/github/chalchuck/mpayer)
6
+ [![Test Coverage](https://codeclimate.com/github/chalchuck/mpayer/badges/coverage.svg)](https://codeclimate.com/github/chalchuck/mpayer/coverage)
7
+ [![Dependency Status](https://gemnasium.com/chalchuck/mpayer.svg)](https://gemnasium.com/chalchuck/mpayer)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'mpayer'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install mpayer
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/chalchuck/mpayer/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'rake/testtask'
13
+ Rake::TestTask.new(:test) do |test|
14
+ test.libs << 'lib' << 'test'
15
+ test.pattern = 'test/**/test_*.rb'
16
+ test.verbose = true
17
+ end
18
+
19
+ task :default => :test
20
+
21
+ require 'rdoc/task'
22
+ Rake::RDocTask.new do |rdoc|
23
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
24
+
25
+ rdoc.rdoc_dir = 'rdoc'
26
+ rdoc.title = "mpayer #{version}"
27
+ rdoc.rdoc_files.include('README*')
28
+ rdoc.rdoc_files.include('lib/**/*.rb')
29
+ end
@@ -0,0 +1,39 @@
1
+ class Mpayer::Account < Mpayer::Base
2
+
3
+ #GET
4
+ #/accounts/all_accounts.json
5
+ def all
6
+ get('/accounts/all_accounts.json')
7
+ end
8
+
9
+ #GET
10
+ #/accounts/all_accounts?accounts_array=#{ids.join(',')}
11
+ def fetch_by_ids(*ids)
12
+ get("/accounts/all_accounts?accounts_array=#{ids.join(',')}")
13
+ end
14
+
15
+ #GET
16
+ #/accounts/:id
17
+ def fetch_account(id)
18
+ get("/accounts/#{id}.json")
19
+ end
20
+
21
+ #GET
22
+ #/accounts/:id
23
+ def balance(id)
24
+ fetch_account(id)['balance'].to_f
25
+ end
26
+
27
+ #GET
28
+ #/accounts/:account_id/members?per_page=100
29
+ def subscribers(account_id)
30
+ get("/accounts/#{account_id}/members?")
31
+ end
32
+
33
+ #POST
34
+ #/accounts/:account_id/enroll
35
+ def enroll(account_id, json_body)
36
+ post("/accounts/#{account_id}/enroll", json_body)
37
+ end
38
+
39
+ end
@@ -0,0 +1,50 @@
1
+ class Mpayer::Base
2
+
3
+ attr_accessor :user_no, :mpayer_token, :base_url
4
+
5
+ def initialize(user_no: nil, mpayer_token: nil, base_url: 'https://app.mpayer.co.ke/api')
6
+ @base_url ||= base_url
7
+ @user_no ||= user_no
8
+ @mpayer_token ||= mpayer_token
9
+ end
10
+
11
+ def parse_api_response(response)
12
+ JSON.parse(response.body)
13
+ end
14
+
15
+ def auth
16
+ WSSE.header(user_no, mpayer_token).to_s
17
+ end
18
+
19
+ def get(url, per_page=10)
20
+ response = Typhoeus.get("#{base_url}#{url}?per_page=#{per_page}", headers: headers)
21
+ parse_api_response(response)
22
+ end
23
+
24
+ def delete(url)
25
+ response = Typhoeus.delete("#{base_url}#{url}", headers: headers)
26
+ parse_api_response(response)
27
+ end
28
+
29
+ def post(url, body, batch=false)
30
+ headers = batch_headers if batch == true
31
+ response = Typhoeus.post("#{base_url}#{url}", body: body.to_json, headers: headers)
32
+ parse_api_response(response)
33
+ end
34
+
35
+ def put(url, body)
36
+ response = Typhoeus.put("#{base_url}#{url}", body: body.to_json, headers: headers)
37
+ parse_api_response(response)
38
+ end
39
+
40
+ private
41
+
42
+ def headers
43
+ { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-WSSE' => auth }
44
+ end
45
+
46
+ def batch_headers
47
+ { 'Content-Type' => 'application/x-www-form-urlencoded', 'X-WSSE' => auth }
48
+ end
49
+
50
+ end
@@ -0,0 +1,9 @@
1
+ class Mpayer::Batch < Mpayer::Base
2
+
3
+ #POST
4
+ #/batch
5
+ def fetch(args)
6
+ batch_post("#{base_url}/batch", body: "requests=#{args[0].to_json}", batch=true)
7
+ end
8
+
9
+ end
@@ -0,0 +1,45 @@
1
+ class Mpayer::Client < Mpayer::Base
2
+
3
+ #GET
4
+ #/clients/all_clients.json
5
+ def all
6
+ get('/clients/all_clients.json')
7
+ end
8
+
9
+ #POST
10
+ #/clients.json
11
+ def create_on_mpayer(json_body)
12
+ post("/clients.json", body: json_body)
13
+ end
14
+
15
+ #GET
16
+ #/clients/:id #id: 21556
17
+ def fetch_client(id)
18
+ get("/clients/#{id}.json")
19
+ end
20
+
21
+ # /clients/:id/accounts.json"
22
+ # GET
23
+ def fetch_accounts(id)
24
+ get("/clients/#{id}/accounts.json")
25
+ end
26
+
27
+ # /clients/:client_id/accounts.json"
28
+ # GET
29
+ def fetch_account(id)
30
+ get("/clients/#{id}/accounts.json")
31
+ end
32
+
33
+ #GET
34
+ #/clients/:client_id/accounts/:ac_id/transactions"
35
+ def fetch_transactions(client_id, ac_id)
36
+ get("/clients/#{client_id}/accounts/#{ac_id}/transactions.json")
37
+ end
38
+
39
+ #POST
40
+ #/clients/:client_id/accounts/new.json
41
+ def create_client_account(id, json_body)
42
+ post("/clients/#{id}/accounts/new.json", body: json_body)
43
+ end
44
+
45
+ end
@@ -0,0 +1,33 @@
1
+ class Mpayer::Payable < Mpayer::Base
2
+
3
+ #GET
4
+ #/payables/all.json
5
+ def all
6
+ get('/payables/all.json')
7
+ end
8
+
9
+ #POST
10
+ #/payables
11
+ def create_payable(json_body)
12
+ post('/payables', json_body)
13
+ end
14
+
15
+ #DELETE
16
+ #/payables/id
17
+ def delete(id)
18
+ delete("/payables/#{id}")
19
+ end
20
+
21
+ #GET
22
+ #/payables/all.json?payable_ids=#{ids.join(',')}
23
+ def get_by_ids(ids)
24
+ get("/payables/all.json?payable_ids=#{ids.join(',')}")
25
+ end
26
+
27
+ #GET
28
+ #/accounts/:account_id/payable_items.json?per_page=100
29
+ def payable_items(account_id)
30
+ get("/accounts/#{account_id}/payable_items.json?", 100)
31
+ end
32
+
33
+ end
data/lib/mpayer/sms.rb ADDED
@@ -0,0 +1,10 @@
1
+ class Mpayer::Sms < Mpayer::Base
2
+
3
+ #POST
4
+ #/messages
5
+ #
6
+ def send_message(json_msg)
7
+ HTTParty.post('/messages', body: json_msg)
8
+ end
9
+
10
+ end
@@ -0,0 +1,51 @@
1
+ class Mpayer::Transaction < Mpayer::Base
2
+
3
+ #GET
4
+ #/transactions/all
5
+ def all
6
+ get('/transactions/all')
7
+ end
8
+
9
+ #PUT
10
+ #/transactions/deposit
11
+ #`ref_id: 'this is a unique field for every transaction(can be used to id a transaction)'
12
+ #`amount: 'this is the amount being transfered'
13
+ #`cr_party: 'this is the recipient(can be an account number or a payable number)'
14
+ #############when it is a payable number a '#' is prepended to
15
+ ############indicate: deposit as per the propotions in the payable
16
+ ##example => {ref_id:"EO4GM2GOGXWPGZ", amount:"200", cr_party:"#GOGXWP"}
17
+ #
18
+ def deposit(json_body)
19
+ put('/transactions/deposit', json_body)
20
+ end
21
+
22
+ #POST
23
+ #/transactions/withdraw
24
+ ############Parameters [all the listed parameters are manadatory]
25
+ #`ref_id: 'this is a unique field for every transaction(can be used to id a transaction)'
26
+ #`amount: 'this is the amount being transfered'
27
+ #`dr_party: 'this is the sender'
28
+ #`cr_party: 'this is the recipient(can be an account number or a payable number)'
29
+ #############when it is a payable number a '#' is prepended to
30
+ ############indicate: withdraw as per the propotions in the payable
31
+ #example=> {ref_id:"345345244545345",amount:"10",cr_party:"#GOGXWP",dr_party:"00043230652927"}
32
+ #
33
+ def withdraw(json_body)
34
+ post('/transactions/withdraw', json_body)
35
+ end
36
+
37
+ #POST
38
+ #/transactions/transfer
39
+ #Parameters [all the listed parameters are manadatory]
40
+ #`ref_id: 'this is a unique field for every transaction(can be used to id a transaction)'
41
+ #`amount: 'this is the amount being transfered'
42
+ #`cr_party: 'this is the recipient(can be an account number or a payable number)'
43
+ #`dr_party: 'this is the sender'
44
+ #############when it is a payable number a '#' is prepended to indicate pay.
45
+ #example: ==> {ref_id:"EO4GM2GOGXWPGZ",amount:"36", cr_party:"#GOGXWP", dr_party:"0004354652927"}
46
+ #
47
+ def transfer(json_body)
48
+ post('/transactions/transfer', json_body)
49
+ end
50
+
51
+ end
@@ -0,0 +1,3 @@
1
+ module Mpayer
2
+ VERSION = "0.0.6"
3
+ end
data/lib/mpayer.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Mpayer
2
+ require 'typhoeus'
3
+ require 'json'
4
+ require 'mpayer/account'
5
+ require 'mpayer/base'
6
+ require 'mpayer/batch'
7
+ require 'mpayer/client'
8
+ require 'mpayer/payable'
9
+ require 'mpayer/sms'
10
+ require 'mpayer/transaction'
11
+ require "mpayer/version"
12
+ end
data/mpayer.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'mpayer/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "mpayer"
7
+ spec.version = Mpayer::VERSION
8
+ spec.authors = ["Charles Chuck"]
9
+ spec.email = ["chalcchuck@gmail.com"]
10
+ spec.summary = %q{A ruby library for Mpayer}
11
+ spec.description = %q{A ruby library for Mpayer.}
12
+ spec.homepage = "https://github.com/chalchuck/mpayer"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency 'json', '~>1.0'
21
+ spec.add_runtime_dependency 'typhoeus', '~> 0.6', '>= 0.7.2'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.0"
24
+ spec.add_development_dependency "rake", '~> 10.0'
25
+ spec.add_development_dependency 'pry', '~> 0.5', '>= 0.9.0'
26
+ spec.add_development_dependency 'minitest', '~> 4.7.0'
27
+ spec.add_development_dependency 'minitest-reporters', '~> 0.7'
28
+ spec.add_development_dependency 'shoulda-context', '~> 1.0', '>= 1.2.1'
29
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mpayer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Charles Chuck
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: typhoeus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: 0.7.2
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.6'
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.7.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: pry
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: '0.5'
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: 0.9.0
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ version: '0.5'
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: 0.9.0
95
+ - !ruby/object:Gem::Dependency
96
+ name: minitest
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 4.7.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ version: 4.7.0
109
+ - !ruby/object:Gem::Dependency
110
+ name: minitest-reporters
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ~>
114
+ - !ruby/object:Gem::Version
115
+ version: '0.7'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ~>
121
+ - !ruby/object:Gem::Version
122
+ version: '0.7'
123
+ - !ruby/object:Gem::Dependency
124
+ name: shoulda-context
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ~>
128
+ - !ruby/object:Gem::Version
129
+ version: '1.0'
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: 1.2.1
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ~>
138
+ - !ruby/object:Gem::Version
139
+ version: '1.0'
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: 1.2.1
143
+ description: A ruby library for Mpayer.
144
+ email:
145
+ - chalcchuck@gmail.com
146
+ executables: []
147
+ extensions: []
148
+ extra_rdoc_files: []
149
+ files:
150
+ - .gitignore
151
+ - .travis.yml
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - lib/mpayer.rb
157
+ - lib/mpayer/account.rb
158
+ - lib/mpayer/base.rb
159
+ - lib/mpayer/batch.rb
160
+ - lib/mpayer/client.rb
161
+ - lib/mpayer/payable.rb
162
+ - lib/mpayer/sms.rb
163
+ - lib/mpayer/transaction.rb
164
+ - lib/mpayer/version.rb
165
+ - mpayer.gemspec
166
+ homepage: https://github.com/chalchuck/mpayer
167
+ licenses:
168
+ - MIT
169
+ metadata: {}
170
+ post_install_message:
171
+ rdoc_options: []
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - '>='
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - '>='
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubyforge_project:
186
+ rubygems_version: 2.2.2
187
+ signing_key:
188
+ specification_version: 4
189
+ summary: A ruby library for Mpayer
190
+ test_files: []