besepa 0.8.6 → 0.8.7

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: a69fb821a543b03151aa6b529d545838b8bea1ad
4
- data.tar.gz: 775acc212a6c94171d2cd84731d320a5df8c9484
3
+ metadata.gz: b0dfd1d5b9656509abbc89b489589aec737a23a8
4
+ data.tar.gz: 95352c75920428600705bd74aad2c6ce822932ec
5
5
  SHA512:
6
- metadata.gz: bb03cc4a74b6fcfb4027457c96d0111e7adadcffffe308256dd5dcfdecbe54f811451a143bcdf220683ddebc2c7ad6dad23a33c35a09a40cfae6d1f937cb5f92
7
- data.tar.gz: ff0320336c6c294d9f9be247dbe2db5da1f7ac72308bbe4985942ee50946c81d946bcfb9e47d690a9d70692ee46c9256a74ffcd79cfa44a5c5770cb9827a472f
6
+ metadata.gz: ad025815d2dbc5d503f1b297a23497d52359b2696cc621a3a62439a3bba597af529e24470f0866cb9afe5b2349c76f75eb81b6721fcddcb1a2c636d0aede648e
7
+ data.tar.gz: c39b99a2cac7aa30881e7c5b7276bd02e6ce0b8bf7677f8fd44469f9983c2fc72667c894df4027d4e6ab79e2e779801d64b7e8e623b49b9988156f79667cdccb
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'rspec', '~> 3.1'
27
27
  spec.add_development_dependency 'webmock', '~> 1.20'
28
28
  spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "byebug"
29
30
  end
@@ -1,26 +1,18 @@
1
1
  module Besepa
2
-
3
2
  module ApiCalls
4
-
5
3
  module Create
6
-
7
4
  module ClassMethods
8
-
9
5
  def create(params, filters={})
10
6
  payload = {}
11
7
  payload[klass_name] = params
12
8
  response = post "/#{api_path(filters)}", payload
13
9
  self.new(response['response'])
14
10
  end
15
-
16
11
  end
17
12
 
18
13
  def self.included(base)
19
14
  base.extend(ClassMethods)
20
15
  end
21
-
22
16
  end
23
-
24
17
  end
25
-
26
18
  end
@@ -4,14 +4,14 @@ module Besepa
4
4
  include Besepa::ApiCalls::List
5
5
  include Besepa::ApiCalls::Create
6
6
  include Besepa::ApiCalls::Update
