mpayer_ruby 0.0.09 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d1756eb098c3a60e5b83f2447f8a7d59229488a
4
- data.tar.gz: 5c31a65abb6cc108b7138457bd40509062ce8fce
3
+ metadata.gz: f16f461bac9407c17afcf540d4095a091965ed8d
4
+ data.tar.gz: 194c8a4618311845f991401be2624d752f9c1bf6
5
5
  SHA512:
6
- metadata.gz: 897e2e56ecb64e9bc1f6e1fe2247c541e8c0f0c77d1e6bd77b94cc275c3c96450126e08c2384101a7c96fcc75d4148e310dd036515deca2177ea57b9332f5b3f
7
- data.tar.gz: 5a57aca6a2c5cad0a7e8d55cc62636e6f87f70cb56b1687396526e479ea92ab16d65a4133c0d81ce3eeda901a40cd4bb631fa64ec6315dc7e2540ff64deb41d9
6
+ metadata.gz: 6aa9d45fe3ce0d126c1b0a453cbe3cbd62da017e6c13387217d24bdb006cd8c370c424ad0bdf40e249f285027940ff0de60ed35d6682423aa06d9a2a1ca49ffe
7
+ data.tar.gz: 25c7d112955514318ebe54ea7c78f9cf243e65d352a83314e56cd1ebb61b861a3c18820afb99f47be97ff6f6ac1edf5d3e6cc39d2f50818ff029228c9dd749dc
data/Guardfile CHANGED
@@ -26,7 +26,6 @@
26
26
  guard :minitest do
27
27
  # with Minitest::Unit
28
28
  watch(%r{^test/(.*)\/?(.*)_test\.rb$})
29
- watch(%r{^test/support/(.*)\/?(.*)\.*$})
30
29
  watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
31
30
  watch(%r{^test/test_helper\.rb$}) { 'test' }
32
31
 
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "mpayer"
4
+ require "mpayer_ruby"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -2,8 +2,8 @@ module Mpayer
2
2
  class Configuration
3
3
  attr_accessor :user_no, :token, :base_url
4
4
 
5
- def initialize(user_no:nil,token:nil)
6
- @base_url = 'https://app.mpayer.co.ke/api/'
5
+ def initialize(user_no:nil,token:nil,base_url:'https://app.mpayer.co.ke/api/')
6
+ @base_url ||= base_url
7
7
  @user_no ||= user_no
8
8
  @token ||= token
9
9
  end
@@ -13,7 +13,7 @@ module Mpayer
13
13
  end
14
14
 
15
15
  def header
16
- {'Content-Type'=> 'application/json', 'Accept' => 'application/json', 'X-WSSE' => auth }
16
+ {'Content-Type'=> 'application/json', 'Accept' => 'application/json', 'X-WSSE' => auth.to_s}
17
17
  end
18
18
 
19
19
  end
@@ -22,7 +22,7 @@ module Mpayer
22
22
  def create(options={})
23
23
  url = "/clients"
24
24
  response = Mpayer::Fetch.post(url,body: options.to_json)
25
- client = new(options.merge!(id:response.id ,response:response))
25
+ client = new(options.merge!(id:response.id ,response:response, account: response.account.first))
26
26
  end
27
27
 
28
28
  end
@@ -30,7 +30,7 @@ module Mpayer
30
30
  # Mpayer::Client.find(id:20284).account(accountsid)
31
31
  def account(account_id=nil,client_id=id)
32
32
  account_id ||= @account.id rescue nil
33
- raise ArgumentError if client_id.nil? or account_id.nil?
33
+ raise "Arguments missing: account_id or client_id" if client_id.nil? or account_id.nil?
34
34
  url = "/clients/#{client_id}/accounts/#{account_id}"
35
35
  if (@account.id == account_id rescue false)
36
36
  @account ||= Mpayer::Fetch.get(url)
@@ -0,0 +1,22 @@
1
+ module Mpayer
2
+ class Message < Mpayer::Endpoint
3
+
4
+ class << self
5
+ # message_attributes = {message: 'Please send me a message', destination:'0722737343,343843843'}
6
+ # Mpayer::Message.create(message_attributes)
7
+ def create(options={})
8
+ url = "/messages"
9
+ response = Mpayer::Fetch.post(url,body: options.to_json)
10
+ message = new(options.merge!(id:response.id ,response:response))
11
+ end
12
+
13
+ end
14
+
15
+ protected
16
+
17
+ def after_initialize
18
+ @endpoint = 'messages'
19
+ end
20
+
21
+ end
22
+ end
@@ -1,7 +1,7 @@
1
1
  module Mpayer
2
2
  class Fetch
3
3
  include HTTParty
