Skip to content

Commit

Permalink
Mpayer_ruby v 0.0.15 Added timezone support
Browse files Browse the repository at this point in the history
  • Loading branch information
kgathi2 committed Aug 10, 2015
1 parent ac446cb commit d18af93
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 15 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ clients = Mpayer::Client.all
client = Mpayer::Client.find(id) #Instantiates and hits the api
client = Mpayer::Client.find(id, fetch:false) #Instantiates only

client_attributes = {client: { client_name: "Kiki Lolo", client_birthday: Time.now.iso8601, client_type: "ext", ac_type: "cu",client_mobile: '0733222222', client_email: 'lolo@kiki.com',currency: "kes", mandate:"s", sub_type: "od" }}
client_attributes = {client: { client_name: "Kiki Lolo", client_birthday: Time.zone.now.iso8601, client_type: "ext", ac_type: "cu",client_mobile: '0733222222', client_email: 'lolo@kiki.com',currency: "kes", mandate:"s", sub_type: "od" }}
client = Mpayer::Client.create(client_attributes)

client = Mpayer::Client.find(id:20284,fetch:false).account(account_id) # Get clients account with id
Expand All @@ -125,7 +125,7 @@ account = Mpayer::Account.find(1, fetch:false) #Instantiates only
account = Mpayer::Account.find(1, fetch:false)
account.update(name:'Lolo Kiki')

options = {from_date: Time.now - (86400*365),to_date:nil, dr_cr:nil, ac_type:nil, category:nil}
options = {from_date: Time.zone.now - (86400*365),to_date:nil, dr_cr:nil, ac_type:nil, category:nil}
accounts = Mpayer::Account.aggregates(options)