7
-
8
- FIELDS = [:id, :iban, :bic, :bank_name, :status, :default,
9
- :core_enabled, :core_suffix, :b2b_enabled, :b2b_suffix,
10
- :created_at, :authorization, :line_amount, :retention_days,
11
- :debit_cost, :rejection_cost, :core_future_risk,
12
- :core_amount_at_risk, :b2b_future_risk, :b2b_amount_at_risk,
7
+
8
+ FIELDS = [:id, :iban, :bic, :bank_name, :status, :default,
9
+ :core_enabled, :core_suffix, :b2b_enabled, :b2b_suffix, :created_at, :authorization,
10
+ :limit_core, :limit_b2b, :retention_days, :debit_cost, :rejection_cost,
11
+ :core_future_risk, :core_current_risk, :b2b_future_risk, :b2b_current_risk,
13
12
  :financed]
14
13
 
14
+
15
15
  FIELDS.each do |f|
16
16
  attr_accessor f
17
17
  end
@@ -1,28 +1,23 @@
1
1
  module Besepa
2
2
 
3
3
  module Errors
4
-
5
4
  class BesepaError < StandardError
6
-
7
5
  attr_reader :error
8
6
  attr_reader :description
9
7
  attr_reader :http_status
10
8
  attr_reader :messages
11
9
 
12
10
  def initialize(error=nil, description=nil, http_status=nil, messages=nil)
13
- @messages = messages
11
+ @messages = messages
14
12
  @http_status = http_status
15
13
  @description = description
16
- @error = error
14
+ @error = error
17
15
  end
18
16
 
19
17
  def to_s
20
18
  status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
21
19
  "#{status_string}#{@error} (#{@description})"
22
20
  end
23
-
24
21
  end
25
-
26
22
  end
27
-
28
- end
23
+ end
@@ -1,11 +1,6 @@
1
1
  module Besepa
2
-
3
2
  module Errors
4
-
5
3
  class InvalidResourceError < BesepaError
6
-
7
4
  end
8
-
9
5
  end
10
-
11
6
  end
@@ -1,11 +1,6 @@
1
1
  module Besepa
2
-
3
2
  module Errors
4
-
5
3
  class ResourceNotFoundError < BesepaError
6
-
7
4
  end
8
-
9
5
  end
10
-
11
6
  end
@@ -0,0 +1,27 @@
1
+ module Besepa
2
+
3
+ class Report < Besepa::Resource
4
+
5
+ include Besepa::ApiCalls::List
6
+ include Besepa::ApiCalls::Create
7
+ include Besepa::ApiCalls::Search
8
+
9
+ FIELDS = [:id, :until_at, :since_at, :kind, :created_at,
10
+ :document_file_name, :document_file_size, :status]
11
+
12
+ FIELDS.each do |f|
13
+ attr_accessor f
14
+ end
15
+
16
+ def self.klass_name
17
+ "report"
18
+ end
19
+
20
+
21
+ def download_url
22
+ response = get "/#{self.class.api_path}/#{CGI.escape(id)}/download"
23
+ response["response"]["url"]
24
+ end
25
+
26
+ end
27
+ end
@@ -1,6 +1,6 @@
1
1
  module Besepa
2
2
 
3
3
  module Utils
4
- VERSION = '0.8.6'.freeze
4
+ VERSION = '0.8.7'.freeze
5
5
  end
6
6
  end
@@ -0,0 +1,134 @@
1
+ require 'helper'
2
+
3
+ describe Besepa::BankAccount do
4
+
5
+ describe '#all' do
6
+ before do
7
+ stub_get('/bank_accounts?page=1').
8
+ to_return(body: fixture('bank_accounts.json'),
9
+ headers: { content_type: 'application/json; charset=utf-8' })
10
+ end
11
+
12
+ it 'returns a list of bank_accounts' do
13
+ bank_accounts = Besepa::BankAccount.all(page: 1)
14
+ expect(bank_accounts).to respond_to(:each)
15
+ expect(bank_accounts.first).to be_an Besepa::BankAccount
16
+ expect(bank_accounts.size).to eq(1)
17
+ expect(bank_accounts.per_page).to eq(30)
18
+ expect(bank_accounts.current_page).to eq(1)
19
+ expect(bank_accounts.total).to eq(1)
20
+ expect(bank_accounts.pages).to eq(1)
21
+ end
22
+ end
23
+
24
+ describe '#find' do
25
+ before do
26
+ stub_get('/bank_accounts/ban12345').
27
+ to_return(body: fixture('bank_account.json'),
28
+ headers: { content_type: 'application/json; charset=utf-8' })
29
+ end
30
+
31
+ it 'returns a bank account' do
32
+ bank_account = Besepa::BankAccount.find('ban12345')
33
+ expect(bank_account).to be_an Besepa::BankAccount
34
+ expect(bank_account.iban).to eq("ES6012345678050000000001")
35
+ end
36
+ end
37
+
38
+ describe '#create' do
39
+ before do
40
+ stub_post('/bank_accounts').with(
41
+ body: { "bank_account": {
42
+ "bank_name": "Test Bank",
43
+ "bic": "TESTXXX",
44
+ "iban": "ES6012345678050000000001",
45
+ "b2b_enabled": "false",
46
+ "b2b_suffix": "000",
47
+ "core_enabled": "true",
48
+ "core_suffix": "000"
49
+ }}.to_json).to_return(
50
+ body: fixture('bank_account.json'),
51
+ headers: {content_type: 'application/json; charset=utf-8'})
52
+ end
53
+
54
+ it 'returns a bank_account' do
55
+ bank_account = Besepa::BankAccount.create({
56
+ "bank_name": "Test Bank",
57
+ "bic": "TESTXXX",
58
+ "iban": "ES6012345678050000000001",
59
+ "b2b_enabled": "false",
60
+ "b2b_suffix": "000",
61
+ "core_enabled": "true",
62
+ "core_suffix": "000"
63
+ })
64
+ expect(bank_account).to be_an Besepa::BankAccount
65
+ expect(bank_account.iban).to eq("ES6012345678050000000001")
66
+ end
67
+ end
68
+
69
+ describe '.generate_signature_request' do
70
+ describe 'with creditor account' do
71
+ before do
72
+ stub_get('/bank_accounts/ban12345').to_return(
73
+ body: fixture('bank_account.json'),
74
+ headers: {content_type: 'application/json; charset=utf-8'})
75
+
76
+
77
+ stub_put('/bank_accounts/ban12345/generate_signature_request').to_return(
78
+ body: fixture('bank_account.json'),
79
+ headers: {content_type: 'application/json; charset=utf-8'})
80
+ end
81
+
82
+ it 'returns a bank_account' do
83
+ bank_account = Besepa::BankAccount.find('ban12345')
84
+ result = bank_account.generate_signature_request
85
+ expect(result).to be_an Besepa::BankAccount
86
+ expect(result.iban).to eq("ES6012345678050000000001")
87
+ end
88
+ end
89
+ describe 'with no creditor account' do
90
+ before do
91
+ stub_get('/bank_accounts/ban12345').to_return(
92
+ body: fixture('bank_account.json'),
93
+ headers: {content_type: 'application/json; charset=utf-8'})
94
+
95
+ stub_put('/bank_accounts/ban12345/generate_signature_request').to_return(
96
+ status: 409,
97
+ body: { error: "missing_creditor",
98
+ error_description: "Status: no puede ser activada sin una cuenta de destino"
99
+ }.to_json,
100
+ headers: {content_type: 'application/json; charset=utf-8'}
101
+ )
102
+ end
103
+ it 'raises error' do
104
+ bank_account = Besepa::BankAccount.find('ban12345')
105
+ expect {
106
+ bank_account.generate_signature_request
107
+ }.to raise_error(Besepa::Errors::BesepaError,
108
+ /no puede ser activada sin una cuenta de destino/)
109
+ end
110
+ end
111
+ describe 'when already signed' do
112
+ before do
113
+ stub_get('/bank_accounts/ban12345').to_return(
114
+ body: fixture('bank_account.json'),
115
+ headers: {content_type: 'application/json; charset=utf-8'})
116
+
117
+ stub_put('/bank_accounts/ban12345/generate_signature_request').to_return(
118
+ status: 409,
119
+ body: { error: "already_signed",
120
+ error_description: "Status: el mandato ya ha sido firmado"
121
+ }.to_json,
122
+ headers: {content_type: 'application/json; charset=utf-8'}
123
+ )
124
+ end
125
+ it 'raises error' do
126
+ bank_account = Besepa::BankAccount.find('ban12345')
127
+ expect {
128
+ bank_account.generate_signature_request
129
+ }.to raise_error(Besepa::Errors::BesepaError,
130
+ /ya ha sido firmado/)
131
+ end
132
+ end
133
+ end
134
+ end
@@ -24,7 +24,7 @@ describe Besepa::Customer do
24
24
  stub_get('/customers/cus12345').to_return(body: fixture('customer.json'), headers: {content_type: 'application/json; charset=utf-8'})
25
25
  end
26
26
 
27
- it 'returns a a customer' do
27
+ it 'returns a customer' do
28
28
  customer = Besepa::Customer.find('cus12345')
29
29
  expect(customer).to be_an Besepa::Customer
30
30
  expect(customer.name).to eq("Pancho Villa SLU")
@@ -54,7 +54,7 @@ describe Besepa::Customer do
54
54
  stub_put('/customers/cus12345').to_return(body: fixture('customer.json'), headers: {content_type: 'application/json; charset=utf-8'})
55
55
  end
56
56
 
57
- it 'returns a a customer' do
57
+ it 'returns a customer' do
58
58
  customer = Besepa::Customer.find('cus12345')
59
59
  customer.name = customer.name.reverse
60
60
  customer = customer.save
@@ -69,7 +69,7 @@ describe Besepa::Customer do
69
69
  stub_delete('/customers/cus12345').to_return(body: fixture('customer_removed.json'), headers: {content_type: 'application/json; charset=utf-8'})
70
70
  end
71
71
 
72
- it 'returns a a customer' do
72
+ it 'returns a customer' do
73
73
  customer = Besepa::Customer.find('cus12345')
74
74
  customer.name = customer.name.reverse
75
75
  customer = customer.destroy
@@ -0,0 +1,63 @@
1
+ require 'helper'
2
+
3
+ describe Besepa::Report do
4
+
5
+ describe '#all' do
6
+ before do
7
+ stub_get('/reports?page=1').to_return(body: fixture('reports.json'), headers: {content_type: 'application/json; charset=utf-8'})
8
+ end
9
+
10
+ it 'returns a list of reports' do
11
+ reports = Besepa::Report.all(page: 1)
12
+ expect(reports).to respond_to(:each)
13
+ expect(reports.first).to be_an Besepa::Report
14
+ expect(reports.size).to eq(3)
15
+ expect(reports.per_page).to eq(30)
16
+ expect(reports.current_page).to eq(1)
17
+ expect(reports.total).to eq(3)
18
+ expect(reports.pages).to eq(1)
19
+ end
20
+ end
21
+
22
+ describe '#find' do
23
+ before do
24
+ stub_get('/reports/rep123456789').to_return(body: fixture('report.json'), headers: {content_type: 'application/json; charset=utf-8'})
25
+ end
26
+
27
+ it 'returns a report' do
28
+ report = Besepa::Report.find('rep123456789')
29
+ expect(report).to be_an Besepa::Report
30
+ expect(report.kind).to eq("FullExcelReports")
31
+ expect(report.status).to eq("GENERATED")
32
+ end
33
+ end
34
+
35
+ describe '#search' do
36
+ before do
37
+ stub_get('/reports/search?field=group_id&value=foo&page=1').to_return(body: fixture('reports.json'), headers: {content_type: 'application/json; charset=utf-8'})
38
+ end
39
+
40
+ it 'returs a list of reports' do
41
+ reports = Besepa::Report.search(field: 'group_id', value: 'foo', page: 1)
42
+ expect(reports).to respond_to(:each)
43
+ expect(reports.first).to be_an Besepa::Report
44
+ expect(reports.size).to eq(3)
45
+ expect(reports.per_page).to eq(30)
46
+ expect(reports.current_page).to eq(1)
47
+ expect(reports.total).to eq(3)
48
+ expect(reports.pages).to eq(1)
49
+ end
50
+ end
51
+
52
+ describe '#download_url' do
53
+ before do
54
+ stub_get("/reports/rep123456789").to_return(body: fixture('report.json'), headers: {content_type: 'application/json; charset=utf-8'})
55
+ stub_get("/reports/rep123456789/download").to_return(body: fixture('report_url.json'), headers: {content_type: 'application/json; charset=utf-8'})
56
+ end
57
+
58
+ it "returns download url" do
59
+ report = Besepa::Report.find('rep123456789')
60
+ expect(report.download_url).to eq("url_s3")
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,15 @@
1
+ {
2
+ "response": {
3
+ "id": "ban12345",
4
+ "iban": "ES6012345678050000000001",
5
+ "bic": "TESTXXX",
6
+ "bank_name": "Banco Test",
7
+ "status": "PENDING_MANDATE",
8
+ "default": true,
9
+ "created_at": "2016-08-26T10:52:28.000+02:00",
10
+ "b2b_enabled": true,
11
+ "b2b_suffix": "001",
12
+ "core_enabled": true,
13
+ "core_suffix": "000"
14
+ }
15
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "response": [
3
+ {
4
+ "id": "ban12345",
5
+ "iban": "ES6012345678050000000001",
6
+ "bic": "TESTXXX",
7
+ "bank_name": "Banco Test",
8
+ "status": "PENDING_MANDATE",
9
+ "default": true,
10
+ "created_at": "2016-08-26T10:52:28.000+02:00",
11
+ "b2b_enabled": true,
12
+ "b2b_suffix": "001",
13
+ "core_enabled": true,
14
+ "core_suffix": "000"
15
+ }
16
+ ],
17
+ "count": 1,
18
+ "pagination": {
19
+ "previous": null,
20
+ "next": null,
21
+ "current": 1,
22
+ "per_page": 30,
23
+ "count": 1,
24
+ "pages": 1
25
+ }
26
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "response": {
3
+ "id": "rep123456789",
4
+ "kind": "FullExcelReports",
5
+ "status": "GENERATED",
6
+ "until_at": "2017-07-14",
7
+ "since_at": "2017-07-14",
8
+ "document_file_name": "README.md",
9
+ "document_file_size": 2345,
10
+ "created_at": "2017-08-08T13:31:59.000+02:00",
11
+ "updated_at": "2017-08-08T13:31:59.000+02:00"
12
+ }
13
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "response": {
3
+ "url": "url_s3"
4
+ }
5
+ }
@@ -0,0 +1,46 @@
1
+ {
2
+ "response": [
3
+ {
4
+ "id": "rep835c463c1d7783",
5
+ "until_at": "2017-07-14",
6
+ "since_at": "2017-07-14",
7
+ "kind": "FullExcelReports",
8
+ "status": "QUEUED",
9
+ "document_file_name": "README.md",
10
+ "document_file_size": 2345,
11
+ "created_at": "2017-08-08T13:31:59.000+02:00",
12
+ "updated_at": "2017-08-08T13:31:59.000+02:00"
13
+ },
14
+ {
15
+ "id": "rep4bd6790cd1706d",
16
+ "until_at": "2017-07-14",
17
+ "since_at": "2017-07-14",
18
+ "kind": "FullExcelReports",
19
+ "status": "QUEUED",
20
+ "document_file_name": "README.md",
21
+ "document_file_size": 2345,
22
+ "created_at": "2017-08-08T13:31:59.000+02:00",
23
+ "updated_at": "2017-08-08T13:31:59.000+02:00"
24
+ },
25
+ {
26
+ "id": "repecd4f6592d0054",
27
+ "until_at": "2017-07-14",
28
+ "since_at": "2017-07-14",
29
+ "kind": "FullExcelReports",
30
+ "status": "QUEUED",
31
+ "document_file_name": "README.md",
32
+ "document_file_size": 2345,
33
+ "created_at": "2017-08-08T13:31:59.000+02:00",
34
+ "updated_at": "2017-08-08T13:31:59.000+02:00"
35
+ }
36
+ ],
37
+ "count": 3,
38
+ "pagination": {
39
+ "previous": null,
40
+ "next": null,
41
+ "current": 1,
42
+ "per_page": 30,
43
+ "count": 3,
44
+ "pages": 1
45
+ }
46
+ }
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.8.6
4
+ version: 0.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - besepa.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-14 00:00:00.000000000 Z
11
+ date: 2018-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Ruby client for besepa.com
98
112
  email:
99
113
  - alberto@besepa.com
@@ -127,6 +141,7 @@ files:
127
141
  - lib/besepa/payment.rb
128
142
  - lib/besepa/product.rb
129
143
  - lib/besepa/remittance.rb
144
+ - lib/besepa/report.rb
130
145
  - lib/besepa/resource.rb
131
146
  - lib/besepa/subscription.rb
132
147
  - lib/besepa/user.rb
@@ -135,9 +150,13 @@ files:
135
150
  - lib/besepa/utils/request.rb
136
151
  - lib/besepa/utils/version.rb
137
152
  - lib/besepa/webhook.rb
153
+ - spec/besepa/bank_account_spec.rb
138
154
  - spec/besepa/customer_spec.rb
139
155
  - spec/besepa/group_spec.rb
156
+ - spec/besepa/report_spec.rb
140
157
  - spec/besepa/subscription_spec.rb
158
+ - spec/fixtures/bank_account.json
159
+ - spec/fixtures/bank_accounts.json
141
160
  - spec/fixtures/collection.json
142
161
  - spec/fixtures/customer.json
143
162
  - spec/fixtures/customer_add_debit.json
@@ -145,6 +164,9 @@ files:
145
164
  - spec/fixtures/customer_debits.json
146
165
  - spec/fixtures/customer_removed.json
147
166
  - spec/fixtures/customers.json
167
+ - spec/fixtures/report.json
168
+ - spec/fixtures/report_url.json
169
+ - spec/fixtures/reports.json
148
170
  - spec/fixtures/resource.json
149
171
  - spec/helper.rb
150
172
  homepage: http://www.besepa.com
@@ -167,14 +189,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
189
  version: '0'
168
190
  requirements: []
169
191
  rubyforge_project:
170
- rubygems_version: 2.4.6
192
+ rubygems_version: 2.5.2
171
193
  signing_key:
172
194
  specification_version: 4
173
195
  summary: Ruby client for besepa.com
174
196
  test_files:
197
+ - spec/besepa/bank_account_spec.rb
175
198
  - spec/besepa/customer_spec.rb
176
199
  - spec/besepa/group_spec.rb
200
+ - spec/besepa/report_spec.rb
177
201
  - spec/besepa/subscription_spec.rb
202
+ - spec/fixtures/bank_account.json
203
+ - spec/fixtures/bank_accounts.json
178
204
  - spec/fixtures/collection.json
179
205
  - spec/fixtures/customer.json
180
206
  - spec/fixtures/customer_add_debit.json
@@ -182,5 +208,8 @@ test_files:
182
208
  - spec/fixtures/customer_debits.json
183
209
  - spec/fixtures/customer_removed.json
184
210
  - spec/fixtures/customers.json
211
+ - spec/fixtures/report.json
212
+ - spec/fixtures/report_url.json
213
+ - spec/fixtures/reports.json
185
214
  - spec/fixtures/resource.json
186
215
  - spec/helper.rb