wizypay-api-client 0.2.4 → 0.2.5

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: d05e8bd0ce798db5329ff037d26d6098503693dc
4
- data.tar.gz: 9bca7271f7dbb98a69d57107bfd33887f469188d
3
+ metadata.gz: 818ea735db4fbdb6ea88cde60677703f9ce018fd
4
+ data.tar.gz: 3a8a28123ca944353f29e995f35b7d60e22900ef
5
5
  SHA512:
6
- metadata.gz: 1f1b39a524e6fe4e96a30d081190934c8e3e85d4a6433c96a862d1032f2256eeb03a02823ef2fa2691686c7f9e359caad2e5a570a3d22da6809b55cbe414c35a
7
- data.tar.gz: 5118035e2bb3e4c88d2d08f8295a7f2f350ddfc0f60433a61832b706d44e17deeb2bb0118f9d339e9e6c5dbe1b7300cfcaa692d3965b878750c14ffc3eaec56e
6
+ metadata.gz: 728d5f5887e427adf3d47f9e997a8181cbbd98ffe2f07074ce3b1b0aaf5802dd51852f24aae6305a6381e07730adb5d282a46289090086364439840c0d615285
7
+ data.tar.gz: 196afcd8ca81c7e026625acbdb96fb52c9f8644ad1e91941de219391f5a24ff2c984cff5d248dab107f45dcf41f7c6be08129bd3d6a3ca76c4c0e03716330b17
data/lib/wizypay.rb CHANGED
@@ -12,6 +12,7 @@ require_relative 'wizypay/ad'
12
12
  require_relative 'wizypay/merchant_category'
13
13
  require_relative 'wizypay/merchant'
14
14
  require_relative 'wizypay/merchant_version'
15
+ require_relative 'wizypay/beneficiary'
15
16
 
16
17
  module Wizypay
17
18
  def self.setup(api_key, api_secret, api_endpoint = 'https://api.wizypay.com')
@@ -0,0 +1,24 @@
1
+ module Wizypay
2
+ class Beneficiary < Resource
3
+ def self.where(q)
4
+ raw = Client.get('/beneficiaries', q)
5
+ Collection.new(self, raw[:data], raw[:meta])
6
+ end
7
+
8
+ def self.all(q = {})
9
+ where(q)
10
+ end
11
+
12
+ def self.find(id)
13
+ new(Client.get("/beneficiaries/#{id}")[:data])
14
+ end
15
+
16
+ def cards
17
+ Collection.new(Card, super['data'], super['meta'])
18
+ end
19
+
20
+ def save
21
+ reinitialize Client.put("/beneficiaries/#{id}", to_h)[:data]
22
+ end
23
+ end
24
+ end
@@ -2,8 +2,8 @@ module Wizypay
2
2
  class Refund < Resource
3
3
  %w(created_at executed_at pending_until).each do |time_attr|
4
4
  define_method time_attr do
