boletosimples 0.6.0 → 1.0.1

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.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  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 -20
  7. data/Gemfile +2 -0
  8. data/README.md +12 -54
  9. data/Rakefile +3 -1
  10. data/boletosimples.gemspec +14 -11
  11. data/lib/boletosimples.rb +4 -6
  12. data/lib/boletosimples/configuration.rb +14 -25
  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 +3 -1
  21. data/lib/boletosimples/resources/bank_billet_payment.rb +3 -1
  22. data/lib/boletosimples/resources/bank_billet_remittance.rb +3 -1
  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 +5 -3
  26. data/lib/boletosimples/resources/customer_subscription.rb +3 -10
  27. data/lib/boletosimples/resources/customer_subscription_import.rb +5 -3
  28. data/lib/boletosimples/resources/discharge.rb +4 -11
  29. data/lib/boletosimples/resources/email_delivery.rb +3 -1
  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 -101
  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 +7 -12
  43. data/spec/boletosimples/resources/bank_billet_payment_spec.rb +7 -12
  44. data/spec/boletosimples/resources/bank_billet_remittance_spec.rb +7 -12
  45. data/spec/boletosimples/resources/bank_billet_spec.rb +56 -42
  46. data/spec/boletosimples/resources/customer_import_spec.rb +41 -30
  47. data/spec/boletosimples/resources/customer_spec.rb +52 -39
  48. data/spec/boletosimples/resources/customer_subscription_import_spec.rb +41 -30
  49. data/spec/boletosimples/resources/customer_subscription_spec.rb +61 -33
  50. data/spec/boletosimples/resources/discharge_spec.rb +64 -11
  51. data/spec/boletosimples/resources/email_delivery_spec.rb +6 -11
  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/discharge.RET +3 -0
  60. data/spec/fixtures/vcr_cassettes/last_request/bank_billets.yml +536 -88
  61. data/spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml +537 -91
  62. data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/success.yml +34 -92
  63. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_params.yml +32 -20
  64. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_root.yml +28 -17
  65. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/valid.yml +43 -27
  66. data/spec/fixtures/vcr_cassettes/resources/bank_billet/duplicate/success.yml +83 -0
  67. data/spec/fixtures/vcr_cassettes/resources/bank_billet/find.yml +51 -27
  68. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/all.yml +131 -20
  69. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_params.yml +34 -20
  70. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_root.yml +30 -19
  71. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/valid.yml +41 -21
  72. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/find.yml +38 -18
  73. data/spec/fixtures/vcr_cassettes/resources/bank_billet_discharge/all.yml +66 -47
  74. data/spec/fixtures/vcr_cassettes/resources/bank_billet_payment/all.yml +44 -42
  75. data/spec/fixtures/vcr_cassettes/resources/bank_billet_remittance/all.yml +95 -48
  76. data/spec/fixtures/vcr_cassettes/resources/customer/all.yml +79 -32
  77. data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_params.yml +30 -17
  78. data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_root.yml +28 -17
  79. data/spec/fixtures/vcr_cassettes/resources/customer/create/valid.yml +33 -21
  80. data/spec/fixtures/vcr_cassettes/resources/customer/find.yml +33 -19
  81. data/spec/fixtures/vcr_cassettes/resources/customer_import/all.yml +43 -60
  82. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_params.yml +37 -51
  83. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_root.yml +38 -52
  84. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/valid.yml +43 -68
  85. data/spec/fixtures/vcr_cassettes/resources/customer_import/find.yml +40 -54
  86. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/all.yml +102 -52
  87. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_params.yml +40 -50
  88. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_root.yml +36 -48
  89. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/valid.yml +48 -53
  90. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/find.yml +44 -50
  91. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/next_charge.yml +45 -133
  92. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/all.yml +44 -55
  93. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_params.yml +37 -52
  94. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_root.yml +39 -53
  95. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/valid.yml +43 -70
  96. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/find.yml +40 -55
  97. data/spec/fixtures/vcr_cassettes/resources/discharge/all.yml +64 -33
  98. data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_params.yml +70 -0
  99. data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_root.yml +69 -0
  100. data/spec/fixtures/vcr_cassettes/resources/discharge/create/valid.yml +84 -0
  101. data/spec/fixtures/vcr_cassettes/resources/discharge/find.yml +71 -0
  102. data/spec/fixtures/vcr_cassettes/resources/email_delivery/all.yml +40 -43
  103. data/spec/fixtures/vcr_cassettes/resources/event/all.yml +490 -166
  104. data/spec/fixtures/vcr_cassettes/resources/installment/all.yml +418 -52
  105. data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_params.yml +41 -52
  106. data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_root.yml +36 -48
  107. data/spec/fixtures/vcr_cassettes/resources/installment/create/valid.yml +48 -53
  108. data/spec/fixtures/vcr_cassettes/resources/installment/find.yml +44 -52
  109. data/spec/fixtures/vcr_cassettes/resources/remittance/all.yml +53 -33
  110. data/spec/fixtures/vcr_cassettes/resources/sns_delivery/all.yml +73 -0
  111. data/spec/fixtures/vcr_cassettes/resources/transaction/all.yml +34 -22
  112. data/spec/fixtures/vcr_cassettes/resources/web_hook/all.yml +42 -33
  113. data/spec/fixtures/vcr_cassettes/resources/webhook_delivery/all.yml +1232 -54
  114. data/spec/spec_helper.rb +3 -20
  115. data/spec/support/stub_env.rb +7 -0
  116. data/spec/support/vcr.rb +3 -4
  117. metadata +87 -52
  118. data/.coveralls.yml +0 -2
  119. data/.travis.yml +0 -46
  120. data/gemfiles/rails_42.gemfile +0 -8
  121. data/gemfiles/rails_50.gemfile +0 -8
  122. data/gemfiles/rails_51.gemfile +0 -8
  123. data/gemfiles/rails_52.gemfile +0 -9
  124. data/lib/boletosimples/extra.rb +0 -8
  125. data/lib/boletosimples/resources/partner/user.rb +0 -7
  126. data/lib/oauth2_patch.rb +0 -24
  127. data/spec/boletosimples/extra_spec.rb +0 -31
  128. data/spec/boletosimples/resources/partner/user_spec.rb +0 -19
  129. data/spec/fixtures/vcr_cassettes/configuration/client_credentials/invalid.yml +0 -64
  130. data/spec/fixtures/vcr_cassettes/configuration/client_credentials/valid.yml +0 -56
  131. data/spec/fixtures/vcr_cassettes/extra/userinfo/authenticated.yml +0 -58
  132. data/spec/fixtures/vcr_cassettes/extra/userinfo/not_authenticated.yml +0 -54
  133. data/spec/fixtures/vcr_cassettes/last_request/userinfo.yml +0 -58
  134. data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/failure.yml +0 -118
  135. data/spec/fixtures/vcr_cassettes/resources/partner/user/create.yml +0 -60
  136. data/spec/spec.opts +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 267fcb0a89580d774bde7f6f875cedffb19d56cf81b5fea7adc7a25d51948320
