wizypay-api-client 0.2.0 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 426e05d103a20afb933b420f11f2b2ca440d7c09
4
- data.tar.gz: 76eaa542040e90e45323248168db754f41bb6260
3
+ metadata.gz: fea8329539f0457da4dc96c3fe29b9ba76cdde79
4
+ data.tar.gz: 7ff679baa52f95b4ffdc3f3686b7b73736f7361b
5
5
  SHA512:
6
- metadata.gz: c7d032b91a535f34c00d57ac2d65013f677ae75eadff83316259f83b24320cd8a27d20a94436916a0cb15ab7821cf67bae1e0b7be15f9cda8dbf9b7c9b2f1495
7
- data.tar.gz: 04967cd33c55cb9ddaba58d5b0b62b47f320c27efe8673800dacd1040d0a5f84dcc64e6d38f7feb206f4dbcaa1d8c846195fc513f94fda333b1cf6308fd82335
6
+ metadata.gz: ec8fa60444298cc762f5b34ea9b0ca9e3c5b645332526a946c0f3f6b23f61cf41e2ddb10232804886bd2993e0e7894206735f1532c56a9029fa3781b02bec1b1
7
+ data.tar.gz: 12f3c0745c3484c2710a24fb39ed629bc3caf0fde5d273c1b1800425cc8f30fe0b7140d2cee345cb60195717ef2fe0054f64a2c8e39589f14f8266ae36d10a25
data/lib/wizypay.rb CHANGED
@@ -9,8 +9,10 @@ require_relative 'wizypay/client'
9
9
  require_relative 'wizypay/resource'
10
10
  require_relative 'wizypay/collection'
11
11
  require_relative 'wizypay/card'
12
+ require_relative 'wizypay/ad'
12
13
  require_relative 'wizypay/merchant_category'
13
14
  require_relative 'wizypay/merchant'
15
+ require_relative 'wizypay/merchant_version'
14
16
 
15
17
  module Wizypay
16
18
  def self.setup(api_key, api_secret, api_endpoint = 'https://api.wizypay.com')
data/lib/wizypay/ad.rb ADDED
@@ -0,0 +1,4 @@
1
+ module Wizypay
2
+ class Ad < Resource
3
+ end
4
+ end
@@ -3,7 +3,7 @@ class Wizypay::Collection
3
3
 
4
4
  def initialize(klass, data, meta = {})
5
5
  @data = data.map {|h| klass.new(h)}
6
- @meta = meta
6
+ @meta = meta || {}
7
7
  end
8
8
 
9
9
  def respond_to?(m)
@@ -9,12 +9,29 @@ module Wizypay
9
9
  where(q)
10
10
  end
11
11
 
12
+ def versions
13
+ MerchantVersion.for(self)
14
+ end
15
+
12
16
  def primary_ad
13
17
  Resource.new(super['data'])
14
18
  end
15
19
 
20
+ def primary_ad_id
21
+ super || primary_ad.id || ads.first.try(:id)
22
+ end
23
+
24
+ def ads
25
+ Collection.new(Ad, super['data'], super['meta'])
26
+ end
27
+
16
28
  def categories
17
29
  Collection.new(MerchantCategory, super['data'], super['meta'])
18
30
  end
31
+
32
+ def network_updated_at
33
+ return nil unless super.present?
34
+ Time.parse(super)
35
+ end
19
36
  end
20
37
  end
@@ -1,4 +1,8 @@
1
1
  module Wizypay
2
2
  class MerchantCategory < Resource
3
+ def self.all
4
+ raw = Client.get('/merchant_categories')
5
+ Collection.new(self, raw[:data], raw[:meta])
6
+ end
3
7
  end
4
8
  end
@@ -0,0 +1,21 @@
1
+ module Wizypay
2
+ class MerchantVersion < Resource
3
+ def self.for(merchant)
4
+ for_id(merchant.id)
5
+ end
6
+
7
+ def self.for_id(merchant_id)
8
+ raw = Client.get("/merchants/#{merchant_id}/versions")
9
+ Collection.new(self, raw[:data], raw[:meta])
10
+ end
11
+
12
+ def merchant
13
+ Merchant.new(super['data'])
14
+ end
15
+
16
+ def created_at
17
+ return nil unless super.present?
18
+ Time.parse(super)
19
+ end
20
+ end
21
+ end
@@ -1,4 +1,8 @@
1
+ require 'active_model'
2
+
1
3
  class Wizypay::Resource < OpenStruct
4
+ extend ActiveModel::Naming
5
+
2
6
  def reinitialize(h)
3
7
  each_pair do |k, _|
4
8
  delete_field k
