besepa 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/besepa/api_calls/list.rb +7 -17
- data/lib/besepa/api_calls/search.rb +4 -11
- data/lib/besepa/collection.rb +36 -0
- data/lib/besepa/utils/request.rb +3 -6
- data/lib/besepa/utils/version.rb +1 -1
- data/spec/besepa/customer_spec.rb +16 -8
- data/spec/besepa/group_spec.rb +5 -1
- data/spec/fixtures/customers.json +8 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 320cf673fdede800b3b27d112273da9d5bfa8702
|
4
|
+
data.tar.gz: 0872852f873885be68c8c60d3fb59faa39443f9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0290b23a8336c5b63cfbf362eef511b2b1a6ac5c2ce4c488dfb7f480d09f1858fec5ceed547fe5a751679fe0947ac0f1d006fbf42bc9b0a40d8615c4cbae4345
|
7
|
+
data.tar.gz: 62ed15a4ce4b7852cf876d4df24ccfa06fb3fab248f522c2f8d246a6826663505e1c38892af132a6c5e75a9fd5f8017530c4465a11acad605518135e87476bb8
|
@@ -1,36 +1,26 @@
|
|
1
1
|
module Besepa
|
2
|
-
|
3
2
|
module ApiCalls
|
4
|
-
|
5
3
|
module List
|
6
|
-
|
7
4
|
module ClassMethods
|
8
|
-
|
9
5
|
def all(filters={})
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
objects
|
6
|
+
path = "/#{api_path(filters)}"
|
7
|
+
params = filters.select{|x| [:page, :field, :value].include?(x)}
|
8
|
+
response = get(path, params)
|
9
|
+
|
10
|
+
Besepa::Collection.new(response, self)
|
18
11
|
end
|
19
|
-
|
12
|
+
|
20
13
|
def find(id, filters={})
|
21
14
|
response = get "/#{api_path(filters)}/#{id}"
|
22
15
|
c = self.new(response['response'])
|
23
16
|
c
|
24
17
|
end
|
25
|
-
|
26
18
|
end
|
27
19
|
|
28
20
|
def self.included(base)
|
29
21
|
base.extend(ClassMethods)
|
30
22
|
end
|
31
|
-
|
23
|
+
|
32
24
|
end
|
33
|
-
|
34
25
|
end
|
35
|
-
|
36
26
|
end
|
@@ -2,24 +2,17 @@ module Besepa
|
|
2
2
|
module ApiCalls
|
3
3
|
module Search
|
4
4
|
module ClassMethods
|
5
|
-
|
6
5
|
def search(filters = {})
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
objects << self.new(c)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
objects
|
6
|
+
path = "/#{api_path}/search"
|
7
|
+
params = filters.select{|x| [:page, :field, :value].include?(x)}
|
8
|
+
response = get(path, params)
|
9
|
+
Besepa::Collection.new(response, self)
|
15
10
|
end
|
16
|
-
|
17
11
|
end
|
18
12
|
|
19
13
|
def self.included(base)
|
20
14
|
base.extend(ClassMethods)
|
21
15
|
end
|
22
|
-
|
23
16
|
end
|
24
17
|
end
|
25
18
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Besepa
|
2
|
+
class Collection
|
3
|
+
include Enumerable
|
4
|
+
attr_accessor :items, :pages, :per_page, :total, :current_page
|
5
|
+
attr_reader :pagination
|
6
|
+
|
7
|
+
def initialize(response, klass)
|
8
|
+
@pagination = false
|
9
|
+
@items = []
|
10
|
+
process_response(response, klass)
|
11
|
+
end
|
12
|
+
|
13
|
+
def each &block
|
14
|
+
@items.each{|item| block.call(item)}
|
15
|
+
end
|
16
|
+
|
17
|
+
alias_method :size, :count
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def process_response(response, klass)
|
22
|
+
if response['pagination']
|
23
|
+
@pagination = true
|
24
|
+
self.per_page = response['pagination']['per_page']
|
25
|
+
self.current_page = response['pagination']['current']
|
26
|
+
self.total = response['pagination']['count']
|
27
|
+
self.pages = response['pagination']['pages']
|
28
|
+
end
|
29
|
+
|
30
|
+
response['response'].each do |c|
|
31
|
+
@items << klass.new(c)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/besepa/utils/request.rb
CHANGED
data/lib/besepa/utils/version.rb
CHANGED
@@ -4,14 +4,18 @@ describe Besepa::Customer do
|
|
4
4
|
|
5
5
|
describe '#all' do
|
6
6
|
before do
|
7
|
-
stub_get('/customers').to_return(body: fixture('customers.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
7
|
+
stub_get('/customers?page=1').to_return(body: fixture('customers.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'returns a list of customers' do
|
11
|
-
customers = Besepa::Customer.all
|
12
|
-
expect(customers).to
|
11
|
+
customers = Besepa::Customer.all(page: 1)
|
12
|
+
expect(customers).to respond_to(:each)
|
13
13
|
expect(customers.first).to be_an Besepa::Customer
|
14
14
|
expect(customers.size).to eq(1)
|
15
|
+
expect(customers.per_page).to eq(50)
|
16
|
+
expect(customers.current_page).to eq(1)
|
17
|
+
expect(customers.total).to eq(1)
|
18
|
+
expect(customers.pages).to eq(1)
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
@@ -29,14 +33,18 @@ describe Besepa::Customer do
|
|
29
33
|
|
30
34
|
describe '#search' do
|
31
35
|
before do
|
32
|
-
stub_get('/customers/search?field=group_id&value=foo').to_return(body: fixture('customers.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
36
|
+
stub_get('/customers/search?field=group_id&value=foo&page=1').to_return(body: fixture('customers.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
33
37
|
end
|
34
38
|
|
35
39
|
it 'returs a list of customers' do
|
36
|
-
customers = Besepa::Customer.search(field: 'group_id', value: 'foo')
|
37
|
-
expect(customers).to
|
40
|
+
customers = Besepa::Customer.search(field: 'group_id', value: 'foo', page: 1)
|
41
|
+
expect(customers).to respond_to(:each)
|
38
42
|
expect(customers.first).to be_an Besepa::Customer
|
39
43
|
expect(customers.size).to eq(1)
|
44
|
+
expect(customers.per_page).to eq(50)
|
45
|
+
expect(customers.current_page).to eq(1)
|
46
|
+
expect(customers.total).to eq(1)
|
47
|
+
expect(customers.pages).to eq(1)
|
40
48
|
end
|
41
49
|
end
|
42
50
|
|
@@ -77,7 +85,7 @@ describe Besepa::Customer do
|
|
77
85
|
|
78
86
|
it 'returns a list of debits' do
|
79
87
|
debits = Besepa::Customer.new(id: 'cus12345').debits
|
80
|
-
expect(debits).to
|
88
|
+
expect(debits).to respond_to(:each)
|
81
89
|
expect(debits.first).to be_an Besepa::Debit
|
82
90
|
expect(debits.size).to eq(1)
|
83
91
|
end
|
@@ -104,7 +112,7 @@ describe Besepa::Customer do
|
|
104
112
|
|
105
113
|
it 'returns a list of bank accounts' do
|
106
114
|
bank_accounts = Besepa::Customer.new(id: 'cus12345').bank_accounts
|
107
|
-
expect(bank_accounts).to
|
115
|
+
expect(bank_accounts).to respond_to(:each)
|
108
116
|
expect(bank_accounts.first).to be_an Besepa::BankAccount
|
109
117
|
expect(bank_accounts.size).to eq(1)
|
110
118
|
end
|
data/spec/besepa/group_spec.rb
CHANGED
@@ -10,9 +10,13 @@ describe Besepa::Group do
|
|
10
10
|
|
11
11
|
it 'returns a list of customers' do
|
12
12
|
customers = @group.customers
|
13
|
-
expect(customers).to
|
13
|
+
expect(customers).to respond_to(:each)
|
14
14
|
expect(customers.first).to be_an Besepa::Customer
|
15
15
|
expect(customers.size).to eq(1)
|
16
|
+
expect(customers.per_page).to eq(50)
|
17
|
+
expect(customers.current_page).to eq(1)
|
18
|
+
expect(customers.total).to eq(1)
|
19
|
+
expect(customers.pages).to eq(1)
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: besepa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- besepa.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -103,7 +103,6 @@ extra_rdoc_files: []
|
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
105
|
- Gemfile
|
106
|
-
- Gemfile.lock
|
107
106
|
- LICENSE.txt
|
108
107
|
- README.md
|
109
108
|
- Rakefile
|
@@ -117,6 +116,7 @@ files:
|
|
117
116
|
- lib/besepa/api_calls/update.rb
|
118
117
|
- lib/besepa/bank_account.rb
|
119
118
|
- lib/besepa/business_account.rb
|
119
|
+
- lib/besepa/collection.rb
|
120
120
|
- lib/besepa/customer.rb
|
121
121
|
- lib/besepa/debit.rb
|
122
122
|
- lib/besepa/errors/besepa_error.rb
|