4
- data.tar.gz: 121d8f4fa802857f9b401ff37f33ac72fcecb0c43f1ceb817687d342e097b8fb
3
+ metadata.gz: '080a1d5f5d9ba832ed3dd093f291dbeb217b732eba56d3713932917ae91534a0'
4
+ data.tar.gz: 954683fba1d52eca0c0831e46828caeecc57ab04b250ab5674433371fb77083d
5
5
  SHA512:
6
- metadata.gz: a3e8c7819279bc063e647329d89bda39047cc70182df5c6832fbc9635382b92896dbbf670dceba67698f88bd6fca35defb2a4bad49911b9aaa19b0fad2a39e27
7
- data.tar.gz: 1eb282604546f93c830134f9137c3f78a73190d3461d4c1e7a6f8e065a188321f8d030a4bbcc92892903123d6978d1c755f21ff8e4a2ce999cee8e477803eaac
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.5.0
1
+ 3.0.1
data/CHANGELOG.md CHANGED
@@ -1,24 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ## 0.4.2
3
+ ## 1.0.0
4
4
 
5
- ### improvements
5
+ ### Breaking changes
6
6
 
7
- - Update dependencies
8
-
9
- ## 0.2.2
10
-
11
- ### features
12
-
13
- - Add BankBilletAccount resource
14
-
15
- ## 0.1.1
16
-
17
- ### features
18
-
19
- - Created `client.cancel_bank_billet(id, options)` to cancel bank billets
20
-
21
- ### improvements
22
-
23
- - Changed `client.create_customer({ "customer" => params })` to `client.create_customer(params)`
24
- - 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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
@@ -11,4 +13,4 @@ task :console do
11
13
 
12
14
  ARGV.clear
13
15
  IRB.start
14
- end
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
 
@@ -21,18 +21,21 @@ Gem::Specification.new do |gem|
21
21
  gem.require_paths = ['lib']
22
22
 
23
23
  # Gems that must be intalled for boletosimples to work
24
- gem.add_dependency 'her', '~> 1.0'
25
- gem.add_dependency 'faraday_middleware', '~> 0.12'
26
- gem.add_dependency 'faraday-http-cache', '~> 2.0.0'
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'
29
+ gem.add_development_dependency 'fuubar'
30
+ gem.add_development_dependency 'rake'
30
31
  gem.add_development_dependency 'rspec'
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'
31
39
  gem.add_development_dependency 'vcr'