@@ -1,3 +1,3 @@
1
1
  module Wizypay
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module Wizypay
4
+ RSpec.describe Merchant do
5
+ let(:api_key) { 'key' }
6
+ let(:api_secret) { 'secret' }
7
+ let(:api_endpoint) { 'https://api.wizypay.com' }
8
+ let(:request) { stub_request(:get, "#{api_endpoint}/merchant_categories").
9
+ with(headers: { 'Accept' => 'application/json',
10
+ 'Authorization' => /WIZYPAY #{api_key}:.*/ }) }
11
+ before do
12
+ Wizypay.setup(api_key, api_secret, api_endpoint)
13
+ end
14
+
15
+ describe '.all' do
16
+ it 'returns' do
17
+ request.to_return(status: 200, body: '{"data": [{"id": 1}]}')
18
+ response = MerchantCategory.all
19
+ expect(request).to have_been_made
20
+ expect(response.length).to eq 1
21
+ expect(response.first).to be_a(MerchantCategory)
22
+ expect(response.first.id).to eq 1
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ module Wizypay
4
+ RSpec.describe Merchant do
5
+ let(:api_key) { 'key' }
6
+ let(:api_secret) { 'secret' }
7
+ let(:api_endpoint) { 'https://api.wizypay.com' }
8
+ let(:merchant_id) { 91 }
9
+ let!(:request) { stub_request(:get, "#{api_endpoint}/merchants/#{merchant_id}/versions").
10
+ with(headers: { 'Accept' => 'application/json',
11
+ 'Authorization' => /WIZYPAY #{api_key}:.*/ }).
12
+ to_return(status: 200, body: '{"data": [{"merchant": {"data": {"name": "old name"}}}]}') }
13
+ before do
14
+ Wizypay.setup(api_key, api_secret, api_endpoint)
15
+ end
16
+
17
+ describe '.for' do
18
+ it 'returns' do
19
+ response = MerchantVersion.for(Merchant.new(id: merchant_id))
20
+ expect(request).to have_been_made
21
+ expect(response.length).to eq 1
22
+ expect(response.first).to be_a(MerchantVersion)
23
+ expect(response.first.merchant).to be_a(Merchant)
24
+ expect(response.first.merchant.name).to eq 'old name'
25
+ end
26
+ end
27
+
28
+ describe '.for_id' do
29
+ it 'returns' do
30
+ response = MerchantVersion.for_id(merchant_id)
31
+ expect(request).to have_been_made
32
+ expect(response.length).to eq 1
33
+ expect(response.first).to be_a(MerchantVersion)
34
+ expect(response.first.merchant).to be_a(Merchant)
35
+ expect(response.first.merchant.name).to eq 'old name'
36
+ end
37
+ end
38
+
39
+ describe 'Merchant#versions' do
40
+ it 'returns' do
41
+ response = Merchant.new(id: merchant_id).versions
42
+ expect(request).to have_been_made
43
+ expect(response.length).to eq 1
44
+ expect(response.first).to be_a(MerchantVersion)
45
+ expect(response.first.merchant).to be_a(Merchant)
46
+ expect(response.first.merchant.name).to eq 'old name'
47
+ end
48
+ end
49
+ end
50
+ 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.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chaker Nakhli
@@ -54,6 +54,20 @@ dependencies:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
56
  version: '1.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: activemodel
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '4.2'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '4.2'
57
71
  - !ruby/object:Gem::Dependency
58
72
  name: bundler
59
73
  requirement: !ruby/object:Gem::Requirement
@@ -136,17 +150,21 @@ files:
136
150
  - LICENSE.txt
137
151
  - Rakefile
138
152
  - lib/wizypay.rb
153
+ - lib/wizypay/ad.rb
139
154
  - lib/wizypay/card.rb
140
155
  - lib/wizypay/client.rb
141
156
  - lib/wizypay/collection.rb
142
157
  - lib/wizypay/merchant.rb
143
158
  - lib/wizypay/merchant_category.rb
159
+ - lib/wizypay/merchant_version.rb
144
160
  - lib/wizypay/resource.rb
145
161
  - lib/wizypay/version.rb
146
162
  - spec/card/cancel_card_spec.rb
147
163
  - spec/card/card_url_spec.rb
148
164
  - spec/card/create_card_spec.rb
149
165
  - spec/merchant/merchant_spec.rb
166
+ - spec/merchant_category/merchant_category_spec.rb
167
+ - spec/merchant_version/merchant_version_spec.rb
150
168
  - spec/spec_helper.rb
151
169
  homepage: http://developers.wizypay.com
152
170
  licenses:
@@ -178,4 +196,6 @@ test_files:
178
196
  - spec/card/card_url_spec.rb
179
197
  - spec/card/create_card_spec.rb
180
198
  - spec/merchant/merchant_spec.rb
199
+ - spec/merchant_category/merchant_category_spec.rb
200
+ - spec/merchant_version/merchant_version_spec.rb
181
201
  - spec/spec_helper.rb