boletosimples 0.0.7 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/README.md +156 -3
- data/boletosimples.gemspec +9 -9
- data/lib/boletosimples.rb +38 -4
- data/lib/boletosimples/configuration.rb +69 -0
- data/lib/boletosimples/extra.rb +8 -0
- data/lib/boletosimples/last_request.rb +43 -0
- data/lib/boletosimples/middlewares/last_request.rb +9 -0
- data/lib/boletosimples/middlewares/raise_error.rb +11 -0
- data/lib/boletosimples/middlewares/user_agent.rb +10 -0
- data/lib/boletosimples/resources/bank_billet.rb +13 -0
- data/lib/boletosimples/resources/base_model.rb +8 -0
- data/lib/boletosimples/resources/customer.rb +4 -0
- data/lib/boletosimples/resources/partner/user.rb +7 -0
- data/lib/boletosimples/resources/transaction.rb +4 -0
- data/lib/boletosimples/response_error.rb +43 -0
- data/lib/boletosimples/version.rb +1 -1
- data/spec/boletosimples/configuration_spec.rb +84 -0
- data/spec/boletosimples/extra_spec.rb +31 -0
- data/spec/boletosimples/last_request_spec.rb +34 -0
- data/spec/boletosimples/resources/bank_billet_spec.rb +75 -0
- data/spec/boletosimples/resources/customer_spec.rb +66 -0
- data/spec/boletosimples/resources/partner/user_spec.rb +19 -0
- data/spec/boletosimples/resources/transactions_spec.rb +17 -0
- data/spec/fixtures/vcr_cassettes/configuration/client_credentials/invalid.yml +64 -0
- data/spec/fixtures/vcr_cassettes/configuration/client_credentials/valid.yml +56 -0
- data/spec/fixtures/vcr_cassettes/extra/userinfo/authenticated.yml +58 -0
- data/spec/fixtures/vcr_cassettes/extra/userinfo/not_authenticated.yml +54 -0
- data/spec/fixtures/vcr_cassettes/last_request/bank_billets.yml +129 -0
- data/spec/fixtures/vcr_cassettes/last_request/userinfo.yml +58 -0
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml +132 -0
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel.yml +125 -0
- data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_params.yml +61 -0
- data/spec/fixtures/vcr_cassettes/{BoletoSimples_Client/_cancel_bank_billet/already_canceled.yml → resources/bank_billet/create/invalid_root.yml} +24 -24
- data/spec/fixtures/vcr_cassettes/{BoletoSimples_Client/_create_bank_billet/with_valid_data.yml → resources/bank_billet/create/valid.yml} +32 -28
- data/spec/fixtures/vcr_cassettes/{BoletoSimples_Client/_bank_billet/existing_bank_billet.yml → resources/bank_billet/find.yml} +30 -28
- data/spec/fixtures/vcr_cassettes/resources/customer/all.yml +72 -0
- data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_params.yml +59 -0
- data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_root.yml +58 -0
- data/spec/fixtures/vcr_cassettes/{BoletoSimples_Client/_create_customer/with_valid_data.yml → resources/customer/create/valid.yml} +30 -26
- data/spec/fixtures/vcr_cassettes/resources/customer/find.yml +59 -0
- data/spec/fixtures/vcr_cassettes/resources/partner/user/create.yml +60 -0
- data/spec/fixtures/vcr_cassettes/resources/transaction/all.yml +62 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/support/vcr.rb +8 -0
- metadata +97 -80
- data/example/access_token_example.rb +0 -79
- data/example/oauth_example.rb +0 -126
- data/lib/boletosimples/client.rb +0 -100
- data/lib/boletosimples/oauth_client.rb +0 -74
- data/spec/boletosimples/client_spec.rb +0 -415
- data/spec/boletosimples/oauth_client_spec.rb +0 -17
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_bank_billet/not_found.yml +0 -44
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_bank_billets.yml +0 -63
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_cancel_bank_billet/with_invalid_bank_billet.yml +0 -54
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_cancel_bank_billet/with_valid_bank_billet.yml +0 -71
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_create_bank_billet/with_invalid_data.yml +0 -64
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_create_customer/with_invalid_data.yml +0 -59
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_customer/existing_customer.yml +0 -57
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_customer/not_found.yml +0 -58
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_customers.yml +0 -59
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_transactions.yml +0 -67
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/with_authentication.yml +0 -56
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/with_authentication/.yml +0 -56
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/without_authentication.yml +0 -54
- data/spec/fixtures/vcr_cassettes/BoletoSimples_Client/_userinfo/without_authentication/.yml +0 -54
- data/spec/fixtures/vcr_cassettes/BoletoSimples_OAuthClient/_userinfo/without_authentication/.yml +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 948e6f3aa087ac1903c87f91160c0f93e225dcea
|
4
|
+
data.tar.gz: 935cd49f3e6963721f5b02822441ee5921a83f7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a512a53c11957d7d8392da1ee15bc86ebe1253bf85d3ff010fbf8f05a14aeda732eabd69fd087b052f57ae98a0bf4dd0da830b2465f51d1f215b15e20019f919
|
7
|
+
data.tar.gz: 9df50c21b21b7a952816772b93ce48febe8128b81e922643743b676732dff346ba5f2a1ffe30525b53a79710b62a99b0469099eae342f3df9f07213697b0f595
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -14,8 +14,6 @@
|
|
14
14
|
|
15
15
|
Esta gem inclui todos os métodos disponíveis na [Boleto Simples JSON API](http://api.boletosimples.com.br).
|
16
16
|
|
17
|
-
Ela suporta Basic Auth e OAuth 2.0 para ações realizadas por parceiros.
|
18
|
-
|
19
17
|
## Instalação
|
20
18
|
|
21
19
|
Adicione a linha a baixo no seu Gemfile:
|
@@ -30,9 +28,164 @@ Ou instale você mesmo:
|
|
30
28
|
|
31
29
|
$ gem install boletosimples
|
32
30
|
|
31
|
+
## Configuração
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'boletosimples'
|
35
|
+
|
36
|
+
BoletoSimples.configure do |c|
|
37
|
+
c.environment = :production # defaut :sandbox
|
38
|
+
c.access_token = 'access-token'
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
### Variáveis de ambiente
|
43
|
+
|
44
|
+
Você também pode configurar as variáveis de ambiente a seguir e não será necessário chamar `BoletoSimples.configure`
|
45
|
+
|
46
|
+
```bash
|
47
|
+
ENV['BOLETOSIMPLES_ENV']
|
48
|
+
ENV['BOLETOSIMPLES_APP_ID']
|
49
|
+
ENV['BOLETOSIMPLES_APP_SECRET']
|
50
|
+
ENV['BOLETOSIMPLES_ACCESS_TOKEN']
|
51
|
+
```
|
52
|
+
|
53
|
+
### Configurando cache
|
54
|
+
|
55
|
+
É altamente recomendável utilizar o cache para evitar chegar no [limite de requisições](http://api.boletosimples.com.br/#limite-de-requisicoes)
|
56
|
+
|
57
|
+
Para isso recomendamos a utilização da gem [Dalli](https://github.com/mperham/dalli)
|
58
|
+
|
59
|
+
Exemplo:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
require 'dalli'
|
63
|
+
|
64
|
+
BoletoSimples.configure do |c|
|
65
|
+
c.cache = ActiveSupport::Cache.lookup_store(:dalli_store, ['localhost:11211'], namespace: 'boletosimples_client', compress: true)
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
33
69
|
## Exemplos
|
34
70
|
|
35
|
-
|
71
|
+
### Boletos Bancários
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# Criar um boleto
|
75
|
+
@bank_billet = BoletoSimples::BankBillet.create({
|
76
|
+
amount: 9.01,
|
77
|
+
description: 'Despesas do contrato 0012',
|
78
|
+
expire_at: '2014-01-01',
|
79
|
+
customer_address: 'Rua quinhentos',
|
80
|
+
customer_address_complement: 'Sala 4',
|
81
|
+
customer_address_number: '111',
|
82
|
+
customer_city_name: 'Rio de Janeiro',
|
83
|
+
customer_cnpj_cpf: '012.345.678-90',
|
84
|
+
customer_email: 'cliente@bom.com',
|
85
|
+
customer_neighborhood: 'Sao Francisco',
|
86
|
+
customer_person_name: 'Joao da Silva',
|
87
|
+
customer_person_type: 'individual',
|
88
|
+
customer_phone_number: '2112123434',
|
89
|
+
customer_state: 'RJ',
|
90
|
+
customer_zipcode: '12312-123',
|
91
|
+
notification_url: 'http://example.com.br/notify'
|
92
|
+
})
|
93
|
+
|
94
|
+
# Criar um novo boleto instanciando o objeto
|
95
|
+
@bank_billet = BoletoSimples::BankBillet.new(amount: 199.99, expire_at: '2020-01-01')
|
96
|
+
@bank_billet.description = 'Cobrança XPTO'
|
97
|
+
@bank_billet.save
|
98
|
+
|
99
|
+
# Mensagens de erro na criação do boleto
|
100
|
+
@bank_billet = BoletoSimples::BankBillet.create(amount: 199.99)
|
101
|
+
@bank_billet.response_errors
|
102
|
+
# {:expire_at=>["não pode ficar em branco", "não é uma data válida"], :customer_person_name=>["não pode ficar em branco"], :customer_cnpj_cpf=>["não pode ficar em branco", "não é um CPNJ ou CPF válido"], :description=>["não pode ficar em branco"], :customer_zipcode=>["não pode ficar em branco"]
|
103
|
+
|
104
|
+
# Pegar informações de um boleto
|
105
|
+
@bank_billet = BoletoSimples::BankBillet.find(1) # onde 1 é o id do boleto.
|
106
|
+
|
107
|
+
# Se o não for encontrado nenhum boleto com o id informado, uma exceção será levantada com a mensagem:
|
108
|
+
# Couldn't find BankBillet with 'id'=1
|
109
|
+
|
110
|
+
# Listar os boletos
|
111
|
+
@bank_billets = BoletoSimples::BankBillet.all(page: 1, per_page: 50)
|
112
|
+
@bank_billet.each do |bank_billet|
|
113
|
+
puts bank_billet.id
|
114
|
+
end
|
115
|
+
|
116
|
+
# Após realizar a chamada na listagem, você terá acesso aos seguintes dados:
|
117
|
+
|
118
|
+
BoletoSimples.last_request.total # número total de boletos
|
119
|
+
BoletoSimples.last_request.links[:first] # url da primeira página
|
120
|
+
BoletoSimples.last_request.links[:prev] # url da página anterior
|
121
|
+
BoletoSimples.last_request.links[:next] # url da próxima página
|
122
|
+
BoletoSimples.last_request.links[:last] # url da última página
|
123
|
+
|
124
|
+
# Cancelar um boleto
|
125
|
+
@bank_billet = BoletoSimples::BankBillet.find(1)
|
126
|
+
@bank_billet.cancel
|
127
|
+
|
128
|
+
```
|
129
|
+
|
130
|
+
### Clientes
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
# Criar um cliente
|
134
|
+
@customer = BoletoSimples::Customer.create({
|
135
|
+
person_name: "Joao da Silva",
|
136
|
+
cnpj_cpf: "012.345.678-90",
|
137
|
+
email: "cliente@bom.com",
|
138
|
+
address: "Rua quinhentos",
|
139
|
+
city_name: "Rio de Janeiro",
|
140
|
+
state: "RJ",
|
141
|
+
neighborhood: "bairro",
|
142
|
+
zipcode: "12312-123",
|
143
|
+
address_number: "111",
|
144
|
+
address_complement: "Sala 4",
|
145
|
+
phone_number: "2112123434"
|
146
|
+
})
|
147
|
+
|
148
|
+
# Mensagens de erro na criação do cliente
|
149
|
+
@customer = BoletoSimples::Customer.new(person_name: '')
|
150
|
+
@customer.response_errors
|
151
|
+
# {:person_name=>["não pode ficar em branco"], :cnpj_cpf=>["não pode ficar em branco"], :zipcode=>["não pode ficar em branco"]}
|
152
|
+
|
153
|
+
# Listar os clientes
|
154
|
+
@customers = BoletoSimples::Customer.all(page: 1, per_page: 50)
|
155
|
+
@customers.each do |customer|
|
156
|
+
puts customer.id
|
157
|
+
end
|
158
|
+
|
159
|
+
# Após realizar a chamada na listagem, você terá acesso aos seguintes dados:
|
160
|
+
|
161
|
+
BoletoSimples.last_request.total # número total de clientes
|
162
|
+
BoletoSimples.last_request.links[:first] # url da primeira página
|
163
|
+
BoletoSimples.last_request.links[:prev] # url da página anterior
|
164
|
+
BoletoSimples.last_request.links[:next] # url da próxima página
|
165
|
+
BoletoSimples.last_request.links[:last] # url da última página
|
166
|
+
|
167
|
+
# Atualizar um cliente
|
168
|
+
@customer = BoletoSimples::Customer.find(1)
|
169
|
+
@customer.person_name = 'Novo nome'
|
170
|
+
@customer.save
|
171
|
+
```
|
172
|
+
|
173
|
+
### Extrato
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
# Listar todas as transações
|
177
|
+
@transactions = BoletoSimples::Transaction.all
|
178
|
+
@transactions.each do |transaction|
|
179
|
+
puts transaction.id
|
180
|
+
end
|
181
|
+
```
|
182
|
+
|
183
|
+
### Extras
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
# Dados do usuário logado
|
187
|
+
@userinfo = BoletoSimples::Extra.userinfo
|
188
|
+
```
|
36
189
|
|
37
190
|
## OAuth 2.0 Authentication (para acessar as contas dos usuários)
|
38
191
|
|
data/boletosimples.gemspec
CHANGED
@@ -21,16 +21,16 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.required_ruby_version = '>= 1.9'
|
22
22
|
|
23
23
|
# Gems that must be intalled for boletosimples to work
|
24
|
-
gem.add_dependency '
|
25
|
-
gem.add_dependency '
|
26
|
-
gem.add_dependency '
|
24
|
+
gem.add_dependency 'her', '~> 0.7.3'
|
25
|
+
gem.add_dependency 'faraday_middleware', '~> 0.9.1'
|
26
|
+
gem.add_dependency 'faraday-http-cache', '~> 1.0.1'
|
27
27
|
|
28
28
|
# Gems that must be installed for boletosimples to compile and build
|
29
|
-
gem.add_development_dependency 'pry'
|
30
|
-
gem.add_development_dependency 'rspec', '~> 3.
|
29
|
+
gem.add_development_dependency 'pry', '~> 0.10.1'
|
30
|
+
gem.add_development_dependency 'rspec', '~> 3.2.0'
|
31
31
|
gem.add_development_dependency 'vcr', '~> 2.9'
|
32
|
-
gem.add_development_dependency 'webmock'
|
33
|
-
gem.add_development_dependency 'rake'
|
34
|
-
gem.add_development_dependency 'coveralls'
|
35
|
-
gem.add_development_dependency 'codeclimate-test-reporter'
|
32
|
+
gem.add_development_dependency 'webmock', '~> 1.20.4'
|
33
|
+
gem.add_development_dependency 'rake', '~> 10.4.2'
|
34
|
+
gem.add_development_dependency 'coveralls', '~> 0.7.11'
|
35
|
+
gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.7'
|
36
36
|
end
|
data/lib/boletosimples.rb
CHANGED
@@ -1,5 +1,39 @@
|
|
1
|
-
require '
|
1
|
+
require 'her'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'faraday-http-cache'
|
2
4
|
require 'boletosimples/version'
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
|
6
|
+
module BoletoSimples
|
7
|
+
autoload :Configuration, 'boletosimples/configuration'
|
8
|
+
autoload :Extra, 'boletosimples/extra'
|
9
|
+
autoload :ResponseError, 'boletosimples/response_error'
|
10
|
+
autoload :LastRequest, 'boletosimples/last_request'
|
11
|
+
|
12
|
+
autoload :BankBillet, 'boletosimples/resources/bank_billet'
|
13
|
+
autoload :Customer, 'boletosimples/resources/customer'
|
14
|
+
autoload :Transaction, 'boletosimples/resources/transaction'
|
15
|
+
autoload :BaseModel, 'boletosimples/resources/base_model'
|
16
|
+
|
17
|
+
module Partner
|
18
|
+
autoload :User, 'boletosimples/resources/partner/user'
|
19
|
+
end
|
20
|
+
|
21
|
+
module Middleware
|
22
|
+
autoload :UserAgent, 'boletosimples/middlewares/user_agent'
|
23
|
+
autoload :RaiseError, 'boletosimples/middlewares/raise_error'
|
24
|
+
autoload :LastRequest, 'boletosimples/middlewares/last_request'
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
attr_accessor :configuration, :last_request
|
29
|
+
|
30
|
+
def configure
|
31
|
+
@configuration = Configuration.new
|
32
|
+
yield(configuration) if block_given?
|
33
|
+
configuration.setup_her # after changing configuration gem her should be configured
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
BoletoSimples.configure
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module BoletoSimples
|
3
|
+
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :environment, :application_id, :application_secret, :access_token, :cache
|
6
|
+
|
7
|
+
|
8
|
+
BASE_URI = {
|
9
|
+
sandbox: 'https://sandbox.boletosimples.com.br/api/v1',
|
10
|
+
production: 'https://boletosimples.com.br/api/v1'
|
11
|
+
}
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@environment = (ENV['BOLETOSIMPLES_ENV'] || :sandbox).to_sym
|
15
|
+
@application_id = ENV['BOLETOSIMPLES_APP_ID']
|
16
|
+
@application_secret = ENV['BOLETOSIMPLES_APP_SECRET']
|
17
|
+
@access_token = ENV['BOLETOSIMPLES_ACCESS_TOKEN']
|
18
|
+
@cache = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def base_uri
|
22
|
+
BASE_URI[@environment]
|
23
|
+
end
|
24
|
+
|
25
|
+
def user_agent
|
26
|
+
"BoletoSimples Ruby Client v#{BoletoSimples::VERSION} (contato@boletosimples.com.br)"
|
27
|
+
end
|
28
|
+
|
29
|
+
def access_token?
|
30
|
+
!@access_token.nil?
|
31
|
+
end
|
32
|
+
|
33
|
+
def client_credentials
|
34
|
+
response = Her::API.default_api.connection.post 'oauth2/token', {
|
35
|
+
grant_type: 'client_credentials',
|
36
|
+
client_id: application_id,
|
37
|
+
client_secret: application_secret
|
38
|
+
}
|
39
|
+
response.body[:data]
|
40
|
+
end
|
41
|
+
|
42
|
+
def setup_her
|
43
|
+
Her::API.setup url: BoletoSimples.configuration.base_uri do |c|
|
44
|
+
# Request
|
45
|
+
c.use BoletoSimples::Middleware::UserAgent
|
46
|
+
c.use FaradayMiddleware::OAuth2, BoletoSimples.configuration.access_token if BoletoSimples.configuration.access_token?
|
47
|
+
c.use FaradayMiddleware::EncodeJson
|
48
|
+
if !BoletoSimples.configuration.cache.nil?
|
49
|
+
c.use Faraday::HttpCache, store: BoletoSimples.configuration.cache
|
50
|
+
end
|
51
|
+
|
52
|
+
# Response
|
53
|
+
c.use BoletoSimples::Middleware::LastRequest
|
54
|
+
c.use BoletoSimples::Middleware::RaiseError
|
55
|
+
c.use Her::Middleware::DefaultParseJSON
|
56
|
+
|
57
|
+
# Adapter
|
58
|
+
c.use Faraday::Adapter::NetHttp
|
59
|
+
end
|
60
|
+
|
61
|
+
# Because Her set the api on the moment module is included we need to call use_api again, after changing the configuration.
|
62
|
+
[BankBillet, Customer, Transaction, Partner::User].each do |klass|
|
63
|
+
klass.send(:use_api, Her::API.default_api)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module BoletoSimples
|
2
|
+
class LastRequest
|
3
|
+
attr_reader :body, :response_headers, :total, :ratelimit_limit, :ratelimit_remaining, :links
|
4
|
+
|
5
|
+
def initialize(env)
|
6
|
+
@env = env
|
7
|
+
end
|
8
|
+
|
9
|
+
def body
|
10
|
+
@body ||= @env[:body][:data]
|
11
|
+
end
|
12
|
+
|
13
|
+
def response_headers
|
14
|
+
@response_headers ||= @env[:response_headers]
|
15
|
+
end
|
16
|
+
|
17
|
+
def total
|
18
|
+
@total ||= @env[:response_headers]["total"].to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
def ratelimit_limit
|
22
|
+
ratelimit_limit ||= @env[:response_headers]["x-ratelimit-limit"].to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
def ratelimit_remaining
|
26
|
+
@ratelimit_remaining ||= @env[:response_headers]["x-ratelimit-remaining"].to_i
|
27
|
+
end
|
28
|
+
|
29
|
+
def links
|
30
|
+
return @links unless @links.nil?
|
31
|
+
link_header = @env[:response_headers]["link"]
|
32
|
+
return {} if link_header.nil?
|
33
|
+
@links = {}
|
34
|
+
link_header.split(", ").each do |link|
|
35
|
+
key = /rel=\"(.*)\"/.match(link)[1]
|
36
|
+
value = /\<(.*)\>/.match(link)[1]
|
37
|
+
@links[key] = value
|
38
|
+
end
|
39
|
+
@links.symbolize_keys!
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module BoletoSimples
|
2
|
+
module Middleware
|
3
|
+
class RaiseError < Faraday::Response::Middleware
|
4
|
+
def on_complete(env)
|
5
|
+
status = env[:status].to_i
|
6
|
+
klass = BoletoSimples::ResponseError
|
7
|
+
raise klass.new(env) if (400..599).include?(status) and env[:body][:data][:error]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module BoletoSimples
|
2
|
+
class BankBillet < BaseModel
|
3
|
+
|
4
|
+
def cancel
|
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
|
+
end
|
10
|
+
self
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|