4
- # base_uri "http://beta.json-generator.com"
4
+
5
5
  base_uri "https://app.mpayer.co.ke/api/"
6
6
  parser proc {|data| Hashie::Mash.new(response: (JSON.parse(data) rescue {data:data}.to_json) ).response}
7
7
  format :json
@@ -26,7 +26,7 @@ module Mpayer
26
26
  def save_json(response)
27
27
  request_method = response.request.http_method.name.split('::').last.upcase
28
28
  file_path = response.request.path.to_s
29
- slash,model,*file_name = file_path.split('/')
29
+ slash,model,*file_name = file_path.split(/\/|\?/)
30
30
  file_location = "lib/mpayer_ruby/support/fake_mpayer/#{model}/#{request_method}_#{file_name.join('_')}.json"
31
31
  File.write(file_location, response.body)
32
32
  end
@@ -8,7 +8,7 @@ class FakeMpayer < Sinatra::Base
8
8
  if (request.env['HTTP_X_WSSE'].empty? rescue true)
9
9
  [200, {}, [{base:["Authentication Failed"]}.to_json]]
10
10
  else
11
- slash,api,model,*path = request.path_info.split('/')
11
+ slash,api,model,*path = request.path_info.split(/\/|\?/)
12
12
  json_response 200, "#{model}/#{request.request_method}_#{path.join('_')}.json"
13
13
  end
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module Mpayer
2
- VERSION = "0.0.09"
2
+ VERSION = "0.0.10"
3
3
  end
data/lib/mpayer_ruby.rb CHANGED
@@ -4,11 +4,12 @@ require "hashie"
4
4
  require "mpayer_ruby/version"
5
5
  require "mpayer_ruby/configuration"
6
6
  require "mpayer_ruby/fetch"
7
- require "mpayer_ruby/endpoints/endpoint"
7
+ require "mpayer_ruby/endpoints/_endpoint"
8
8
  require "mpayer_ruby/endpoints/client"
9
9
  require "mpayer_ruby/endpoints/transaction"
10
10
  require "mpayer_ruby/endpoints/account"
11
11
  require "mpayer_ruby/endpoints/payable"
12
+ require "mpayer_ruby/endpoints/message"
12
13
 
13
14
  # begin
14
15
  # require "pry"
@@ -19,22 +20,22 @@ require "mpayer_ruby/endpoints/payable"
19
20
  module Mpayer
20
21
  class << self
21
22
  attr_writer :configuration
22
- end
23
23
 
24
- def self.configuration
25
- @configuration ||= Configuration.new
26
- end
24
+ def configuration
25
+ @configuration ||= Configuration.new
26
+ end
27
27
 
28
- def self.reset
29
- @configuration = Configuration.new
30
- end
28
+ def reset
29
+ @configuration = Configuration.new
30
+ end
31
31
 
32
- def self.setup
33
- yield(configuration)
34
- end
32
+ def setup
33
+ yield(configuration)
34
+ end
35
35
 
36
- def self.login
37
- Mpayer::Fetch.post('/login',post: {user_no: ENV['MPAYER_USER'],password:ENV['MPAYER_PASSWORD']}.to_json)
38
- end
36
+ def login
37
+ Mpayer::Fetch.post('/login',post: {user_no: ENV['MPAYER_USER'],password:ENV['MPAYER_PASSWORD']}.to_json)
38
+ end
39
+ end
39
40
 
40
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mpayer_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.09
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kariuki Gathitu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -241,15 +241,17 @@ files:
241
241
  - lib/mpayer-ruby.rb
242
242
  - lib/mpayer_ruby.rb
243
243
  - lib/mpayer_ruby/configuration.rb
244
+ - lib/mpayer_ruby/endpoints/_endpoint.rb
244
245
  - lib/mpayer_ruby/endpoints/account.rb
245
246
  - lib/mpayer_ruby/endpoints/client.rb
246
- - lib/mpayer_ruby/endpoints/endpoint.rb
247
+ - lib/mpayer_ruby/endpoints/message.rb
247
248
  - lib/mpayer_ruby/endpoints/payable.rb
248
249
  - lib/mpayer_ruby/endpoints/transaction.rb
249
250
  - lib/mpayer_ruby/fetch.rb
250
251
  - lib/mpayer_ruby/support/fake_mpayer.rb
251
252
  - lib/mpayer_ruby/support/fake_mpayer/accounts/.keep
252
253
  - lib/mpayer_ruby/support/fake_mpayer/clients/.keep
254
+ - lib/mpayer_ruby/support/fake_mpayer/messages/.keep
253
255
  - lib/mpayer_ruby/support/fake_mpayer/payables/.keep
254
256
  - lib/mpayer_ruby/support/fake_mpayer/transactions/.keep
255
257
  - lib/mpayer_ruby/version.rb