boletosimples 0.4.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +34 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +9 -0
  5. data/.ruby-version +1 -1
  6. data/CHANGELOG.md +6 -14
  7. data/Gemfile +2 -0
  8. data/README.md +12 -54
  9. data/Rakefile +10 -0
  10. data/boletosimples.gemspec +21 -17
  11. data/lib/boletosimples.rb +10 -6
  12. data/lib/boletosimples/configuration.rb +17 -32
  13. data/lib/boletosimples/last_request.rb +12 -9
  14. data/lib/boletosimples/middlewares/bearer.rb +12 -0
  15. data/lib/boletosimples/middlewares/last_request.rb +3 -1
  16. data/lib/boletosimples/middlewares/raise_error.rb +9 -2
  17. data/lib/boletosimples/middlewares/user_agent.rb +3 -1
  18. data/lib/boletosimples/resources/bank_billet.rb +5 -11
  19. data/lib/boletosimples/resources/bank_billet_account.rb +3 -1
  20. data/lib/boletosimples/resources/bank_billet_discharge.rb +6 -0
  21. data/lib/boletosimples/resources/bank_billet_payment.rb +6 -0
  22. data/lib/boletosimples/resources/bank_billet_remittance.rb +6 -0
  23. data/lib/boletosimples/resources/base_model.rb +3 -1
  24. data/lib/boletosimples/resources/customer.rb +3 -1
  25. data/lib/boletosimples/resources/customer_import.rb +8 -0
  26. data/lib/boletosimples/resources/customer_subscription.rb +4 -11
  27. data/lib/boletosimples/resources/customer_subscription_import.rb +8 -0
  28. data/lib/boletosimples/resources/discharge.rb +4 -11
  29. data/lib/boletosimples/resources/email_delivery.rb +6 -0
  30. data/lib/boletosimples/resources/event.rb +3 -1
  31. data/lib/boletosimples/resources/installment.rb +3 -1
  32. data/lib/boletosimples/resources/remittance.rb +3 -1
  33. data/lib/boletosimples/resources/sms_delivery.rb +6 -0
  34. data/lib/boletosimples/resources/transaction.rb +3 -1
  35. data/lib/boletosimples/resources/webhook.rb +3 -1
  36. data/lib/boletosimples/resources/webhook_delivery.rb +3 -1
  37. data/lib/boletosimples/response_error.rb +8 -3
  38. data/lib/boletosimples/version.rb +3 -1
  39. data/spec/boletosimples/configuration_spec.rb +71 -83
  40. data/spec/boletosimples/last_request_spec.rb +16 -28
  41. data/spec/boletosimples/resources/bank_billet_account_spec.rb +57 -33
  42. data/spec/boletosimples/resources/bank_billet_discharge_spec.rb +12 -0
  43. data/spec/boletosimples/resources/bank_billet_payment_spec.rb +12 -0
  44. data/spec/boletosimples/resources/bank_billet_remittance_spec.rb +12 -0
  45. data/spec/boletosimples/resources/bank_billet_spec.rb +56 -42
  46. data/spec/boletosimples/resources/customer_import_spec.rb +67 -0
  47. data/spec/boletosimples/resources/customer_spec.rb +52 -39
  48. data/spec/boletosimples/resources/customer_subscription_import_spec.rb +67 -0
  49. data/spec/boletosimples/resources/customer_subscription_spec.rb +64 -30
  50. data/spec/boletosimples/resources/discharge_spec.rb +64 -11
  51. data/spec/boletosimples/resources/email_delivery_spec.rb +12 -0
  52. data/spec/boletosimples/resources/event_spec.rb +7 -12
  53. data/spec/boletosimples/resources/installment_spec.rb +61 -32
  54. data/spec/boletosimples/resources/remittance_spec.rb +7 -12
  55. data/spec/boletosimples/resources/sms_delivery_spec.rb +12 -0
  56. data/spec/boletosimples/resources/transactions_spec.rb +7 -12
  57. data/spec/boletosimples/resources/webhook_delivery_spec.rb +7 -12
  58. data/spec/boletosimples/resources/webhook_spec.rb +7 -12
  59. data/spec/fixtures/customer_imports.csv +1 -0
  60. data/spec/fixtures/customer_subscription_imports.csv +1 -0
  61. data/spec/fixtures/discharge.RET +3 -0
  62. data/spec/fixtures/vcr_cassettes/last_request/bank_billets.yml +536 -88
  63. data/spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml +537 -91
  64. data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/success.yml +34 -92
  65. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_params.yml +32 -20
  66. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_root.yml +28 -17
  67. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/valid.yml +43 -27
  68. data/spec/fixtures/vcr_cassettes/resources/bank_billet/duplicate/success.yml +83 -0
  69. data/spec/fixtures/vcr_cassettes/resources/bank_billet/find.yml +51 -27
  70. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/all.yml +131 -20
  71. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_params.yml +34 -20
  72. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_root.yml +30 -19
  73. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/valid.yml +41 -21
  74. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/find.yml +38 -18
  75. data/spec/fixtures/vcr_cassettes/resources/bank_billet_discharge/all.yml +97 -0
  76. data/spec/fixtures/vcr_cassettes/resources/bank_billet_payment/all.yml +75 -0
  77. data/spec/fixtures/vcr_cassettes/resources/bank_billet_remittance/all.yml +126 -0
  78. data/spec/fixtures/vcr_cassettes/resources/customer/all.yml +79 -32
  79. data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_params.yml +30 -17
  80. data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_root.yml +28 -17
  81. data/spec/fixtures/vcr_cassettes/resources/customer/create/valid.yml +33 -21
  82. data/spec/fixtures/vcr_cassettes/resources/customer/find.yml +33 -19
  83. data/spec/fixtures/vcr_cassettes/resources/customer_import/all.yml +74 -0
  84. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_params.yml +69 -0
  85. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_root.yml +69 -0
  86. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/valid.yml +76 -0
  87. data/spec/fixtures/vcr_cassettes/resources/customer_import/find.yml +71 -0
  88. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/all.yml +102 -52
  89. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_params.yml +40 -50
  90. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_root.yml +36 -48
  91. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/valid.yml +48 -53
  92. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/find.yml +44 -50
  93. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/next_charge.yml +77 -0
  94. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/all.yml +75 -0
  95. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_params.yml +69 -0
  96. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_root.yml +70 -0
  97. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/valid.yml +76 -0
  98. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/find.yml +71 -0
  99. data/spec/fixtures/vcr_cassettes/resources/discharge/all.yml +64 -33
  100. data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_params.yml +70 -0
  101. data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_root.yml +69 -0
  102. data/spec/fixtures/vcr_cassettes/resources/discharge/create/valid.yml +84 -0
  103. data/spec/fixtures/vcr_cassettes/resources/discharge/find.yml +71 -0
  104. data/spec/fixtures/vcr_cassettes/resources/email_delivery/all.yml +73 -0
  105. data/spec/fixtures/vcr_cassettes/resources/event/all.yml +490 -166
  106. data/spec/fixtures/vcr_cassettes/resources/installment/all.yml +418 -52
  107. data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_params.yml +41 -52
  108. data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_root.yml +36 -48
  109. data/spec/fixtures/vcr_cassettes/resources/installment/create/valid.yml +48 -53
  110. data/spec/fixtures/vcr_cassettes/resources/installment/find.yml +44 -52
  111. data/spec/fixtures/vcr_cassettes/resources/remittance/all.yml +53 -33
  112. data/spec/fixtures/vcr_cassettes/resources/sns_delivery/all.yml +73 -0
  113. data/spec/fixtures/vcr_cassettes/resources/transaction/all.yml +34 -22
  114. data/spec/fixtures/vcr_cassettes/resources/web_hook/all.yml +42 -33
  115. data/spec/fixtures/vcr_cassettes/resources/webhook_delivery/all.yml +1232 -54
  116. data/spec/spec_helper.rb +3 -20
  117. data/spec/support/stub_env.rb +7 -0
  118. data/spec/support/vcr.rb +3 -4
  119. metadata +181 -77
  120. data/.coveralls.yml +0 -2
  121. data/.ruby-gemset +0 -1
  122. data/.travis.yml +0 -11
  123. data/lib/boletosimples/extra.rb +0 -8
  124. data/lib/boletosimples/resources/partner/user.rb +0 -7
  125. data/lib/oauth2_patch.rb +0 -24
  126. data/spec/boletosimples/extra_spec.rb +0 -31
  127. data/spec/boletosimples/resources/partner/user_spec.rb +0 -19
  128. data/spec/fixtures/vcr_cassettes/configuration/client_credentials/invalid.yml +0 -64
  129. data/spec/fixtures/vcr_cassettes/configuration/client_credentials/valid.yml +0 -56
  130. data/spec/fixtures/vcr_cassettes/extra/userinfo/authenticated.yml +0 -58
  131. data/spec/fixtures/vcr_cassettes/extra/userinfo/not_authenticated.yml +0 -54
  132. data/spec/fixtures/vcr_cassettes/last_request/userinfo.yml +0 -58
  133. data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/failure.yml +0 -118
  134. data/spec/fixtures/vcr_cassettes/resources/partner/user/create.yml +0 -60
  135. data/spec/spec.opts +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 490d1c76e70d03fec1a8578e593b6a18e6c58f1e