members = Mpayer::Account.find(25735, fetch:false).members
Expand Down Expand Up @@ -163,7 +163,7 @@ options = {
client_id: client_id,
status: status,
payable_type: payable_type,
due_date: Time.now+(86400*31),
due_date: Time.zone.now+(86400*31),
pay: payable_items,
tags: tags,
flags: flags,
Expand All @@ -182,7 +182,7 @@ payable.destroy# Delete a payable
```ruby
# Note: cr_party is the recieving (credited) account while dr_party is paying (debited) account

transactions = Mpayer::Transaction.all(from: Time.now - (86400*400))
transactions = Mpayer::Transaction.all(from: Time.zone.now - (86400*400))

transaction = Mpayer::Transaction.where(ref_id:"KT00410000402")# Only ref_id supported currently

Expand Down
1 change: 1 addition & 0 deletions lib/mpayer_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require "active_support/time"
require "wsse"
require "httparty"
require "hashie"
Expand Down
18 changes: 16 additions & 2 deletions lib/mpayer_ruby/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
module Mpayer
class Configuration
attr_accessor :user_no, :token, :base_url
attr_accessor :user_no, :token, :base_url, :time_zone

def initialize(user_no:nil,token:nil,base_url:'https://app.mpayer.co.ke/api/')
def initialize(user_no:nil,token:nil,time_zone:nil,base_url:'https://app.mpayer.co.ke/api/')
@base_url ||= base_url
@user_no ||= user_no
@token ||= token
@time_zone ||= time_zone
set_time_zone
end

def time_zone=(value)
set_time_zone(value)
@time_zone = value
end

def auth
Expand All @@ -16,5 +23,12 @@ def header
{'Content-Type'=> 'application/json', 'Accept' => 'application/json', 'X-WSSE' => auth.to_s}
end

private

def set_time_zone(tz = nil)
time_zone = tz || @time_zone || Time.zone || 'UTC'
Time.zone = time_zone unless time_zone.nil?
end

end
end
2 changes: 1 addition & 1 deletion lib/mpayer_ruby/endpoints/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def find(client_id,fetch: true)
client = new(id:client_id,response:response)
end

# client_attributes = {client: { client_name: "Kiki Lolo", client_birthday: Time.now.iso8601, client_type: "ext", ac_type: "cu",client_mobile: '073373932', client_email: 'lolo@kiki.com',currency: "kes", mandate:"s", sub_type: "od" }}
# client_attributes = {client: { client_name: "Kiki Lolo", client_birthday: Time.zone.now.iso8601, client_type: "ext", ac_type: "cu",client_mobile: '073373932', client_email: 'lolo@kiki.com',currency: "kes", mandate:"s", sub_type: "od" }}
# Mpayer::Client.create(client_attributes)
def create(options={})
url = "/clients"
Expand Down
2 changes: 1 addition & 1 deletion lib/mpayer_ruby/endpoints/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Transaction < Mpayer::Endpoint

class << self

# Mpayer::Transaction.all(from: Time.now - (86400*400))
# Mpayer::Transaction.all(from: Time.zone.now - (86400*400))
def all(page:1,per_page:100,from: nil,to: nil)
url = "/transactions/all"
from = from.strftime("%F %T") unless from.nil?
Expand Down
6 changes: 3 additions & 3 deletions lib/mpayer_ruby/support/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create_mpayer_client
client_attributes = {
client: {
client_name: Faker::Name.name,
client_birthday: Time.now.iso8601,
client_birthday: Time.zone.now.iso8601,
client_type: "ext",
ac_type: "cu",
client_mobile: Faker::Number.number(10) ,
Expand Down Expand Up @@ -71,7 +71,7 @@ def create_mpayer_payable
# client_id: client_id,
# status: @model.status,
# payable_type: @model.payable_type,
due_date: Time.now+(86400*31),
due_date: Time.zone.now+(86400*31),
pay: payable_items
# tags:@tags,
# flags:@flags,
Expand Down Expand Up @@ -102,7 +102,7 @@ def create_mpayer_transaction
end

def get_mpayer_transactions
@@get_mpayer_transactions ||= Mpayer::Transaction.all(from: Time.now - (86400*400))
@@get_mpayer_transactions ||= Mpayer::Transaction.all(from: Time.zone.now - (86400*400))
@@get_mpayer_transactions.any? ? @@get_mpayer_transactions : [create_mpayer_transaction]
end
end
2 changes: 1 addition & 1 deletion lib/mpayer_ruby/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Mpayer
VERSION = "0.0.14"
VERSION = "0.0.15"
end
1 change: 1 addition & 0 deletions mpayer_ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "sinatra", '~> 1.4'
spec.add_development_dependency "faker", '~> 1.4'

spec.add_dependency 'activesupport', "~> 4.2"
spec.add_dependency 'httparty', "~> 0.13"
spec.add_dependency 'wsse', "~> 0.0"
spec.add_dependency 'hashie', "~> 3.4"
Expand Down
2 changes: 1 addition & 1 deletion test/mpayer_ruby/endpoints/account_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_update_account
def test_account_aggregates
# skip
options = {
from_date: Time.now - (86400*365),
from_date: Time.zone.now - (86400*365),
to_date:nil,
dr_cr:nil,
ac_type:nil,
Expand Down
2 changes: 1 addition & 1 deletion test/mpayer_ruby/endpoints/payable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_search_payable
refute_nil(payable, "Failure message.")
assert(payable.is_a?(Mpayer::Payable), "Failure message.")
payable = Mpayer::Payable.where(ref_id:"Ksdfsfsdf000411")
assert_nil(payable, "Failure message.")
assert_equal({"data"=>"not found"}, JSON.parse(payable))
end

def test_create_mpayer_payable
Expand Down
2 changes: 1 addition & 1 deletion test/mpayer_ruby/endpoints/transaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setup
end

# def get_mpayer_transactions
# @transactions ||= Mpayer::Transaction.all(from: Time.now - (86400*400))
# @transactions ||= Mpayer::Transaction.all(from: Time.zone.now - (86400*400))
# @transactions.any? ? @transactions : [create_mpayer_transaction]
# end

Expand Down

0 comments on commit d18af93

Please sign in to comment.