5
- return nil unless super.present?
6
- Time.parse(super)
5
+ return nil unless super().present?
6
+ Time.parse(super())
7
7
  end
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module Wizypay
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ module Wizypay
4
+ RSpec.describe Beneficiary do
5
+ let(:api_key) { 'key' }
6
+ let(:api_secret) { 'secret' }
7
+ let(:api_endpoint) { 'https://api.wizypay.com' }
8
+ let(:id) { 3 }
9
+ let(:kyc_compliant) { false }
10
+ let(:all_beneficiaries_request) { stub_request(:get, "#{api_endpoint}/beneficiaries").
11
+ with(headers: { 'Accept' => 'application/json',
12
+ 'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
13
+ let(:where_beneficiaries_request) { stub_request(:get, "#{api_endpoint}/beneficiaries?first_name=john").
14
+ with(headers: { 'Accept' => 'application/json',
15
+ 'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
16
+ let(:beneficiary_request) { stub_request(:get, "#{api_endpoint}/beneficiaries/#{id}").
17
+ with(headers: { 'Accept' => 'application/json',
18
+ 'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
19
+ let(:update_request) { stub_request(:put, "#{api_endpoint}/beneficiaries/#{id}").
20
+ with(body: { 'id' => id.to_s, 'kyc_compliant' => kyc_compliant.to_s },
21
+ headers: { 'Accept' => 'application/json',
22
+ 'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
23
+ before do
24
+ Wizypay.setup(api_key, api_secret, api_endpoint)
25
+ end
26
+
27
+ context 'all' do
28
+ it 'is a collection' do
29
+ all_beneficiaries_request.to_return(status: 200, body: '{"data":[{"id":3,"client_name":"Dummy","email":"joel@wizypay.com","last_name":"Cogen","first_name":"Joel","recent_amount":1337}],"meta":{"total_pages":1,"current_page":1,"limit_value":25}}')
30
+ response = Beneficiary.all
31
+ expect(response).to be_a(Collection)
32
+ expect(response.first).to be_a(Beneficiary)
33
+ expect(response.first.first_name).to eq 'Joel'
34
+ end
35
+ end
36
+
37
+ context 'where' do
38
+ it 'returns empty body' do
39
+ request = where_beneficiaries_request.to_return(status: 200, body: '{"data": []}')
40
+ response = Beneficiary.where(first_name: 'john')
41
+ expect(request).to have_been_made
42
+ expect(response).to be_empty
43
+ end
44
+ end
45
+
46
+ context 'find' do
47
+ it 'returns' do
48
+ request = beneficiary_request.to_return(status: 200, body: '{"data":{"id":3,"client_name":"Dummy","email":"joel@wizypay.com","name":"Joel Cogen","recent_amount":1337,"phone":null,"kyc_compliant?":true,"cards":{"data":[{"created_at":"2016-02-01T15:03:43.015+01:00","amount":1337,"status":"cancelled","merchant_ref":91,"partial_number":"XXXX-8674","real_merchant_ref":null,"user":{"id":1,"email":"joel@wizypay.com","last_name":"Cogen","first_name":"Joel"}}]}}}')
49
+ response = Beneficiary.find(id)
50
+ expect(request).to have_been_made
51
+ expect(response).to be_a(Beneficiary)
52
+ expect(response.name).to eq 'Joel Cogen'
53
+ expect(response.cards).to be_a(Collection)
54
+ expect(response.cards.first).to be_a(Card)
55
+ end
56
+ end
57
+
58
+ context 'save' do
59
+ it 'puts' do
60
+ request = update_request.to_return(status: 200, body: '{"data":{"id":3,"client_name":"Dummy","email":"joel@wizypay.com","name":"Joel Cogen","recent_amount":1337,"phone":null,"kyc_compliant?":false,"cards":{"data":[{"created_at":"2016-02-01T15:03:43.015+01:00","amount":1337,"status":"cancelled","merchant_ref":91,"partial_number":"XXXX-8674","real_merchant_ref":null,"user":{"id":1,"email":"joel@wizypay.com","last_name":"Cogen","first_name":"Joel"}}]}}}')
61
+ beneficiary = Beneficiary.new(id: id, kyc_compliant: kyc_compliant)
62
+ beneficiary.save
63
+ expect(request).to have_been_made
64
+ expect(beneficiary.name).to eq 'Joel Cogen'
65
+ expect(beneficiary.kyc_compliant?).to eq kyc_compliant
66
+ end
67
+ end
68
+ end
69
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wizypay-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chaker Nakhli
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-02-02 00:00:00.000000000 Z
13
+ date: 2016-02-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: simple-hmac
@@ -151,6 +151,7 @@ files:
151
151
  - Rakefile
152
152
  - lib/wizypay.rb
153
153
  - lib/wizypay/ad.rb
154
+ - lib/wizypay/beneficiary.rb
154
155
  - lib/wizypay/card.rb
155
156
  - lib/wizypay/client.rb
156
157
  - lib/wizypay/collection.rb
@@ -161,6 +162,7 @@ files:
161
162
  - lib/wizypay/resource.rb
162
163
  - lib/wizypay/vdc_operation.rb
163
164
  - lib/wizypay/version.rb
165
+ - spec/beneficiary/beneficiary_spec.rb
164
166
  - spec/card/cancel_card_spec.rb
165
167
  - spec/card/card_all_spec.rb
166
168
  - spec/card/card_show_spec.rb
@@ -197,6 +199,7 @@ signing_key:
197
199
  specification_version: 4
198
200
  summary: Programmatic API to access Wizypay's API.
199
201
  test_files:
202
+ - spec/beneficiary/beneficiary_spec.rb
200
203
  - spec/card/cancel_card_spec.rb
201
204
  - spec/card/card_all_spec.rb
202
205
  - spec/card/card_show_spec.rb