4
- data.tar.gz: ffc415cf01929b2237ce2dc928460973cda9516c
2
+ SHA256:
3
+ metadata.gz: '080a1d5f5d9ba832ed3dd093f291dbeb217b732eba56d3713932917ae91534a0'
4
+ data.tar.gz: 954683fba1d52eca0c0831e46828caeecc57ab04b250ab5674433371fb77083d
5
5
  SHA512:
6
- metadata.gz: 9bd04063532e772ab874480ce21af8c8a6108b2649857062ea4aed159586078a96c76b492c03412c099d025fd1d9812745f5fea3c6440f4021a8b03cda1b8125
7
- data.tar.gz: c6aaa930072ad9c2d954c5b5f400496aaba2ee25426f8b999634db769526080f8d5becdbc76b4d64168cb7f34a791e96d9911ded6a7ccae96aa14860f33ed541
6
+ metadata.gz: 1a224228c2735cf16331fba27644c75eb0f38904f1cdc39a0b15209063a8f9a0250438231449e28dee0be4d39e8c84bd1a7607623c5e1aa018e35c91c6db7656
7
+ data.tar.gz: fe49d834e95ef86f2b38362fe15c22e592d617b9f3a0d34e00b1b0f71bfec039f8f8d9e029ac77819a70f59a037018b4d38c79372b57a7cf9b658477236cabe3
@@ -0,0 +1,34 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [master]
13
+ pull_request:
14
+ branches: [master]
15
+
16
+ jobs:
17
+ test:
18
+ runs-on: ubuntu-latest
19
+ name: Test against Ruby ${{ matrix.ruby-version }}
20
+ strategy:
21
+ matrix:
22
+ ruby-version: [2.4, 2.5, 2.6, 2.7, 3.0]
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+
27
+ - name: Set up Ruby
28
+ uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby-version }}
31
+ bundler-cache: true # runs 'bundle install' and caches installed
32
+
33
+ - name: Run tests
34
+ run: bundle exec rake
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format Fuubar
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,9 @@
1
+ require:
2
+ - rubocop-performance
3
+ - "test_prof/rubocop"
4
+ - rubocop-rspec
5
+ - rubocop-rake
6
+
7
+ AllCops:
8
+ NewCops: enable
9
+ TargetRubyVersion: 2.7
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.1
1
+ 3.0.1
data/CHANGELOG.md CHANGED
@@ -1,18 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ## 0.2.2
3
+ ## 1.0.0
4
4
 
