boletosimples 0.4.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +6 -14
- data/README.md +12 -54
- data/lib/boletosimples.rb +10 -6
- data/lib/boletosimples/configuration.rb +18 -33
- data/lib/boletosimples/last_request.rb +12 -9
- data/lib/boletosimples/middlewares/bearer.rb +12 -0
- data/lib/boletosimples/middlewares/last_request.rb +3 -1
- data/lib/boletosimples/middlewares/raise_error.rb +9 -2
- data/lib/boletosimples/middlewares/user_agent.rb +3 -1
- data/lib/boletosimples/resources/bank_billet.rb +5 -11
- data/lib/boletosimples/resources/bank_billet_account.rb +3 -1
- data/lib/boletosimples/resources/bank_billet_discharge.rb +6 -0
- data/lib/boletosimples/resources/bank_billet_payment.rb +6 -0
- data/lib/boletosimples/resources/bank_billet_remittance.rb +6 -0
- data/lib/boletosimples/resources/base_model.rb +3 -1
- data/lib/boletosimples/resources/customer.rb +3 -1
- data/lib/boletosimples/resources/customer_import.rb +8 -0
- data/lib/boletosimples/resources/customer_subscription.rb +3 -10
- data/lib/boletosimples/resources/customer_subscription_import.rb +8 -0
- data/lib/boletosimples/resources/discharge.rb +4 -11
- data/lib/boletosimples/resources/email_delivery.rb +6 -0
- data/lib/boletosimples/resources/event.rb +3 -1
- data/lib/boletosimples/resources/installment.rb +3 -1
- data/lib/boletosimples/resources/remittance.rb +3 -1
- data/lib/boletosimples/resources/sms_delivery.rb +6 -0
- data/lib/boletosimples/resources/transaction.rb +3 -1
- data/lib/boletosimples/resources/webhook.rb +3 -1
- data/lib/boletosimples/resources/webhook_delivery.rb +3 -1
- data/lib/boletosimples/response_error.rb +8 -3
- data/lib/boletosimples/version.rb +3 -1
- data/spec/boletosimples/configuration_spec.rb +71 -83
- data/spec/boletosimples/last_request_spec.rb +16 -28
- data/spec/boletosimples/resources/bank_billet_account_spec.rb +57 -33
- data/spec/boletosimples/resources/bank_billet_discharge_spec.rb +12 -0
- data/spec/boletosimples/resources/bank_billet_payment_spec.rb +12 -0
- data/spec/boletosimples/resources/bank_billet_remittance_spec.rb +12 -0
- data/spec/boletosimples/resources/bank_billet_spec.rb +56 -42
- data/spec/boletosimples/resources/customer_import_spec.rb +67 -0
- data/spec/boletosimples/resources/customer_spec.rb +52 -39
- data/spec/boletosimples/resources/customer_subscription_import_spec.rb +67 -0
- data/spec/boletosimples/resources/customer_subscription_spec.rb +61 -33
- data/spec/boletosimples/resources/discharge_spec.rb +64 -11
- data/spec/boletosimples/resources/email_delivery_spec.rb +12 -0
- data/spec/boletosimples/resources/event_spec.rb +7 -12
- data/spec/boletosimples/resources/installment_spec.rb +61 -32
- data/spec/boletosimples/resources/remittance_spec.rb +7 -12
- data/spec/boletosimples/resources/sms_delivery_spec.rb +12 -0
- data/spec/boletosimples/resources/transactions_spec.rb +7 -12
- data/spec/boletosimples/resources/webhook_delivery_spec.rb +7 -12
- data/spec/boletosimples/resources/webhook_spec.rb +7 -12
- data/spec/fixtures/customer_imports.csv +1 -0
- data/spec/fixtures/customer_subscription_imports.csv +1 -0
- data/spec/fixtures/discharge.RET +3 -0
- data/spec/fixtures/vcr_cassettes/last_request/bank_billets.yml +536 -88
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml +537 -91
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/success.yml +34 -92
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_params.yml +32 -20
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_root.yml +28 -17
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/valid.yml +43 -27
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/duplicate/success.yml +83 -0
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/find.yml +51 -27
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/all.yml +131 -20
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_params.yml +34 -20
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_root.yml +30 -19
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/valid.yml +41 -21
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/find.yml +38 -18
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_discharge/all.yml +97 -0
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_payment/all.yml +75 -0
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_remittance/all.yml +126 -0
- data/spec/fixtures/vcr_cassettes/resources/customer/all.yml +79 -32
- data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_params.yml +30 -17
- data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_root.yml +28 -17
- data/spec/fixtures/vcr_cassettes/resources/customer/create/valid.yml +33 -21
- data/spec/fixtures/vcr_cassettes/resources/customer/find.yml +33 -19
- data/spec/fixtures/vcr_cassettes/resources/customer_import/all.yml +74 -0
- data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_params.yml +69 -0
- data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_root.yml +69 -0
- data/spec/fixtures/vcr_cassettes/resources/customer_import/create/valid.yml +76 -0
- data/spec/fixtures/vcr_cassettes/resources/customer_import/find.yml +71 -0
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/all.yml +102 -52
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_params.yml +40 -50
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_root.yml +36 -48
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/valid.yml +48 -53
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/find.yml +44 -50
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/next_charge.yml +45 -133
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/all.yml +75 -0
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_params.yml +69 -0
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_root.yml +70 -0
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/valid.yml +76 -0
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/find.yml +71 -0
- data/spec/fixtures/vcr_cassettes/resources/discharge/all.yml +64 -33
- data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_params.yml +70 -0
- data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_root.yml +69 -0
- data/spec/fixtures/vcr_cassettes/resources/discharge/create/valid.yml +84 -0
- data/spec/fixtures/vcr_cassettes/resources/discharge/find.yml +71 -0
- data/spec/fixtures/vcr_cassettes/resources/email_delivery/all.yml +73 -0
- data/spec/fixtures/vcr_cassettes/resources/event/all.yml +490 -166
- data/spec/fixtures/vcr_cassettes/resources/installment/all.yml +418 -52
- data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_params.yml +41 -52
- data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_root.yml +36 -48
- data/spec/fixtures/vcr_cassettes/resources/installment/create/valid.yml +48 -53
- data/spec/fixtures/vcr_cassettes/resources/installment/find.yml +44 -52
- data/spec/fixtures/vcr_cassettes/resources/remittance/all.yml +53 -33
- data/spec/fixtures/vcr_cassettes/resources/sns_delivery/all.yml +73 -0
- data/spec/fixtures/vcr_cassettes/resources/transaction/all.yml +34 -22
- data/spec/fixtures/vcr_cassettes/resources/web_hook/all.yml +42 -33
- data/spec/fixtures/vcr_cassettes/resources/webhook_delivery/all.yml +1232 -54
- data/spec/spec_helper.rb +3 -20
- data/spec/support/stub_env.rb +7 -0
- data/spec/support/vcr.rb +3 -4
- metadata +190 -82
- data/.coveralls.yml +0 -2
- data/.gitignore +0 -19
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -11
- data/Gemfile +0 -4
- data/Rakefile +0 -6
- data/boletosimples.gemspec +0 -37
- data/lib/boletosimples/extra.rb +0 -8
- data/lib/boletosimples/resources/partner/user.rb +0 -7
- data/lib/oauth2_patch.rb +0 -24
- data/spec/boletosimples/extra_spec.rb +0 -31
- data/spec/boletosimples/resources/partner/user_spec.rb +0 -19
- data/spec/fixtures/vcr_cassettes/configuration/client_credentials/invalid.yml +0 -64
- data/spec/fixtures/vcr_cassettes/configuration/client_credentials/valid.yml +0 -56
- data/spec/fixtures/vcr_cassettes/extra/userinfo/authenticated.yml +0 -58
- data/spec/fixtures/vcr_cassettes/extra/userinfo/not_authenticated.yml +0 -54
- data/spec/fixtures/vcr_cassettes/last_request/userinfo.yml +0 -58
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/failure.yml +0 -118
- data/spec/fixtures/vcr_cassettes/resources/partner/user/create.yml +0 -60
- data/spec/spec.opts +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a50336e111c9ed876ff2fd2c6821a2b358c47b77d1cd9fc536d37127f82f0b31
|
4
|
+
data.tar.gz: bda195f137e393e9e9fa4dcb0c937d72ee4bc2cae0b46fbb3cc3559532852500
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0d7bb571f7cfc0364402d082a6ddf48ae476e11d9fb320ed3682b4dd198a94c1924d6e87c935fb78c94cfa6bdb8fd922c665be6207df22eb161a02cc854e3eb
|
7
|
+
data.tar.gz: e9b0a0dfe9092bc01d4b8bf43ef9f1f38b2a56f65dcb27a901fc9438c3b1b20a40dcf07c065f00c70ac0db2cf20f6d9d12ebbde5b01c464f758e7a7ed9fa763f
|
data/CHANGELOG.md
CHANGED
@@ -1,18 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 0.
|
3
|
+
## 1.0.0
|
4
4
|
|
5
|
-
###
|
5
|
+
### Breaking changes
|
6
6
|
|
7
|
-
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
### features
|
12
|
-
|
13
|
-
- Created `client.cancel_bank_billet(id, options)` to cancel bank billets
|
14
|
-
|
15
|
-
### improvements
|
16
|
-
|
17
|
-
- Changed `client.create_customer({ "customer" => params })` to `client.create_customer(params)`
|
18
|
-
- Changed `client.create_bank_billet({ "bank_billet" => params })` to `client.create_bank_billet(params)`
|
7
|
+
- Remove Oauth code
|
8
|
+
- Require user_agent configuration
|
9
|
+
- Require api_token configuration
|
10
|
+
- All Errors now return with same root `errors`
|
data/README.md
CHANGED
@@ -1,16 +1,9 @@
|
|
1
1
|
# Boleto Simples Ruby
|
2
2
|
|
3
3
|
[![Gem Version](http://img.shields.io/gem/v/boletosimples.svg)][gem]
|
4
|
-
[![
|
5
|
-
[![Dependency Status](http://img.shields.io/gemnasium/BoletoSimples/boletosimples-ruby.svg)][gemnasium]
|
6
|
-
[![Code Climate](http://img.shields.io/codeclimate/github/BoletoSimples/boletosimples-ruby.svg)][codeclimate]
|
7
|
-
[![Coverage Status](http://img.shields.io/coveralls/BoletoSimples/boletosimples-ruby.svg)][coveralls]
|
4
|
+
[![Ruby](https://github.com/BoletoSimples/boletosimples-ruby/actions/workflows/ruby.yml/badge.svg?branch=master)](https://github.com/BoletoSimples/boletosimples-ruby/actions/workflows/ruby.yml)
|
8
5
|
|
9
6
|
[gem]: https://rubygems.org/gems/boletosimples
|
10
|
-
[travis]: http://travis-ci.org/BoletoSimples/boletosimples-ruby
|
11
|
-
[gemnasium]: https://gemnasium.com/BoletoSimples/boletosimples-ruby
|
12
|
-
[codeclimate]: https://codeclimate.com/github/BoletoSimples/boletosimples-ruby
|
13
|
-
[coveralls]: https://coveralls.io/r/BoletoSimples/boletosimples-ruby
|
14
7
|
|
15
8
|
Biblioteca Ruby para acessar informações do [Boleto Simples](http://boletosimples.com.br) através da [API](http://api.boletosimples.com.br).
|
16
9
|
|
@@ -30,12 +23,17 @@ Ou instale você mesmo:
|
|
30
23
|
|
31
24
|
## Configuração
|
32
25
|
|
26
|
+
Saiba mais sobre o [Token de API ](https://api.boletosimples.com.br/authentication/token/)
|
27
|
+
|
33
28
|
```ruby
|
34
29
|
require 'boletosimples'
|
35
30
|
|
36
31
|
BoletoSimples.configure do |c|
|
37
32
|
c.environment = :production # defaut :sandbox
|
38
|
-
|
33
|
+
# production - https://boletosimples.com.br/conta/api/tokens
|
34
|
+
# sandbox - https://sandbox.boletosimples.com.br/conta/api/tokens
|
35
|
+
c.api_token = 'api-token'
|
36
|
+
c.user_agent = 'email@minhaempresa.com.br' #Colocar um e-mail válido para contatos técnicos relacionado ao uso da API.
|
39
37
|
end
|
40
38
|
```
|
41
39
|
|
@@ -45,9 +43,7 @@ Você também pode configurar as variáveis de ambiente a seguir e não será ne
|
|
45
43
|
|
46
44
|
```bash
|
47
45
|
ENV['BOLETOSIMPLES_ENV']
|
48
|
-
ENV['
|
49
|
-
ENV['BOLETOSIMPLES_APP_SECRET']
|
50
|
-
ENV['BOLETOSIMPLES_ACCESS_TOKEN']
|
46
|
+
ENV['BOLETOSIMPLES_API_TOKEN']
|
51
47
|
```
|
52
48
|
|
53
49
|
### Configurando cache
|
@@ -72,7 +68,7 @@ Exemplo:
|
|
72
68
|
|
73
69
|
```ruby
|
74
70
|
# Criar um boleto
|
75
|
-
@bank_billet = BoletoSimples::BankBillet.create(
|
71
|
+
@bank_billet = BoletoSimples::BankBillet.create(
|
76
72
|
amount: 9.01,
|
77
73
|
description: 'Despesas do contrato 0012',
|
78
74
|
expire_at: '2014-01-01',
|
@@ -88,7 +84,7 @@ Exemplo:
|
|
88
84
|
customer_phone_number: '2112123434',
|
89
85
|
customer_state: 'RJ',
|
90
86
|
customer_zipcode: '12312-123'
|
91
|
-
|
87
|
+
)
|
92
88
|
|
93
89
|
# Criar um novo boleto instanciando o objeto
|
94
90
|
@bank_billet = BoletoSimples::BankBillet.new(amount: 199.99, expire_at: '2020-01-01')
|
@@ -112,14 +108,6 @@ Exemplo:
|
|
112
108
|
puts bank_billet.attributes
|
113
109
|
end
|
114
110
|
|
115
|
-
# Após realizar a chamada na listagem, você terá acesso aos seguintes dados:
|
116
|
-
|
117
|
-
BoletoSimples.last_request.total # número total de boletos
|
118
|
-
BoletoSimples.last_request.links[:first] # url da primeira página
|
119
|
-
BoletoSimples.last_request.links[:prev] # url da página anterior
|
120
|
-
BoletoSimples.last_request.links[:next] # url da próxima página
|
121
|
-
BoletoSimples.last_request.links[:last] # url da última página
|
122
|
-
|
123
111
|
# Cancelar um boleto
|
124
112
|
@bank_billet = BoletoSimples::BankBillet.find(1)
|
125
113
|
@bank_billet.cancel
|
@@ -130,7 +118,7 @@ BoletoSimples.last_request.links[:last] # url da última página
|
|
130
118
|
|
131
119
|
```ruby
|
132
120
|
# Criar um cliente
|
133
|
-
@customer = BoletoSimples::Customer.create(
|
121
|
+
@customer = BoletoSimples::Customer.create(
|
134
122
|
person_name: "Joao da Silva",
|
135
123
|
cnpj_cpf: "012.345.678-90",
|
136
124
|
email: "cliente@example.com",
|
@@ -142,7 +130,7 @@ BoletoSimples.last_request.links[:last] # url da última página
|
|
142
130
|
address_number: "111",
|
143
131
|
address_complement: "Sala 4",
|
144
132
|
phone_number: "2112123434"
|
145
|
-
|
133
|
+
)
|
146
134
|
|
147
135
|
# Mensagens de erro na criação do cliente
|
148
136
|
@customer = BoletoSimples::Customer.new(person_name: '')
|
@@ -155,38 +143,8 @@ BoletoSimples.last_request.links[:last] # url da última página
|
|
155
143
|
puts customer.attributes
|
156
144
|
end
|
157
145
|
|
158
|
-
# Após realizar a chamada na listagem, você terá acesso aos seguintes dados:
|
159
|
-
|
160
|
-
BoletoSimples.last_request.total # número total de clientes
|
161
|
-
BoletoSimples.last_request.links[:first] # url da primeira página
|
162
|
-
BoletoSimples.last_request.links[:prev] # url da página anterior
|
163
|
-
BoletoSimples.last_request.links[:next] # url da próxima página
|
164
|
-
BoletoSimples.last_request.links[:last] # url da última página
|
165
|
-
|
166
146
|
# Atualizar um cliente
|
167
147
|
@customer = BoletoSimples::Customer.find(1)
|
168
148
|
@customer.person_name = 'Novo nome'
|
169
149
|
@customer.save
|
170
150
|
```
|
171
|
-
|
172
|
-
### Extrato
|
173
|
-
|
174
|
-
```ruby
|
175
|
-
# Listar todas as transações
|
176
|
-
@transactions = BoletoSimples::Transaction.all
|
177
|
-
@transactions.each do |transaction|
|
178
|
-
puts transaction.attributes
|
179
|
-
end
|
180
|
-
```
|
181
|
-
|
182
|
-
### Extras
|
183
|
-
|
184
|
-
```ruby
|
185
|
-
# Dados do usuário logado
|
186
|
-
@userinfo = BoletoSimples::Extra.userinfo
|
187
|
-
```
|
188
|
-
|
189
|
-
## OAuth 2.0 Authentication (para acessar as contas dos usuários)
|
190
|
-
|
191
|
-
Comece [solicitando um cadastro de OAuth 2.0 application](http://suporte.boletosimples.com.br)
|
192
|
-
|
data/lib/boletosimples.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'her'
|
2
4
|
require 'faraday_middleware'
|
3
5
|
require 'faraday-http-cache'
|
@@ -5,15 +7,21 @@ require 'boletosimples/version'
|
|
5
7
|
|
6
8
|
module BoletoSimples
|
7
9
|
autoload :Configuration, 'boletosimples/configuration'
|
8
|
-
autoload :Extra, 'boletosimples/extra'
|
9
10
|
autoload :ResponseError, 'boletosimples/response_error'
|
10
11
|
autoload :LastRequest, 'boletosimples/last_request'
|
11
12
|
|
12
13
|
autoload :BankBillet, 'boletosimples/resources/bank_billet'
|
13
14
|
autoload :BankBilletAccount, 'boletosimples/resources/bank_billet_account'
|
15
|
+
autoload :BankBilletDischarge, 'boletosimples/resources/bank_billet_discharge'
|
16
|
+
autoload :BankBilletPayment, 'boletosimples/resources/bank_billet_payment'
|
17
|
+
autoload :BankBilletRemittance, 'boletosimples/resources/bank_billet_remittance'
|
14
18
|
autoload :Event, 'boletosimples/resources/event'
|
19
|
+
autoload :EmailDelivery, 'boletosimples/resources/email_delivery'
|
20
|
+
autoload :SmsDelivery, 'boletosimples/resources/sms_delivery'
|
15
21
|
autoload :Customer, 'boletosimples/resources/customer'
|
22
|
+
autoload :CustomerImport, 'boletosimples/resources/customer_import'
|
16
23
|
autoload :CustomerSubscription, 'boletosimples/resources/customer_subscription'
|
24
|
+
autoload :CustomerSubscriptionImport, 'boletosimples/resources/customer_subscription_import'
|
17
25
|
autoload :Installment, 'boletosimples/resources/installment'
|
18
26
|
autoload :Transaction, 'boletosimples/resources/transaction'
|
19
27
|
autoload :Remittance, 'boletosimples/resources/remittance'
|
@@ -22,14 +30,11 @@ module BoletoSimples
|
|
22
30
|
autoload :Webhook, 'boletosimples/resources/webhook'
|
23
31
|
autoload :WebhookDelivery, 'boletosimples/resources/webhook_delivery'
|
24
32
|
|
25
|
-
module Partner
|
26
|
-
autoload :User, 'boletosimples/resources/partner/user'
|
27
|
-
end
|
28
|
-
|
29
33
|
module Middleware
|
30
34
|
autoload :UserAgent, 'boletosimples/middlewares/user_agent'
|
31
35
|
autoload :RaiseError, 'boletosimples/middlewares/raise_error'
|
32
36
|
autoload :LastRequest, 'boletosimples/middlewares/last_request'
|
37
|
+
autoload :Bearer, 'boletosimples/middlewares/bearer'
|
33
38
|
end
|
34
39
|
|
35
40
|
class << self
|
@@ -41,7 +46,6 @@ module BoletoSimples
|
|
41
46
|
configuration.setup_her # after changing configuration gem her should be configured
|
42
47
|
end
|
43
48
|
end
|
44
|
-
|
45
49
|
end
|
46
50
|
|
47
51
|
BoletoSimples.configure
|
@@ -1,21 +1,19 @@
|
|
1
|
-
#
|
2
|
-
module BoletoSimples
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
3
|
+
module BoletoSimples
|
4
4
|
class Configuration
|
5
|
-
attr_accessor :environment, :
|
6
|
-
|
5
|
+
attr_accessor :environment, :cache, :user_agent, :api_token
|
7
6
|
|
8
7
|
BASE_URI = {
|
9
8
|
sandbox: 'https://sandbox.boletosimples.com.br/api/v1',
|
10
9
|
production: 'https://boletosimples.com.br/api/v1',
|
11
10
|
development: 'http://localhost:5000/api/v1'
|
12
|
-
}
|
11
|
+
}.freeze
|
13
12
|
|
14
13
|
def initialize
|
15
14
|
@environment = (ENV['BOLETOSIMPLES_ENV'] || :sandbox).to_sym
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@access_token = ENV['BOLETOSIMPLES_ACCESS_TOKEN']
|
15
|
+
@api_token = ENV['BOLETOSIMPLES_API_TOKEN']
|
16
|
+
@user_agent = ENV['BOLETOSIMPLES_USER_AGENT']
|
19
17
|
@cache = nil
|
20
18
|
end
|
21
19
|
|
@@ -23,32 +21,19 @@ module BoletoSimples
|
|
23
21
|
BASE_URI[@environment]
|
24
22
|
end
|
25
23
|
|
26
|
-
def
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def access_token?
|
31
|
-
!@access_token.nil?
|
32
|
-
end
|
33
|
-
|
34
|
-
def client_credentials
|
35
|
-
response = Her::API.default_api.connection.post 'oauth2/token', {
|
36
|
-
grant_type: 'client_credentials',
|
37
|
-
client_id: application_id,
|
38
|
-
client_secret: application_secret
|
39
|
-
}
|
40
|
-
response.body[:data]
|
24
|
+
def api_token?
|
25
|
+
!@api_token.nil?
|
41
26
|
end
|
42
27
|
|
43
28
|
def setup_her
|
44
|
-
Her::API.setup url:
|
29
|
+
Her::API.setup url: base_uri do |c|
|
45
30
|
# Request
|
46
31
|
c.use BoletoSimples::Middleware::UserAgent
|
47
|
-
c.use
|
32
|
+
c.use BoletoSimples::Middleware::Bearer if api_token?
|
33
|
+
c.use Faraday::Request::Multipart
|
48
34
|
c.use FaradayMiddleware::EncodeJson
|
49
|
-
|
50
|
-
|
51
|
-
end
|
35
|
+
c.use Her::Middleware::AcceptJSON
|
36
|
+
c.use Faraday::HttpCache, store: cache unless cache.nil?
|
52
37
|
|
53
38
|
# Response
|
54
39
|
c.use BoletoSimples::Middleware::LastRequest
|
@@ -56,16 +41,16 @@ module BoletoSimples
|
|
56
41
|
c.use Her::Middleware::DefaultParseJSON
|
57
42
|
|
58
43
|
# Adapter
|
59
|
-
c.
|
44
|
+
c.adapter Faraday::Adapter::NetHttp
|
60
45
|
end
|
61
46
|
|
62
47
|
# Because Her set the api on the moment module is included we need to call use_api again, after changing the configuration.
|
63
|
-
[BankBillet, BankBilletAccount, Customer,
|
64
|
-
|
48
|
+
[BankBillet, BankBilletAccount, Customer, CustomerImport, CustomerSubscription,
|
49
|
+
CustomerSubscriptionImport, Installment, Transaction, Webhook, Discharge,
|
50
|
+
Remittance, WebhookDelivery, Event, EmailDelivery, BankBilletDischarge,
|
51
|
+
BankBilletPayment, BankBilletRemittance, SmsDelivery].each do |klass|
|
65
52
|
klass.send(:use_api, Her::API.default_api)
|
66
53
|
end
|
67
54
|
end
|
68
|
-
|
69
55
|
end
|
70
|
-
|
71
56
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BoletoSimples
|
2
4
|
class LastRequest
|
3
5
|
attr_reader :body, :response_headers, :total, :ratelimit_limit, :ratelimit_remaining, :links
|
@@ -15,29 +17,30 @@ module BoletoSimples
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def total
|
18
|
-
@total ||= @env[:response_headers][
|
20
|
+
@total ||= @env[:response_headers]['total'].to_i
|
19
21
|
end
|
20
22
|
|
21
23
|
def ratelimit_limit
|
22
|
-
ratelimit_limit ||= @env[:response_headers][
|
24
|
+
ratelimit_limit ||= @env[:response_headers]['x-ratelimit-limit'].to_i
|
23
25
|
end
|
24
26
|
|
25
27
|
def ratelimit_remaining
|
26
|
-
@ratelimit_remaining ||= @env[:response_headers][
|
28
|
+
@ratelimit_remaining ||= @env[:response_headers]['x-ratelimit-remaining'].to_i
|
27
29
|
end
|
28
30
|
|
29
31
|
def links
|
30
32
|
return @links unless @links.nil?
|
31
|
-
|
33
|
+
|
34
|
+
link_header = @env[:response_headers]['link']
|
32
35
|
return {} if link_header.nil?
|
36
|
+
|
33
37
|
@links = {}
|
34
|
-
link_header.split(
|
35
|
-
key = /rel
|
36
|
-
value =
|
38
|
+
link_header.split(', ').each do |link|
|
39
|
+
key = /rel="(.*)"/.match(link)[1]
|
40
|
+
value = /<(.*)>/.match(link)[1]
|
37
41
|
@links[key] = value
|
38
42
|
end
|
39
43
|
@links.symbolize_keys!
|
40
44
|
end
|
41
|
-
|
42
45
|
end
|
43
|
-
end
|
46
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BoletoSimples
|
4
|
+
module Middleware
|
5
|
+
class Bearer < Faraday::Middleware
|
6
|
+
def call(env)
|
7
|
+
env[:request_headers]['Authorization'] = "Bearer #{BoletoSimples.configuration.api_token}"
|
8
|
+
@app.call(env)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,11 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BoletoSimples
|
2
4
|
module Middleware
|
3
5
|
class RaiseError < Faraday::Response::Middleware
|
4
6
|
def on_complete(env)
|
5
7
|
status = env[:status].to_i
|
8
|
+
return if status == 422
|
9
|
+
|
6
10
|
klass = BoletoSimples::ResponseError
|
7
|
-
|
11
|
+
if (400..599).cover?(status) && env[:body][:errors]
|
12
|
+
puts env.inspect
|
13
|
+
raise klass, env
|
14
|
+
end
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
11
|
-
end
|
18
|
+
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BoletoSimples
|
2
4
|
module Middleware
|
3
5
|
class UserAgent < Faraday::Middleware
|
4
6
|
def call(env)
|
5
|
-
env[:request_headers][
|
7
|
+
env[:request_headers]['User-Agent'] = BoletoSimples.configuration.user_agent
|
6
8
|
@app.call(env)
|
7
9
|
end
|
8
10
|
end
|
@@ -1,14 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BoletoSimples
|
2
4
|
class BankBillet < BaseModel
|
3
|
-
|
4
|
-
|
5
|
-
self.class.request(:_method => :put, :_path => self.class.build_request_path('bank_billets/:id/cancel', {self.class.primary_key => id})) do |parsed_data, response|
|
6
|
-
assign_attributes(self.class.parse(parsed_data[:data])) if parsed_data[:data].any?
|
7
|
-
@metadata = parsed_data[:metadata]
|
8
|
-
@response_errors = parsed_data[:errors]
|
9
|
-
@response = response
|
10
|
-
end
|
11
|
-
return @response.success?
|
12
|
-
end
|
5
|
+
custom_put :pay, :cancel
|
6
|
+
custom_post :duplicate
|
13
7
|
end
|
14
|
-
end
|
8
|
+
end
|