boletosimples 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +11 -8
- data/lib/boletosimples/configuration.rb +10 -4
- data/lib/boletosimples/middlewares/debug.rb +30 -0
- data/lib/boletosimples/response_error.rb +2 -2
- data/lib/boletosimples/version.rb +1 -1
- data/lib/boletosimples.rb +1 -0
- data/spec/boletosimples/configuration_spec.rb +3 -3
- data/spec/boletosimples/resources/bank_billet_spec.rb +2 -2
- data/spec/boletosimples/resources/customer_spec.rb +9 -4
- data/spec/boletosimples/resources/customer_subscription_spec.rb +1 -1
- data/spec/boletosimples/resources/installment_spec.rb +1 -1
- data/spec/fixtures/vcr_cassettes/last_request/bank_billets.yml +386 -520
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml +78 -522
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/success.yml +30 -12
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_params.yml +32 -16
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_root.yml +31 -15
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/valid.yml +42 -28
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/duplicate/success.yml +41 -27
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/find.yml +46 -31
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/all.yml +47 -103
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_params.yml +31 -15
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_root.yml +31 -15
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/valid.yml +35 -19
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/find.yml +35 -19
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_discharge/all.yml +35 -41
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_payment/all.yml +73 -72
- data/spec/fixtures/vcr_cassettes/resources/bank_billet_remittance/all.yml +39 -70
- data/spec/fixtures/vcr_cassettes/resources/customer/all.yml +111 -56
- data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_params.yml +35 -19
- data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_root.yml +35 -16
- data/spec/fixtures/vcr_cassettes/resources/customer/create/valid.yml +37 -21
- data/spec/fixtures/vcr_cassettes/resources/customer/find.yml +36 -20
- data/spec/fixtures/vcr_cassettes/resources/customer_import/all.yml +34 -18
- data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_params.yml +31 -15
- data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_root.yml +31 -15
- data/spec/fixtures/vcr_cassettes/resources/customer_import/create/valid.yml +36 -20
- data/spec/fixtures/vcr_cassettes/resources/customer_import/find.yml +34 -18
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/all.yml +35 -71
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_params.yml +32 -16
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_root.yml +31 -15
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/valid.yml +35 -19
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/find.yml +36 -20
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription/next_charge.yml +36 -20
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/all.yml +34 -19
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_params.yml +31 -15
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_root.yml +31 -15
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/valid.yml +36 -20
- data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/find.yml +34 -18
- data/spec/fixtures/vcr_cassettes/resources/discharge/all.yml +37 -39
- data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_params.yml +31 -15
- data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_root.yml +31 -15
- data/spec/fixtures/vcr_cassettes/resources/discharge/create/valid.yml +37 -21
- data/spec/fixtures/vcr_cassettes/resources/discharge/find.yml +36 -18
- data/spec/fixtures/vcr_cassettes/resources/email_delivery/all.yml +1 -1
- data/spec/fixtures/vcr_cassettes/resources/event/all.yml +267 -432
- data/spec/fixtures/vcr_cassettes/resources/installment/all.yml +71 -375
- data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_params.yml +32 -16
- data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_root.yml +31 -15
- data/spec/fixtures/vcr_cassettes/resources/installment/create/valid.yml +35 -19
- data/spec/fixtures/vcr_cassettes/resources/installment/find.yml +59 -19
- data/spec/fixtures/vcr_cassettes/resources/remittance/all.yml +82 -81
- data/spec/fixtures/vcr_cassettes/resources/sns_delivery/all.yml +31 -15
- data/spec/fixtures/vcr_cassettes/resources/transaction/all.yml +72 -71
- data/spec/fixtures/vcr_cassettes/resources/web_hook/all.yml +33 -17
- data/spec/fixtures/vcr_cassettes/resources/webhook_delivery/all.yml +2657 -1206
- metadata +6 -186
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45f7d3c3d88c50c61728838d4c3b1e3664c8dd555cadb1d57379220d51aaba9a
|
4
|
+
data.tar.gz: ea7d7fc35cb62433fc8fb7da44d01ff29d1a340f26c9f882c1ad91c4e3687b37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d22dd9edf36f28e3e0caf282a7ce20fc75a4652cdbe1270f66708912f17b35b6a6e17c18c9aac1f3c38f7c8e8de08b4951f9338e5828a158664731ce4a49c35
|
7
|
+
data.tar.gz: 3b3f5acf48399f3bf6964d1bd91c3208900fbc295f00b1755bf38435b4f6a1630e9247c84340eead8adef2b75ccc527bfccb57b8b8ea561d3a3337fa4a4ad1fe
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2.0.0
|
4
|
+
|
5
|
+
### Changes
|
6
|
+
|
7
|
+
- Update URLs based on new API: https://developers.kobana.com.br/reference/endpoints-1
|
8
|
+
|
9
|
+
## 1.0.4
|
10
|
+
|
11
|
+
### Changes
|
12
|
+
|
13
|
+
- Fix cache
|
14
|
+
|
15
|
+
## 1.0.3
|
16
|
+
|
17
|
+
### Changes
|
18
|
+
|
19
|
+
- Add debug option
|
20
|
+
|
3
21
|
## 1.0.0
|
4
22
|
|
5
23
|
### Breaking changes
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
[gem]: https://rubygems.org/gems/boletosimples
|
7
7
|
|
8
|
-
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).
|
9
9
|
|
10
10
|
## Instalação
|
11
11
|
|
@@ -23,17 +23,18 @@ Ou instale você mesmo:
|
|
23
23
|
|
24
24
|
## Configuração
|
25
25
|
|
26
|
-
Saiba mais sobre o [Token de API ](https://
|
26
|
+
Saiba mais sobre o [Token de API ](https://developers.kobana.com.br/reference/token-de-acesso)
|
27
27
|
|
28
28
|
```ruby
|
29
29
|
require 'boletosimples'
|
30
30
|
|
31
31
|
BoletoSimples.configure do |c|
|
32
32
|
c.environment = :production # defaut :sandbox
|
33
|
-
# production - https://
|
34
|
-
# sandbox - https://sandbox.
|
33
|
+
# production - https://app.kobana.com.br/conta/api/tokens
|
34
|
+
# sandbox - https://app-sandbox.kobana.com.br/conta/api/tokens
|
35
35
|
c.api_token = 'api-token'
|
36
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
|
37
38
|
end
|
38
39
|
```
|
39
40
|
|
@@ -44,11 +45,12 @@ Você também pode configurar as variáveis de ambiente a seguir e não será ne
|
|
44
45
|
```bash
|
45
46
|
ENV['BOLETOSIMPLES_ENV']
|
46
47
|
ENV['BOLETOSIMPLES_API_TOKEN']
|
48
|
+
ENV['BOLETOSIMPLES_DEBUG']
|
47
49
|
```
|
48
50
|
|
49
51
|
### Configurando cache
|
50
52
|
|
51
|
-
É altamente recomendável utilizar o cache para evitar chegar no [limite de requisições](
|
53
|
+
É altamente recomendável utilizar o cache para evitar chegar no [limite de requisições](https://developers.kobana.com.br/reference/limite-de-requisições)
|
52
54
|
|
53
55
|
Para isso recomendamos a utilização da gem [Dalli](https://github.com/mperham/dalli)
|
54
56
|
|
@@ -58,7 +60,9 @@ Exemplo:
|
|
58
60
|
require 'dalli'
|
59
61
|
|
60
62
|
BoletoSimples.configure do |c|
|
61
|
-
c.cache = ActiveSupport::Cache.lookup_store(:
|
63
|
+
c.cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, ['localhost:11211'],
|
64
|
+
namespace: 'boletosimples_client',
|
65
|
+
compress: true)
|
62
66
|
end
|
63
67
|
```
|
64
68
|
|
@@ -109,8 +113,7 @@ Exemplo:
|
|
109
113
|
end
|
110
114
|
|
111
115
|
# Cancelar um boleto
|
112
|
-
@bank_billet = BoletoSimples::BankBillet.
|
113
|
-
@bank_billet.cancel
|
116
|
+
@bank_billet = BoletoSimples::BankBillet.cancel(id: 1)
|
114
117
|
|
115
118
|
```
|
116
119
|
|
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
module BoletoSimples
|
4
4
|
class Configuration
|
5
|
-
attr_accessor :environment, :cache, :user_agent, :api_token
|
5
|
+
attr_accessor :environment, :cache, :user_agent, :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
|
|
@@ -15,6 +15,7 @@ module BoletoSimples
|
|
15
15
|
@api_token = ENV['BOLETOSIMPLES_API_TOKEN']
|
16
16
|
@user_agent = ENV['BOLETOSIMPLES_USER_AGENT']
|
17
17
|
@cache = nil
|
18
|
+
@debug = ENV['BOLETOSIMPLES_DEBUG']
|
18
19
|
end
|
19
20
|
|
20
21
|
def base_uri
|
@@ -25,6 +26,10 @@ module BoletoSimples
|
|
25
26
|
!@api_token.nil?
|
26
27
|
end
|
27
28
|
|
29
|
+
def debug?
|
30
|
+
!@debug.nil?
|
31
|
+
end
|
32
|
+
|
28
33
|
def setup_her
|
29
34
|
Her::API.setup url: base_uri do |c|
|
30
35
|
# Request
|
@@ -33,9 +38,10 @@ module BoletoSimples
|
|
33
38
|
c.use Faraday::Request::Multipart
|
34
39
|
c.use FaradayMiddleware::EncodeJson
|
35
40
|
c.use Her::Middleware::AcceptJSON
|
36
|
-
c.use Faraday::HttpCache, store: cache unless cache.nil?
|
41
|
+
c.use Faraday::HttpCache, store: cache, serializer: Marshal unless cache.nil?
|
37
42
|
|
38
43
|
# Response
|
44
|
+
c.use BoletoSimples::Middleware::Debug if debug?
|
39
45
|
c.use BoletoSimples::Middleware::LastRequest
|
40
46
|
c.use BoletoSimples::Middleware::RaiseError
|
41
47
|
c.use Her::Middleware::DefaultParseJSON
|
@@ -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
|
@@ -9,14 +9,14 @@ module BoletoSimples
|
|
9
9
|
# Examples:
|
10
10
|
#
|
11
11
|
# BoletoSimples::BankBillet.all
|
12
|
-
# BoletoSimples::ResponseError: 401 POST https://sandbox.
|
12
|
+
# BoletoSimples::ResponseError: 401 POST https://api-sandbox.kobana.com.br/v1/bank_billets
|
13
13
|
#
|
14
14
|
# begin
|
15
15
|
# BoletoSimples::BankBillet.all
|
16
16
|
# rescue BoletoSimples::ResponseError => response
|
17
17
|
# response.status # => 401
|
18
18
|
# response.method # => "GET"
|
19
|
-
# response.url # => "https://sandbox.
|
19
|
+
# response.url # => "https://api-sandbox.kobana.com.br/v1/bank_billets"
|
20
20
|
# response.body # => "{"error":"Você precisa se logar ou registrar antes de prosseguir."}"
|
21
21
|
# response.error_message # => "Você precisa se logar ou registrar antes de prosseguir."
|
22
22
|
# end
|
data/lib/boletosimples.rb
CHANGED
@@ -34,6 +34,7 @@ module BoletoSimples
|
|
34
34
|
autoload :UserAgent, 'boletosimples/middlewares/user_agent'
|
35
35
|
autoload :RaiseError, 'boletosimples/middlewares/raise_error'
|
36
36
|
autoload :LastRequest, 'boletosimples/middlewares/last_request'
|
37
|
+
autoload :Debug, 'boletosimples/middlewares/debug'
|
37
38
|
autoload :Bearer, 'boletosimples/middlewares/bearer'
|
38
39
|
end
|
39
40
|
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
# it do
|
16
16
|
# expect(subject.environment).to eq(:sandbox)
|
17
|
-
# expect(subject.base_uri).to eq('https://sandbox.
|
17
|
+
# expect(subject.base_uri).to eq('https://api-sandbox.kobana.com.br/v1')
|
18
18
|
# expect(subject.cache).to be_nil
|
19
19
|
# expect(subject.user_agent).to be_nil
|
20
20
|
# end
|
@@ -31,7 +31,7 @@
|
|
31
31
|
|
32
32
|
# it do
|
33
33
|
# expect(subject.environment).to eq(:production)
|
34
|
-
# expect(subject.base_uri).to eq('https://
|
34
|
+
# expect(subject.base_uri).to eq('https://api.kobana.com.br/v1')
|
35
35
|
# expect(subject.user_agent).to eq('email@minhaempresa.com.br')
|
36
36
|
# end
|
37
37
|
|
@@ -59,7 +59,7 @@
|
|
59
59
|
# it do
|
60
60
|
# expect(subject.environment).to eq(:production)
|
61
61
|
# expect(subject.user_agent).to eq('Meu agent')
|
62
|
-
# expect(subject.base_uri).to eq('https://
|
62
|
+
# expect(subject.base_uri).to eq('https://api.kobana.com.br/v1')
|
63
63
|
# end
|
64
64
|
|
65
65
|
# describe 'cache' do
|
@@ -10,7 +10,7 @@ RSpec.describe BoletoSimples::BankBillet do
|
|
10
10
|
@bank_billet = described_class.create(
|
11
11
|
amount: 9.01,
|
12
12
|
description: 'Despesas do contrato 0012',
|
13
|
-
expire_at: '
|
13
|
+
expire_at: '2024-01-01',
|
14
14
|
customer_address: 'Rua quinhentos',
|
15
15
|
customer_address_complement: 'Sala 4',
|
16
16
|
customer_address_number: '111',
|
@@ -60,7 +60,7 @@ RSpec.describe BoletoSimples::BankBillet do
|
|
60
60
|
|
61
61
|
it {
|
62
62
|
expect(subject.response_errors).to eq({ customer_person_name: ['não pode ficar em branco'],
|
63
|
-
customer_cnpj_cpf: ['não
|
63
|
+
customer_cnpj_cpf: ['não é um CNPJ ou CPF válido'],
|
64
64
|
customer_zipcode: ['não pode ficar em branco'],
|
65
65
|
expire_at: ['não pode ficar em branco', 'não é uma data válida'],
|
66
66
|
customer_address: ['não pode ficar em branco'],
|
@@ -9,7 +9,7 @@ RSpec.describe BoletoSimples::Customer do
|
|
9
9
|
VCR.use_cassette('resources/customer/create/valid') do
|
10
10
|
@customer = described_class.create(
|
11
11
|
person_name: 'Maria José',
|
12
|
-
cnpj_cpf: '
|
12
|
+
cnpj_cpf: '84.232.027/0001-08',
|
13
13
|
email: 'cliente@example.com',
|
14
14
|
address: 'Rua quinhentos',
|
15
15
|
city_name: 'Rio de Janeiro',
|
@@ -42,8 +42,13 @@ RSpec.describe BoletoSimples::Customer do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it {
|
45
|
-
expect(subject.response_errors).to eq(
|
46
|
-
|
45
|
+
expect(subject.response_errors).to eq({ address: ['não pode ficar em branco'],
|
46
|
+
city_name: ['não pode ficar em branco'],
|
47
|
+
cnpj_cpf: ['não é um CNPJ ou CPF válido'],
|
48
|
+
neighborhood: ['não pode ficar em branco'],
|
49
|
+
person_name: ['não pode ficar em branco'],
|
50
|
+
state: ['não está incluído na lista'],
|
51
|
+
zipcode: ['não pode ficar em branco'] })
|
47
52
|
}
|
48
53
|
end
|
49
54
|
|
@@ -56,7 +61,7 @@ RSpec.describe BoletoSimples::Customer do
|
|
56
61
|
|
57
62
|
it {
|
58
63
|
expect(subject.response_errors).to eq({ person_name: ['não pode ficar em branco'],
|
59
|
-
cnpj_cpf: ['não
|
64
|
+
cnpj_cpf: ['não é um CNPJ ou CPF válido'], zipcode: ['não pode ficar em branco'],
|
60
65
|
address: ['não pode ficar em branco'], neighborhood: ['não pode ficar em branco'],
|
61
66
|
city_name: ['não pode ficar em branco'], state: ['não está incluído na lista'] })
|
62
67
|
}
|
@@ -61,7 +61,7 @@ RSpec.describe BoletoSimples::CustomerSubscription do
|
|
61
61
|
|
62
62
|
it {
|
63
63
|
expect(subject.response_errors).to eq({ customer_person_name: ['não pode ficar em branco'],
|
64
|
-
customer_cnpj_cpf: ['não
|
64
|
+
customer_cnpj_cpf: ['não é um CNPJ ou CPF válido'],
|
65
65
|
customer_zipcode: ['não pode ficar em branco'],
|
66
66
|
amount: ['não pode ficar em branco'],
|
67
67
|
customer_address: ['não pode ficar em branco'],
|
@@ -62,7 +62,7 @@ RSpec.describe BoletoSimples::Installment do
|
|
62
62
|
|
63
63
|
it {
|
64
64
|
expect(subject.response_errors).to eq({ customer_person_name: ['não pode ficar em branco'],
|
65
|
-
customer_cnpj_cpf: ['não
|
65
|
+
customer_cnpj_cpf: ['não é um CNPJ ou CPF válido'],
|
66
66
|
customer_zipcode: ['não pode ficar em branco'],
|
67
67
|
total: ['não pode ficar em branco', 'não é um número'],
|
68
68
|
start_at: ['não pode ficar em branco'],
|