boletosimples 0.6.0 → 2.1.0
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 +4 -4
- data/CHANGELOG.md +16 -12
- data/README.md +21 -59
- data/lib/boletosimples/configuration.rb +25 -28
- data/lib/boletosimples/last_request.rb +17 -10
- data/lib/boletosimples/middlewares/bearer.rb +12 -0
- data/lib/boletosimples/middlewares/custom_headers.rb +12 -0
- data/lib/boletosimples/middlewares/debug.rb +30 -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 +3 -1
- data/lib/boletosimples/resources/bank_billet_payment.rb +3 -1
- data/lib/boletosimples/resources/bank_billet_remittance.rb +3 -1
- data/lib/boletosimples/resources/base_model.rb +3 -1
- data/lib/boletosimples/resources/customer.rb +3 -1
- data/lib/boletosimples/resources/customer_import.rb +5 -3
- data/lib/boletosimples/resources/customer_subscription.rb +3 -10
- data/lib/boletosimples/resources/customer_subscription_import.rb +5 -3
- data/lib/boletosimples/resources/discharge.rb +4 -11
- data/lib/boletosimples/resources/email_delivery.rb +3 -1
- 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 +10 -5
- data/lib/boletosimples/version.rb +3 -1
- data/lib/boletosimples.rb +6 -6
- data/spec/boletosimples/configuration_spec.rb +67 -80
- data/spec/boletosimples/last_request_spec.rb +17 -28
- data/spec/boletosimples/middlewares/custom_headers_spec.rb +26 -0
- data/spec/boletosimples/resources/bank_billet_account_spec.rb +57 -33
- data/spec/boletosimples/resources/bank_billet_discharge_spec.rb +7 -12
- data/spec/boletosimples/resources/bank_billet_payment_spec.rb +7 -12
- data/spec/boletosimples/resources/bank_billet_remittance_spec.rb +7 -12
- data/spec/boletosimples/resources/bank_billet_spec.rb +56 -42
- data/spec/boletosimples/resources/customer_import_spec.rb +41 -30
- data/spec/boletosimples/resources/customer_spec.rb +57 -39
- data/spec/boletosimples/resources/customer_subscription_import_spec.rb +41 -30
- 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 +6 -11
- 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/discharge.RET +3 -0
- data/spec/fixtures/vcr_cassettes/custom_headers.yml +113 -0
- data/spec/fixtures/vcr_cassettes/last_request/bank_billets.yml +409 -95
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml +101 -99
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/success.yml +55 -95
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_params.yml +55 -27
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_root.yml +51 -24
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/valid.yml +64 -34
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/duplicate/success.yml +97 -0
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/find.yml +73 -34
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/all.yml +82 -27
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_params.yml +57 -27
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_root.yml +53 -26
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/valid.yml +64 -28
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/find.yml +61 -25
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_discharge/all.yml +59 -46
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_payment/all.yml +74 -71
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_remittance/all.yml +63 -47
- data/spec/fixtures/vcr_cassettes/resources/customer/all.yml +141 -39
- data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_params.yml +54 -25
- data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_root.yml +54 -24
- data/spec/fixtures/vcr_cassettes/resources/customer/create/valid.yml +56 -28
- data/spec/fixtures/vcr_cassettes/resources/customer/find.yml +56 -26
- data/spec/fixtures/vcr_cassettes/resources/customer_import/all.yml +58 -59
- data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_params.yml +53 -51
- data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_root.yml +54 -52
- data/spec/fixtures/vcr_cassettes/resources/customer_import/create/valid.yml +58 -67
- data/spec/fixtures/vcr_cassettes/resources/customer_import/find.yml +55 -53
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/all.yml +65 -51
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_params.yml +56 -50
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_root.yml +52 -48
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/valid.yml +63 -52
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/find.yml +61 -51
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/next_charge.yml +60 -132
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/all.yml +58 -54
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_params.yml +53 -52
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_root.yml +55 -53
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/valid.yml +58 -69
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/find.yml +55 -54
- data/spec/fixtures/vcr_cassettes/resources/discharge/all.yml +63 -34
- data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_params.yml +86 -0
- data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_root.yml +85 -0
- data/spec/fixtures/vcr_cassettes/resources/discharge/create/valid.yml +100 -0
- data/spec/fixtures/vcr_cassettes/resources/discharge/find.yml +89 -0
- data/spec/fixtures/vcr_cassettes/resources/email_delivery/all.yml +40 -43
- data/spec/fixtures/vcr_cassettes/resources/event/all.yml +326 -167
- data/spec/fixtures/vcr_cassettes/resources/installment/all.yml +113 -51
- data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_params.yml +57 -52
- data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_root.yml +52 -48
- data/spec/fixtures/vcr_cassettes/resources/installment/create/valid.yml +63 -52
- data/spec/fixtures/vcr_cassettes/resources/installment/find.yml +83 -51
- data/spec/fixtures/vcr_cassettes/resources/remittance/all.yml +83 -62
- data/spec/fixtures/vcr_cassettes/resources/sns_delivery/all.yml +89 -0
- data/spec/fixtures/vcr_cassettes/resources/transaction/all.yml +73 -60
- data/spec/fixtures/vcr_cassettes/resources/web_hook/all.yml +59 -34
- data/spec/fixtures/vcr_cassettes/resources/webhook_delivery/all.yml +2684 -55
- data/spec/spec_helper.rb +3 -20
- data/spec/support/stub_env.rb +7 -0
- data/spec/support/vcr.rb +3 -4
- metadata +42 -176
- data/.coveralls.yml +0 -2
- data/.gitignore +0 -19
- data/.ruby-version +0 -1
- data/.travis.yml +0 -46
- data/Gemfile +0 -4
- data/Rakefile +0 -14
- data/boletosimples.gemspec +0 -38
- data/gemfiles/rails_42.gemfile +0 -8
- data/gemfiles/rails_50.gemfile +0 -8
- data/gemfiles/rails_51.gemfile +0 -8
- data/gemfiles/rails_52.gemfile +0 -9
- 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
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b0b065f756a9ee10d080e10686637aee38ca6b63306878dc4879dbf56fd676c
|
4
|
+
data.tar.gz: c83c0eadff5245a19d07ea7a6cbe8c184eeed809e0895db4eb9ca78802250cf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 977fb2769a02f9fcc6da3e2a4a4fe35ba9fe9f80327584bfc3b48dbb1446ea666f1b1cb0c5b61d09422cc1f1ff702a88768e3b58c820b8c83121972dab9ae4cd
|
7
|
+
data.tar.gz: fa35fda07bc7f85c31c03f4991fed958107e4709418292798c22122da79940719688bc337c5ab686224877102c30e475421e79e9d117b4f7ba66c883fba7c333
|
data/CHANGELOG.md
CHANGED
@@ -1,24 +1,28 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 0.
|
3
|
+
## 2.0.0
|
4
4
|
|
5
|
-
###
|
5
|
+
### Changes
|
6
6
|
|
7
|
-
- Update
|
7
|
+
- Update URLs based on new API: https://developers.kobana.com.br/reference/endpoints-1
|
8
8
|
|
9
|
-
## 0.
|
9
|
+
## 1.0.4
|
10
10
|
|
11
|
-
###
|
11
|
+
### Changes
|
12
12
|
|
13
|
-
-
|
13
|
+
- Fix cache
|
14
14
|
|
15
|
-
## 0.
|
15
|
+
## 1.0.3
|
16
16
|
|
17
|
-
###
|
17
|
+
### Changes
|
18
18
|
|
19
|
-
-
|
19
|
+
- Add debug option
|
20
20
|
|
21
|
-
|
21
|
+
## 1.0.0
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
### Breaking changes
|
24
|
+
|
25
|
+
- Remove Oauth code
|
26
|
+
- Require user_agent configuration
|
27
|
+
- Require api_token configuration
|
28
|
+
- All Errors now return with same root `errors`
|
data/README.md
CHANGED
@@ -1,18 +1,11 @@
|
|
1
1
|
# Boleto Simples Ruby
|
2
2
|
|
3
3
|
[][gem]
|
4
|
-
[][gemnasium]
|
6
|
-
[][codeclimate]
|
7
|
-
[][coveralls]
|
4
|
+
[](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
|
-
Biblioteca Ruby para acessar informações
|
8
|
+
Biblioteca Ruby para acessar informações da [Kobana](https://www.kobana.com.br) através da [API](https://api.kobana.com.br).
|
16
9
|
|
17
10
|
## Instalação
|
18
11
|
|
@@ -30,12 +23,19 @@ Ou instale você mesmo:
|
|
30
23
|
|
31
24
|
## Configuração
|
32
25
|
|
26
|
+
Saiba mais sobre o [Token de API ](https://developers.kobana.com.br/reference/token-de-acesso)
|
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://app.kobana.com.br/conta/api/tokens
|
34
|
+
# sandbox - https://app-sandbox.kobana.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.
|
37
|
+
# c.debug = true
|
38
|
+
# c.custom_headers = { 'X-CUSTOM' => 'CONTENT' }
|
39
39
|
end
|
40
40
|
```
|
41
41
|
|
@@ -45,14 +45,13 @@ Você também pode configurar as variáveis de ambiente a seguir e não será ne
|
|
45
45
|
|
46
46
|
```bash
|
47
47
|
ENV['BOLETOSIMPLES_ENV']
|
48
|
-
ENV['
|
49
|
-
ENV['
|
50
|
-
ENV['BOLETOSIMPLES_ACCESS_TOKEN']
|
48
|
+
ENV['BOLETOSIMPLES_API_TOKEN']
|
49
|
+
ENV['BOLETOSIMPLES_DEBUG']
|
51
50
|
```
|
52
51
|
|
53
52
|
### Configurando cache
|
54
53
|
|
55
|
-
É altamente recomendável utilizar o cache para evitar chegar no [limite de requisições](
|
54
|
+
É altamente recomendável utilizar o cache para evitar chegar no [limite de requisições](https://developers.kobana.com.br/reference/limite-de-requisições)
|
56
55
|
|
57
56
|
Para isso recomendamos a utilização da gem [Dalli](https://github.com/mperham/dalli)
|
58
57
|
|
@@ -62,7 +61,9 @@ Exemplo:
|
|
62
61
|
require 'dalli'
|
63
62
|
|
64
63
|
BoletoSimples.configure do |c|
|
65
|
-
c.cache = ActiveSupport::Cache.lookup_store(:
|
64
|
+
c.cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, ['localhost:11211'],
|
65
|
+
namespace: 'boletosimples_client',
|
66
|
+
compress: true)
|
66
67
|
end
|
67
68
|
```
|
68
69
|
|
@@ -72,7 +73,7 @@ Exemplo:
|
|
72
73
|
|
73
74
|
```ruby
|
74
75
|
# Criar um boleto
|
75
|
-
@bank_billet = BoletoSimples::BankBillet.create(
|
76
|
+
@bank_billet = BoletoSimples::BankBillet.create(
|
76
77
|
amount: 9.01,
|
77
78
|
description: 'Despesas do contrato 0012',
|
78
79
|
expire_at: '2014-01-01',
|
@@ -88,7 +89,7 @@ Exemplo:
|
|
88
89
|
customer_phone_number: '2112123434',
|
89
90
|
customer_state: 'RJ',
|
90
91
|
customer_zipcode: '12312-123'
|
91
|
-
|
92
|
+
)
|
92
93
|
|
93
94
|
# Criar um novo boleto instanciando o objeto
|
94
95
|
@bank_billet = BoletoSimples::BankBillet.new(amount: 199.99, expire_at: '2020-01-01')
|
@@ -112,17 +113,8 @@ Exemplo:
|
|
112
113
|
puts bank_billet.attributes
|
113
114
|
end
|
114
115
|
|
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
116
|
# Cancelar um boleto
|
124
|
-
@bank_billet = BoletoSimples::BankBillet.
|
125
|
-
@bank_billet.cancel
|
117
|
+
@bank_billet = BoletoSimples::BankBillet.cancel(id: 1)
|
126
118
|
|
127
119
|
```
|
128
120
|
|
@@ -130,7 +122,7 @@ BoletoSimples.last_request.links[:last] # url da última página
|
|
130
122
|
|
131
123
|
```ruby
|
132
124
|
# Criar um cliente
|
133
|
-
@customer = BoletoSimples::Customer.create(
|
125
|
+
@customer = BoletoSimples::Customer.create(
|
134
126
|
person_name: "Joao da Silva",
|
135
127
|
cnpj_cpf: "012.345.678-90",
|
136
128
|
email: "cliente@example.com",
|
@@ -142,7 +134,7 @@ BoletoSimples.last_request.links[:last] # url da última página
|
|
142
134
|
address_number: "111",
|
143
135
|
address_complement: "Sala 4",
|
144
136
|
phone_number: "2112123434"
|
145
|
-
|
137
|
+
)
|
146
138
|
|
147
139
|
# Mensagens de erro na criação do cliente
|
148
140
|
@customer = BoletoSimples::Customer.new(person_name: '')
|
@@ -155,38 +147,8 @@ BoletoSimples.last_request.links[:last] # url da última página
|
|
155
147
|
puts customer.attributes
|
156
148
|
end
|
157
149
|
|
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
150
|
# Atualizar um cliente
|
167
151
|
@customer = BoletoSimples::Customer.find(1)
|
168
152
|
@customer.person_name = 'Novo nome'
|
169
153
|
@customer.save
|
170
154
|
```
|
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
|
-
|
@@ -1,67 +1,64 @@
|
|
1
|
-
#
|
2
|
-
module BoletoSimples
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
3
|
+
module BoletoSimples
|
4
4
|
class Configuration
|
5
|
-
attr_accessor :environment, :
|
5
|
+
attr_accessor :environment, :cache, :user_agent, :custom_headers, :api_token, :debug
|
6
6
|
|
7
7
|
BASE_URI = {
|
8
|
-
sandbox: 'https://sandbox.
|
9
|
-
production: 'https://
|
8
|
+
sandbox: 'https://api-sandbox.kobana.com.br/v1',
|
9
|
+
production: 'https://api.kobana.com.br/v1',
|
10
10
|
development: 'http://localhost:5000/api/v1'
|
11
|
-
}
|
11
|
+
}.freeze
|
12
12
|
|
13
13
|
def initialize
|
14
|
-
@environment = (
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
14
|
+
@environment = ENV.fetch('BOLETOSIMPLES_ENV', :sandbox).to_sym
|
15
|
+
@api_token = ENV.fetch('BOLETOSIMPLES_API_TOKEN', nil)
|
16
|
+
@user_agent = ENV.fetch('BOLETOSIMPLES_USER_AGENT', nil)
|
17
|
+
@custom_headers = {}
|
18
18
|
@cache = nil
|
19
|
-
@
|
19
|
+
@debug = ENV.fetch('BOLETOSIMPLES_DEBUG', nil)
|
20
20
|
end
|
21
21
|
|
22
22
|
def base_uri
|
23
23
|
BASE_URI[@environment]
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
!@
|
26
|
+
def api_token?
|
27
|
+
!@api_token.nil?
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
|
32
|
-
grant_type: 'client_credentials',
|
33
|
-
client_id: application_id,
|
34
|
-
client_secret: application_secret
|
35
|
-
}
|
36
|
-
response.body[:data]
|
30
|
+
def debug?
|
31
|
+
!@debug.nil?
|
37
32
|
end
|
38
33
|
|
39
34
|
def setup_her
|
40
35
|
Her::API.setup url: base_uri do |c|
|
41
36
|
# Request
|
42
37
|
c.use BoletoSimples::Middleware::UserAgent
|
43
|
-
c.use
|
38
|
+
c.use BoletoSimples::Middleware::Bearer if api_token?
|
39
|
+
c.use BoletoSimples::Middleware::CustomHeaders
|
44
40
|
c.use Faraday::Request::Multipart
|
45
|
-
c.use Faraday::Request::UrlEncoded
|
46
41
|
c.use FaradayMiddleware::EncodeJson
|
47
|
-
c.use
|
42
|
+
c.use Her::Middleware::AcceptJSON
|
43
|
+
c.use Faraday::HttpCache, store: cache, serializer: Marshal unless cache.nil?
|
48
44
|
|
49
45
|
# Response
|
46
|
+
c.use BoletoSimples::Middleware::Debug if debug?
|
50
47
|
c.use BoletoSimples::Middleware::LastRequest
|
51
48
|
c.use BoletoSimples::Middleware::RaiseError
|
52
49
|
c.use Her::Middleware::DefaultParseJSON
|
53
50
|
|
54
51
|
# Adapter
|
55
|
-
c.
|
52
|
+
c.adapter Faraday::Adapter::NetHttp
|
56
53
|
end
|
57
54
|
|
58
55
|
# Because Her set the api on the moment module is included we need to call use_api again, after changing the configuration.
|
59
|
-
[BankBillet, BankBilletAccount, Customer, CustomerImport, CustomerSubscription,
|
60
|
-
|
56
|
+
[BankBillet, BankBilletAccount, Customer, CustomerImport, CustomerSubscription,
|
57
|
+
CustomerSubscriptionImport, Installment, Transaction, Webhook, Discharge,
|
58
|
+
Remittance, WebhookDelivery, Event, EmailDelivery, BankBilletDischarge,
|
59
|
+
BankBilletPayment, BankBilletRemittance, SmsDelivery].each do |klass|
|
61
60
|
klass.send(:use_api, Her::API.default_api)
|
62
61
|
end
|
63
62
|
end
|
64
|
-
|
65
63
|
end
|
66
|
-
|
67
64
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BoletoSimples
|
2
4
|
class LastRequest
|
3
|
-
attr_reader :body, :response_headers, :total, :ratelimit_limit, :ratelimit_remaining, :links
|
5
|
+
attr_reader :body, :request_headers, :response_headers, :total, :ratelimit_limit, :ratelimit_remaining, :links
|
4
6
|
|
5
7
|
def initialize(env)
|
6
8
|
@env = env
|
@@ -10,34 +12,39 @@ module BoletoSimples
|
|
10
12
|
@body ||= @env[:body][:data]
|
11
13
|
end
|
12
14
|
|
15
|
+
def request_headers
|
16
|
+
@request_headers ||= @env.request_headers
|
17
|
+
end
|
18
|
+
|
13
19
|
def response_headers
|
14
20
|
@response_headers ||= @env[:response_headers]
|
15
21
|
end
|
16
22
|
|
17
23
|
def total
|
18
|
-
@total ||= @env[:response_headers][
|
24
|
+
@total ||= @env[:response_headers]['total'].to_i
|
19
25
|
end
|
20
26
|
|
21
27
|
def ratelimit_limit
|
22
|
-
ratelimit_limit ||= @env[:response_headers][
|
28
|
+
ratelimit_limit ||= @env[:response_headers]['x-ratelimit-limit'].to_i
|
23
29
|
end
|
24
30
|
|
25
31
|
def ratelimit_remaining
|
26
|
-
@ratelimit_remaining ||= @env[:response_headers][
|
32
|
+
@ratelimit_remaining ||= @env[:response_headers]['x-ratelimit-remaining'].to_i
|
27
33
|
end
|
28
34
|
|
29
35
|
def links
|
30
36
|
return @links unless @links.nil?
|
31
|
-
|
37
|
+
|
38
|
+
link_header = @env[:response_headers]['link']
|
32
39
|
return {} if link_header.nil?
|
40
|
+
|
33
41
|
@links = {}
|
34
|
-
link_header.split(
|
35
|
-
key = /rel
|
36
|
-
value =
|
42
|
+
link_header.split(', ').each do |link|
|
43
|
+
key = /rel="(.*)"/.match(link)[1]
|
44
|
+
value = /<(.*)>/.match(link)[1]
|
37
45
|
@links[key] = value
|
38
46
|
end
|
39
47
|
@links.symbolize_keys!
|
40
48
|
end
|
41
|
-
|
42
49
|
end
|
43
|
-
end
|
50
|
+
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
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BoletoSimples
|
4
|
+
module Middleware
|
5
|
+
class Debug < Faraday::Response::Middleware
|
6
|
+
def initialize(app, logger = nil)
|
7
|
+
super(app)
|
8
|
+
@logger = logger || begin
|
9
|
+
require 'logger'
|
10
|
+
::Logger.new($stdout)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def on_complete(env)
|
15
|
+
@logger.info "\n::#{env[:method].upcase} #{env[:url]}"
|
16
|
+
@logger.info ' Request'
|
17
|
+
env[:request_headers].each do |key, value|
|
18
|
+
@logger.info " -- #{key}: #{value}"
|
19
|
+
end
|
20
|
+
@logger.info ' Response'
|
21
|
+
@logger.info " -- Status: #{env[:status]}"
|
22
|
+
env[:response_headers].each do |key, value|
|
23
|
+
@logger.info " -- #{key}: #{value}"
|
24
|
+
end
|
25
|
+
@logger.info ' Response body'
|
26
|
+
@logger.info " -- #{env[:body]} \n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
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
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BoletoSimples
|
2
4
|
class CustomerImport < BaseModel
|
3
|
-
collection_path
|
4
|
-
resource_path
|
5
|
+
collection_path 'imports/customers'
|
6
|
+
resource_path 'imports/customers/:id'
|
5
7
|
end
|
6
|
-
end
|
8
|
+
end
|
@@ -1,14 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BoletoSimples
|
2
4
|
class CustomerSubscription < BaseModel
|
3
|
-
|
4
|
-
def next_charge
|
5
|
-
self.class.request(:_method => :post, :_path => self.class.build_request_path('customer_subscriptions/:id/next_charge', {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_post :next_charge
|
13
6
|
end
|
14
7
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BoletoSimples
|
2
4
|
class CustomerSubscriptionImport < BaseModel
|
3
|
-
collection_path
|
4
|
-
resource_path
|
5
|
+
collection_path 'imports/customer_subscriptions'
|
6
|
+
resource_path 'imports/customer_subscriptions/:id'
|
5
7
|
end
|
6
|
-
end
|
8
|
+
end
|
@@ -1,14 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BoletoSimples
|
2
4
|
class Discharge < BaseModel
|
3
|
-
|
4
|
-
def pay_off
|
5
|
-
self.class.request(:_method => :put, :_path => self.class.build_request_path('discharges/:id/pay_off', {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_off
|
13
6
|
end
|
14
|
-
end
|
7
|
+
end
|