wizypay-api-client 0.1.0 → 0.1.1

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: 25e3c4eb158ef8bd15bcbdf79419abc1506c6294
4
- data.tar.gz: ec3ced582b40b8778d49c70c5f5a3dde956fb375
3
+ metadata.gz: 5943bf48ae0d0ed8f7571a95a76e1527201fa97d
4
+ data.tar.gz: 8dad34334638adda70c41fd0bedd6ccd2f8405ac
5
5
  SHA512:
6
- metadata.gz: b69685a587d3c6f1a9a9df75a99f19df876fb5e4c8511f39547d5a22d3d7f49ec2bc98fb4ecfc14cb4e075d6e9142392a7d452cc01e564103321e9c60135c3bb
7
- data.tar.gz: 96ad24fc1c985821ce4c1935c9e4cf1d09571c065e74531120bce597298743d964253e9fab2c85f5fbe86470cfa06bc51f4f5c798001c9e17cfc73c25776c7d3
6
+ metadata.gz: 556fa5335e9ad5dae8f7d044f150aa15da9093dd90403e93b1806e0a82b8fee361d8aead95e2105219affada80c17b93d58de7856376ade1b1f9c771e3ff385a
7
+ data.tar.gz: 1d346535ccf3d7097e9ae1d29eee59660be0b0dfe0799bba183a7921c4a691ba45b5144e7e126eb00f333679151bbc017b898823c34af30146ef921f2f7a25b0
@@ -1,3 +1,5 @@
1
+ require 'deep_merge'
2
+
1
3
  module Wizypay
2
4
  class Client
3
5
  class << self
@@ -7,12 +9,12 @@ module Wizypay
7
9
  execute(path, { method: :post, payload: payload })
8
10
  end
9
11
 
10
- def get(path)
11
- execute(path, { method: :get })
12
+ def get(path, params = {})
13
+ execute(path, { method: :get, headers: { params: params } })
12
14
  end
13
15
 
14
16
  def execute(path, req_params)
15
- req_params.merge!(
17
+ req_params.deep_merge!(
16
18
  url: "#{api_endpoint}#{path}",
17
19
  headers: { accept: :json }
18
20
  )
@@ -0,0 +1,11 @@
1
+ module Wizypay
2
+ class Merchant
3
+ def self.where(q)
4
+ Client.get('/merchants', q)[:data]
5
+ end
6
+
7
+ def self.all(q = {})
8
+ where(q)
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Wizypay
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/wizypay.rb CHANGED
@@ -7,11 +7,13 @@ require 'simple-hmac'
7
7
  require 'json'
8
8
  require_relative 'wizypay/client'
9
9
  require_relative 'wizypay/card'
10
+ require_relative 'wizypay/merchant'
10
11
 
11
12
  module Wizypay
12
13
  def self.setup(api_key, api_secret, api_endpoint = 'https://api.wizypay.com')
13
14
  Wizypay::Client.api_endpoint = api_endpoint
14
15
  Wizypay::Client.api_key = api_key
15
16
  Wizypay::Client.api_secret = api_secret
17
+ nil
16
18
  end
17
19
  end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'AffiliationApi::merchants' do
4
+
5
+ let(:api_key) { 'key' }
6
+ let(:api_secret) { 'secret' }
7
+ let(:api_endpoint) { 'https://api.wizypay.com' }
8
+ let(:all_merchants_request) { stub_request(:get, "#{api_endpoint}/merchants").
9
+ with(headers: { 'Accept' => 'application/json',
10
+ 'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
11
+ let(:where_merchants_request) { stub_request(:get, "#{api_endpoint}/merchants?q=hp").
12
+ with(headers: { 'Accept' => 'application/json',
13
+ 'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
14
+ before do
15
+ Wizypay.setup(api_key, api_secret, api_endpoint)
16
+ end
17
+
18
+ context 'all' do
19
+ it 'returns empty body' do
20
+ request = all_merchants_request.to_return(status: 200, body: '{"data": []}')
21
+ response = Wizypay::Merchant.all
22
+ expect(request).to have_been_made
23
+ expect(response).to be_empty
24
+ end
25
+ end
26
+
27
+ context 'where' do
28
+ it 'returns empty body' do
29
+ request = where_merchants_request.to_return(status: 200, body: '{"data": []}')
30
+ response = Wizypay::Merchant.where(q: 'hp')
31
+ expect(request).to have_been_made
32
+ expect(response).to be_empty
33
+ end
34
+ end
35
+
36
+ context 'failure' do
37
+ context '4XX' do
38
+ it "throws #{RestClient::Exception}" do
39
+ request = all_merchants_request.to_return(status: 401, body: { errors: { base: ['authentication_failed'] } }.to_json)
40
+ expect do
41
+ Wizypay::Merchant.all
42
+ end.to raise_error(RestClient::Exception)
43
+ expect(request).to have_been_made
44
+ end
45
+ end
46
+
47
+ context 'timeout' do
48
+ it "throws #{RestClient::Exception}" do
49
+ request = all_merchants_request.to_timeout
50
+ expect do
51
+ Wizypay::Merchant.all
52
+ end.to raise_error(RestClient::Exception)
53
+ expect(request).to have_been_made
54
+ end
55
+ end
56
+ end
57
+ end
data/spec/spec_helper.rb CHANGED
@@ -74,7 +74,7 @@ RSpec.configure do |config|
74
74
  # Print the 10 slowest examples and example groups at the
75
75
  # end of the spec run, to help surface which specs are running
76
76
  # particularly slow.
77
- config.profile_examples = 10
77
+ # config.profile_examples = 10
78
78
 
79
79
  # Run specs in random order to surface order dependencies. If you find an
80
80
  # order dependency and want to debug it, you can fix the order by providing
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.1.0
4
+ version: 0.1.1
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-01-21 00:00:00.000000000 Z
13
+ date: 2016-01-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: simple-hmac
@@ -40,6 +40,20 @@ dependencies:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '1.8'
43
+ - !ruby/object:Gem::Dependency
44
+ name: deep_merge
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '1.0'
43
57
  - !ruby/object:Gem::Dependency
44
58
  name: bundler
45
59
  requirement: !ruby/object:Gem::Requirement
@@ -124,10 +138,12 @@ files:
124
138
  - lib/wizypay.rb
125
139
  - lib/wizypay/card.rb
126
140
  - lib/wizypay/client.rb
141
+ - lib/wizypay/merchant.rb
127
142
  - lib/wizypay/version.rb
128
143
  - spec/card/cancel_card_spec.rb
129
144
  - spec/card/card_url_spec.rb
130
145
  - spec/card/create_card_spec.rb
146
+ - spec/merchant/merchant_spec.rb
131
147
  - spec/spec_helper.rb
132
148
  homepage: http://developers.wizypay.com
133
149
  licenses:
@@ -158,4 +174,5 @@ test_files:
158
174
  - spec/card/cancel_card_spec.rb
159
175
  - spec/card/card_url_spec.rb
160
176
  - spec/card/create_card_spec.rb
177
+ - spec/merchant/merchant_spec.rb
161
178
  - spec/spec_helper.rb