32
40
  gem.add_development_dependency 'webmock'
33
- gem.add_development_dependency 'rake'
34
- gem.add_development_dependency 'coveralls'
35
- gem.add_development_dependency 'simplecov'
36
- gem.add_development_dependency 'codeclimate-test-reporter'
37
- gem.add_development_dependency 'rubocop'
38
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,7 +7,6 @@ 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
 
@@ -16,6 +17,7 @@ module BoletoSimples
16
17
  autoload :BankBilletRemittance, 'boletosimples/resources/bank_billet_remittance'
17
18
  autoload :Event, 'boletosimples/resources/event'
18
19
  autoload :EmailDelivery, 'boletosimples/resources/email_delivery'
20
+ autoload :SmsDelivery, 'boletosimples/resources/sms_delivery'
19
21
  autoload :Customer, 'boletosimples/resources/customer'
20
22
  autoload :CustomerImport, 'boletosimples/resources/customer_import'
21
23
  autoload :CustomerSubscription, 'boletosimples/resources/customer_subscription'
@@ -28,14 +30,11 @@ module BoletoSimples
28
30
  autoload :Webhook, 'boletosimples/resources/webhook'
29
31
  autoload :WebhookDelivery, 'boletosimples/resources/webhook_delivery'
30
32
 
31
- module Partner
32
- autoload :User, 'boletosimples/resources/partner/user'
33
- end
34
-
35
33
  module Middleware
36
34
  autoload :UserAgent, 'boletosimples/middlewares/user_agent'
37
35
  autoload :RaiseError, 'boletosimples/middlewares/raise_error'
38
36
  autoload :LastRequest, 'boletosimples/middlewares/last_request'
37
+ autoload :Bearer, 'boletosimples/middlewares/bearer'
39
38
  end
40
39
 
41
40
  class << self
@@ -47,7 +46,6 @@ module BoletoSimples
47
46
  configuration.setup_her # after changing configuration gem her should be configured
48
47
  end
49
48
  end
50
-
51
49
  end
52
50
 
53
51
  BoletoSimples.configure
@@ -1,49 +1,38 @@
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, :user_agent
5
+ attr_accessor :environment, :cache, :user_agent, :api_token
6
6
 
7
7
  BASE_URI = {
8
8
  sandbox: 'https://sandbox.boletosimples.com.br/api/v1',
9
9
  production: 'https://boletosimples.com.br/api/v1',
10
10
  development: 'http://localhost:5000/api/v1'
11
- }
11
+ }.freeze
12
12
 
13
13
  def initialize
14
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']
15
+ @api_token = ENV['BOLETOSIMPLES_API_TOKEN']
16
+ @user_agent = ENV['BOLETOSIMPLES_USER_AGENT']
18
17
  @cache = nil
19
- @user_agent = ENV['BOLETOSIMPLES_USER_AGENT'] || "BoletoSimples Ruby Client v#{BoletoSimples::VERSION} (contato@boletosimples.com.br)"
20
18
  end
21
19
 
22
20
  def base_uri
23
21
  BASE_URI[@environment]
24
22
  end
25
23
 
26
- def access_token?
27
- !@access_token.nil?
28
- end
29
-
30
- def client_credentials
31
- response = Her::API.default_api.connection.post 'oauth2/token', {
32
- grant_type: 'client_credentials',
33
- client_id: application_id,
34
- client_secret: application_secret
35
- }
36
- response.body[:data]
24
+ def api_token?
25
+ !@api_token.nil?
37
26
  end
38
27
 
39
28
  def setup_her
40
29
  Her::API.setup url: base_uri do |c|
41
30
  # Request
42
31
  c.use BoletoSimples::Middleware::UserAgent
43
- c.use FaradayMiddleware::OAuth2, access_token, token_type: 'param' if access_token?
32
+ c.use BoletoSimples::Middleware::Bearer if api_token?
44
33
  c.use Faraday::Request::Multipart
45
- c.use Faraday::Request::UrlEncoded
46
34
  c.use FaradayMiddleware::EncodeJson
35
+ c.use Her::Middleware::AcceptJSON
47
36
  c.use Faraday::HttpCache, store: cache unless cache.nil?
48
37
 
49
38
  # Response
@@ -56,12 +45,12 @@ module BoletoSimples
56
45
  end
57
46
 
58
47
  # 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, CustomerSubscriptionImport, Installment, Transaction, Partner::User,
60
- Webhook, Discharge, Remittance, WebhookDelivery, Event, EmailDelivery, BankBilletDischarge, BankBilletPayment, BankBilletRemittance].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|
61
52
  klass.send(:use_api, Her::API.default_api)
62
53
  end
63
54
  end
64
-
65
55
  end
66
-
67
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