5
- ### features
5
+ ### Breaking changes
6
6
 
7
- - Add BankBilletAccount resource
8
-
9
- ## 0.1.1
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/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in pah.gemspec
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
- [![Build Status](http://img.shields.io/travis/BoletoSimples/boletosimples-ruby.svg)][travis]
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
- c.access_token = 'access-token'
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['BOLETOSIMPLES_APP_ID']
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/Rakefile CHANGED
@@ -1,6 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
8
  task default: :spec
9
+
10
+ task :console do
11
+ require 'irb'
12
+ require 'irb/completion'
13
+
14
+ ARGV.clear
15
+ IRB.start
16
+ end
@@ -1,6 +1,6 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'boletosimples/version'
6
6
 
@@ -13,25 +13,29 @@ Gem::Specification.new do |gem|
13
13
  gem.summary = 'Boleto Simples API wrapper.'
14
14
  gem.homepage = 'https://github.com/BoletoSimples/boletosimples-ruby'
15
15
 
16
- gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
- gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
18
- gem.test_files = gem.files.grep(/^(test|spec|features)\//)
19
- gem.require_paths = ['lib']
16
+ gem.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(spec|features)/})
18
+ end
20
19
 
21
- gem.required_ruby_version = '>= 1.9'
20
+ gem.test_files = `git ls-files -- {spec,features}/*`.split("\n")
21
+ gem.require_paths = ['lib']
22
22
 
23
23
  # Gems that must be intalled for boletosimples to work
24
- gem.add_dependency 'her', '~> 0.8.1'
25
- gem.add_dependency 'faraday_middleware', '~> 0.10.0'
26
- gem.add_dependency 'faraday-http-cache', '~> 1.3.1'
24
+ gem.add_dependency 'faraday-http-cache', '~> 2.2.0'
25
+ gem.add_dependency 'faraday_middleware', '~> 0.14'
26
+ gem.add_dependency 'her', '~> 1.1'
27
27
 
28
28
  # Gems that must be installed for boletosimples to compile and build
29
- gem.add_development_dependency 'pry', '~> 0.10.1'
30
- gem.add_development_dependency 'rspec', '~> 3.5.0'
31
- gem.add_development_dependency 'vcr', '~> 3.0'
32
- gem.add_development_dependency 'webmock', '~> 2.1.0'
33
- gem.add_development_dependency 'rake', '~> 11.2.2'
34
- gem.add_development_dependency 'coveralls', '~> 0.8.2'
35
- gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.6.0'
29
+ gem.add_development_dependency 'fuubar'
30
+ gem.add_development_dependency 'rake'
31
+ gem.add_development_dependency 'rspec'
36
32
  gem.add_development_dependency 'rubocop'
33
+ gem.add_development_dependency 'rubocop-performance'
34
+ gem.add_development_dependency 'rubocop-rake'
35
+ gem.add_development_dependency 'rubocop-rspec'
36
+ gem.add_development_dependency 'solargraph'
37
+ gem.add_development_dependency 'stub_env'
38
+ gem.add_development_dependency 'test-prof'
39
+ gem.add_development_dependency 'vcr'
40
+ gem.add_development_dependency 'webmock'
37
41
  end
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
- # encoding: utf-8
2
- module BoletoSimples
1
+ # frozen_string_literal: true
3
2
 
3
+ module BoletoSimples
4
4
  class Configuration
5
- attr_accessor :environment, :application_id, :application_secret, :access_token, :cache
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
- @application_id = ENV['BOLETOSIMPLES_APP_ID']
17
- @application_secret = ENV['BOLETOSIMPLES_APP_SECRET']
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 user_agent
27
- "BoletoSimples Ruby Client v#{BoletoSimples::VERSION} (contato@boletosimples.com.br)"
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: BoletoSimples.configuration.base_uri do |c|
29
+ Her::API.setup url: base_uri do |c|
45
30
  # Request
46
31
  c.use BoletoSimples::Middleware::UserAgent
47
- c.use FaradayMiddleware::OAuth2, BoletoSimples.configuration.access_token if BoletoSimples.configuration.access_token?
32
+ c.use BoletoSimples::Middleware::Bearer if api_token?
33
+ c.use Faraday::Request::Multipart
48
34
  c.use FaradayMiddleware::EncodeJson
49
- if !BoletoSimples.configuration.cache.nil?
50
- c.use Faraday::HttpCache, store: BoletoSimples.configuration.cache
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
@@ -60,12 +45,12 @@ module BoletoSimples
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, CustomerSubscription, Installment, Transaction, Partner::User,
64
- Webhook, Discharge, Remittance, WebhookDelivery, Event].each do |klass|
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]["total"].to_i
20
+ @total ||= @env[:response_headers]['total'].to_i
19
21
  end
20
22
 
21
23
  def ratelimit_limit
22
- ratelimit_limit ||= @env[:response_headers]["x-ratelimit-limit"].to_i
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]["x-ratelimit-remaining"].to_i
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
- link_header = @env[:response_headers]["link"]
33
+
34
+ link_header = @env[:response_headers]['link']
32
35
  return {} if link_header.nil?
36
+
33
37
  @links = {}
34
- link_header.split(", ").each do |link|
35
- key = /rel=\"(.*)\"/.match(link)[1]
36
- value = /\<(.*)\>/.match(link)[1]
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