boletosimples 0.6.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -12
  3. data/README.md +21 -59
  4. data/lib/boletosimples/configuration.rb +25 -28
  5. data/lib/boletosimples/last_request.rb +17 -10
  6. data/lib/boletosimples/middlewares/bearer.rb +12 -0
  7. data/lib/boletosimples/middlewares/custom_headers.rb +12 -0
  8. data/lib/boletosimples/middlewares/debug.rb +30 -0
  9. data/lib/boletosimples/middlewares/last_request.rb +3 -1
  10. data/lib/boletosimples/middlewares/raise_error.rb +9 -2
  11. data/lib/boletosimples/middlewares/user_agent.rb +3 -1
  12. data/lib/boletosimples/resources/bank_billet.rb +5 -11
  13. data/lib/boletosimples/resources/bank_billet_account.rb +3 -1
  14. data/lib/boletosimples/resources/bank_billet_discharge.rb +3 -1
  15. data/lib/boletosimples/resources/bank_billet_payment.rb +3 -1
  16. data/lib/boletosimples/resources/bank_billet_remittance.rb +3 -1
  17. data/lib/boletosimples/resources/base_model.rb +3 -1
  18. data/lib/boletosimples/resources/customer.rb +3 -1
  19. data/lib/boletosimples/resources/customer_import.rb +5 -3
  20. data/lib/boletosimples/resources/customer_subscription.rb +3 -10
  21. data/lib/boletosimples/resources/customer_subscription_import.rb +5 -3
  22. data/lib/boletosimples/resources/discharge.rb +4 -11
  23. data/lib/boletosimples/resources/email_delivery.rb +3 -1
  24. data/lib/boletosimples/resources/event.rb +3 -1
  25. data/lib/boletosimples/resources/installment.rb +3 -1
  26. data/lib/boletosimples/resources/remittance.rb +3 -1
  27. data/lib/boletosimples/resources/sms_delivery.rb +6 -0
  28. data/lib/boletosimples/resources/transaction.rb +3 -1
  29. data/lib/boletosimples/resources/webhook.rb +3 -1
  30. data/lib/boletosimples/resources/webhook_delivery.rb +3 -1
  31. data/lib/boletosimples/response_error.rb +10 -5
  32. data/lib/boletosimples/version.rb +3 -1
  33. data/lib/boletosimples.rb +6 -6
  34. data/spec/boletosimples/configuration_spec.rb +67 -80
  35. data/spec/boletosimples/last_request_spec.rb +17 -28
  36. data/spec/boletosimples/middlewares/custom_headers_spec.rb +26 -0
  37. data/spec/boletosimples/resources/bank_billet_account_spec.rb +57 -33
  38. data/spec/boletosimples/resources/bank_billet_discharge_spec.rb +7 -12
  39. data/spec/boletosimples/resources/bank_billet_payment_spec.rb +7 -12
  40. data/spec/boletosimples/resources/bank_billet_remittance_spec.rb +7 -12
  41. data/spec/boletosimples/resources/bank_billet_spec.rb +56 -42
  42. data/spec/boletosimples/resources/customer_import_spec.rb +41 -30
  43. data/spec/boletosimples/resources/customer_spec.rb +57 -39
  44. data/spec/boletosimples/resources/customer_subscription_import_spec.rb +41 -30
  45. data/spec/boletosimples/resources/customer_subscription_spec.rb +61 -33
  46. data/spec/boletosimples/resources/discharge_spec.rb +64 -11
  47. data/spec/boletosimples/resources/email_delivery_spec.rb +6 -11
  48. data/spec/boletosimples/resources/event_spec.rb +7 -12
  49. data/spec/boletosimples/resources/installment_spec.rb +61 -32
  50. data/spec/boletosimples/resources/remittance_spec.rb +7 -12
  51. data/spec/boletosimples/resources/sms_delivery_spec.rb +12 -0
  52. data/spec/boletosimples/resources/transactions_spec.rb +7 -12
  53. data/spec/boletosimples/resources/webhook_delivery_spec.rb +7 -12
  54. data/spec/boletosimples/resources/webhook_spec.rb +7 -12
  55. data/spec/fixtures/discharge.RET +3 -0
  56. data/spec/fixtures/vcr_cassettes/custom_headers.yml +113 -0
  57. data/spec/fixtures/vcr_cassettes/last_request/bank_billets.yml +409 -95
  58. data/spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml +101 -99
  59. data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/success.yml +55 -95
  60. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_params.yml +55 -27
  61. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/invalid_root.yml +51 -24
  62. data/spec/fixtures/vcr_cassettes/resources/bank_billet/create/valid.yml +64 -34
  63. data/spec/fixtures/vcr_cassettes/resources/bank_billet/duplicate/success.yml +97 -0
  64. data/spec/fixtures/vcr_cassettes/resources/bank_billet/find.yml +73 -34
  65. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/all.yml +82 -27
  66. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_params.yml +57 -27
  67. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/invalid_root.yml +53 -26
  68. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/create/valid.yml +64 -28
  69. data/spec/fixtures/vcr_cassettes/resources/bank_billet_account/find.yml +61 -25
  70. data/spec/fixtures/vcr_cassettes/resources/bank_billet_discharge/all.yml +59 -46
  71. data/spec/fixtures/vcr_cassettes/resources/bank_billet_payment/all.yml +74 -71
  72. data/spec/fixtures/vcr_cassettes/resources/bank_billet_remittance/all.yml +63 -47
  73. data/spec/fixtures/vcr_cassettes/resources/customer/all.yml +141 -39
  74. data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_params.yml +54 -25
  75. data/spec/fixtures/vcr_cassettes/resources/customer/create/invalid_root.yml +54 -24
  76. data/spec/fixtures/vcr_cassettes/resources/customer/create/valid.yml +56 -28
  77. data/spec/fixtures/vcr_cassettes/resources/customer/find.yml +56 -26
  78. data/spec/fixtures/vcr_cassettes/resources/customer_import/all.yml +58 -59
  79. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_params.yml +53 -51
  80. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/invalid_root.yml +54 -52
  81. data/spec/fixtures/vcr_cassettes/resources/customer_import/create/valid.yml +58 -67
  82. data/spec/fixtures/vcr_cassettes/resources/customer_import/find.yml +55 -53
  83. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/all.yml +65 -51
  84. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_params.yml +56 -50
  85. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/invalid_root.yml +52 -48
  86. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/create/valid.yml +63 -52
  87. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/find.yml +61 -51
  88. data/spec/fixtures/vcr_cassettes/resources/customer_subscription/next_charge.yml +60 -132
  89. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/all.yml +58 -54
  90. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_params.yml +53 -52
  91. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/invalid_root.yml +55 -53
  92. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/create/valid.yml +58 -69
  93. data/spec/fixtures/vcr_cassettes/resources/customer_subscription_import/find.yml +55 -54
  94. data/spec/fixtures/vcr_cassettes/resources/discharge/all.yml +63 -34
  95. data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_params.yml +86 -0
  96. data/spec/fixtures/vcr_cassettes/resources/discharge/create/invalid_root.yml +85 -0
  97. data/spec/fixtures/vcr_cassettes/resources/discharge/create/valid.yml +100 -0
  98. data/spec/fixtures/vcr_cassettes/resources/discharge/find.yml +89 -0
  99. data/spec/fixtures/vcr_cassettes/resources/email_delivery/all.yml +40 -43
  100. data/spec/fixtures/vcr_cassettes/resources/event/all.yml +326 -167
  101. data/spec/fixtures/vcr_cassettes/resources/installment/all.yml +113 -51
  102. data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_params.yml +57 -52
  103. data/spec/fixtures/vcr_cassettes/resources/installment/create/invalid_root.yml +52 -48
  104. data/spec/fixtures/vcr_cassettes/resources/installment/create/valid.yml +63 -52
  105. data/spec/fixtures/vcr_cassettes/resources/installment/find.yml +83 -51
  106. data/spec/fixtures/vcr_cassettes/resources/remittance/all.yml +83 -62
  107. data/spec/fixtures/vcr_cassettes/resources/sns_delivery/all.yml +89 -0
  108. data/spec/fixtures/vcr_cassettes/resources/transaction/all.yml +73 -60
  109. data/spec/fixtures/vcr_cassettes/resources/web_hook/all.yml +59 -34
  110. data/spec/fixtures/vcr_cassettes/resources/webhook_delivery/all.yml +2684 -55
  111. data/spec/spec_helper.rb +3 -20
  112. data/spec/support/stub_env.rb +7 -0
  113. data/spec/support/vcr.rb +3 -4
  114. metadata +42 -176
  115. data/.coveralls.yml +0 -2
  116. data/.gitignore +0 -19
  117. data/.ruby-version +0 -1
  118. data/.travis.yml +0 -46
  119. data/Gemfile +0 -4
  120. data/Rakefile +0 -14
  121. data/boletosimples.gemspec +0 -38
  122. data/gemfiles/rails_42.gemfile +0 -8
  123. data/gemfiles/rails_50.gemfile +0 -8
  124. data/gemfiles/rails_51.gemfile +0 -8
  125. data/gemfiles/rails_52.gemfile +0 -9
  126. data/lib/boletosimples/extra.rb +0 -8
  127. data/lib/boletosimples/resources/partner/user.rb +0 -7
  128. data/lib/oauth2_patch.rb +0 -24
  129. data/spec/boletosimples/extra_spec.rb +0 -31
  130. data/spec/boletosimples/resources/partner/user_spec.rb +0 -19
  131. data/spec/fixtures/vcr_cassettes/configuration/client_credentials/invalid.yml +0 -64
  132. data/spec/fixtures/vcr_cassettes/configuration/client_credentials/valid.yml +0 -56
  133. data/spec/fixtures/vcr_cassettes/extra/userinfo/authenticated.yml +0 -58
  134. data/spec/fixtures/vcr_cassettes/extra/userinfo/not_authenticated.yml +0 -54
  135. data/spec/fixtures/vcr_cassettes/last_request/userinfo.yml +0 -58
  136. data/spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/failure.yml +0 -118
  137. data/spec/fixtures/vcr_cassettes/resources/partner/user/create.yml +0 -60
  138. data/spec/spec.opts +0 -8
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class Transaction < BaseModel
3
5
  end
4
- end
6
+ end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class Webhook < BaseModel
3
5
  end
4
- end
6
+ end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  class WebhookDelivery < BaseModel
3
5
  end
4
- end
6
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
4
  # BoletoSimples::ResponseError
3
5
  # Exception that gets raised if the response is an error (4xx or 5xx)
@@ -7,14 +9,14 @@ module BoletoSimples
7
9
  # Examples:
8
10
  #
9
11
  # BoletoSimples::BankBillet.all
10
- # BoletoSimples::ResponseError: 401 POST https://sandbox.boletosimples.com.br/api/v1/bank_billets
12
+ # BoletoSimples::ResponseError: 401 POST https://api-sandbox.kobana.com.br/v1/bank_billets
11
13
  #
12
14
  # begin
13
15
  # BoletoSimples::BankBillet.all
14
16
  # rescue BoletoSimples::ResponseError => response
15
17
  # response.status # => 401
16
18
  # response.method # => "GET"
17
- # response.url # => "https://sandbox.boletosimples.com.br/api/v1/bank_billets"
19
+ # response.url # => "https://api-sandbox.kobana.com.br/v1/bank_billets"
18
20
  # response.body # => "{"error":"Você precisa se logar ou registrar antes de prosseguir."}"
19
21
  # response.error_message # => "Você precisa se logar ou registrar antes de prosseguir."
20
22
  # end
@@ -29,15 +31,18 @@ module BoletoSimples
29
31
  @status = response[:status].to_i
30
32
  @method = response[:method].to_s.upcase
31
33
  @url = response[:url]
32
- @error_message = @body[:error]
34
+
35
+ errors = response[:body][:errors]
36
+ @error_message = errors.first[:title] unless errors.blank?
33
37
 
34
38
  super
35
39
  end
36
40
 
37
41
  def to_s
38
- msg = "#{status} #{method} #{url}"
42
+ msg = ''
43
+ msg += "#{status} #{method} #{url}"
39
44
  msg << " (#{error_message})" unless error_message.blank?
40
45
  msg
41
46
  end
42
47
  end
43
- end
48
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BoletoSimples
2
- VERSION = '0.6.0'
4
+ VERSION = '2.1.0'
3
5
  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,13 @@ 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'
35
+ autoload :CustomHeaders, 'boletosimples/middlewares/custom_headers'
37
36
  autoload :RaiseError, 'boletosimples/middlewares/raise_error'
38
37
  autoload :LastRequest, 'boletosimples/middlewares/last_request'
38
+ autoload :Debug, 'boletosimples/middlewares/debug'
39
+ autoload :Bearer, 'boletosimples/middlewares/bearer'
39
40
  end
40
41
 
41
42
  class << self
@@ -47,7 +48,6 @@ module BoletoSimples
47
48
  configuration.setup_her # after changing configuration gem her should be configured
48
49
  end
49
50
  end
50
-
51
51
  end
52
52
 
53
53
  BoletoSimples.configure
@@ -1,101 +1,88 @@
1
- # encoding: UTF-8
1
+ # # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe BoletoSimples::Configuration do
5
- before {
6
- @last_env = {}
7
- @last_env['BOLETOSIMPLES_ENV'] = ENV['BOLETOSIMPLES_ENV']
8
- @last_env['BOLETOSIMPLES_APP_ID'] = ENV['BOLETOSIMPLES_APP_ID']
9
- @last_env['BOLETOSIMPLES_APP_SECRET'] = ENV['BOLETOSIMPLES_APP_SECRET']
10
- @last_env['BOLETOSIMPLES_ACCESS_TOKEN'] = ENV['BOLETOSIMPLES_ACCESS_TOKEN']
11
- }
12
- after {
13
- ENV['BOLETOSIMPLES_ENV'] = @last_env['BOLETOSIMPLES_ENV']
14
- ENV['BOLETOSIMPLES_APP_ID'] = @last_env['BOLETOSIMPLES_APP_ID']
15
- ENV['BOLETOSIMPLES_APP_SECRET'] = @last_env['BOLETOSIMPLES_APP_SECRET']
16
- ENV['BOLETOSIMPLES_ACCESS_TOKEN'] = @last_env['BOLETOSIMPLES_ACCESS_TOKEN']
17
- }
18
6
  describe 'defaults' do
19
- before {
20
- ENV['BOLETOSIMPLES_ENV'] = nil
21
- ENV['BOLETOSIMPLES_APP_ID'] = nil
22
- ENV['BOLETOSIMPLES_APP_SECRET'] = nil
23
- ENV['BOLETOSIMPLES_ACCESS_TOKEN'] = nil
24
- }
25
- subject { BoletoSimples::Configuration.new }
26
- before { subject.setup_her}
27
- it { expect(subject.environment).to eq(:sandbox) }
28
- it { expect(subject.base_uri).to eq('https://sandbox.boletosimples.com.br/api/v1') }
29
- it { expect(subject.application_id).to be_nil }
30
- it { expect(subject.application_secret).to be_nil }
31
- it { expect(subject.access_token).to be_nil }
32
- it { expect(subject.cache).to be_nil }
33
- it { expect(subject).not_to be_access_token }
7
+ subject { described_class.new }
8
+
9
+ before do
10
+ stub_env('BOLETOSIMPLES_ENV', nil)
11
+ stub_env('BOLETOSIMPLES_USER_AGENT', nil)
12
+ subject.setup_her
13
+ end
14
+
15
+ after do
16
+ BoletoSimples.configure
17
+ end
18
+
19
+ it do
20
+ expect(subject.environment).to eq(:sandbox)
21
+ expect(subject.base_uri).to eq('https://api-sandbox.kobana.com.br/v1')
22
+ expect(subject.cache).to be_nil
23
+ expect(subject.user_agent).to be_nil
24
+ expect(subject.custom_headers).to eq({})
25
+ end
34
26
  end
27
+
35
28
  describe 'environment variables' do
36
- before {
37
- ENV['BOLETOSIMPLES_ENV'] = 'production'
38
- ENV['BOLETOSIMPLES_APP_ID'] = 'app-id'
39
- ENV['BOLETOSIMPLES_APP_SECRET'] = 'app-secret'
40
- ENV['BOLETOSIMPLES_ACCESS_TOKEN'] = 'access-token'
41
- }
42
- before { BoletoSimples.configure }
43
29
  subject { BoletoSimples.configuration }
44
- # subject { BoletoSimples::Configuration.new }
45
- it { expect(subject.environment).to eq(:production) }
46
- it { expect(subject.base_uri).to eq('https://boletosimples.com.br/api/v1') }
47
- it { expect(subject.application_id).to eq('app-id') }
48
- it { expect(subject.application_secret).to eq('app-secret') }
49
- it { expect(subject.access_token).to eq('access-token') }
50
- it { expect(subject).to be_access_token }
51
- it { expect(subject.user_agent).to eq("BoletoSimples Ruby Client v#{BoletoSimples::VERSION} (contato@boletosimples.com.br)") }
30
+
31
+ before do
32
+ stub_env('BOLETOSIMPLES_ENV', 'production')
33
+ stub_env('BOLETOSIMPLES_USER_AGENT', 'email@minhaempresa.com.br')
34
+ BoletoSimples.configure
35
+ end
36
+
37
+ after do
38
+ BoletoSimples.configure
39
+ end
40
+
41
+ it do
42
+ expect(subject.environment).to eq(:production)
43
+ expect(subject.base_uri).to eq('https://api.kobana.com.br/v1')
44
+ expect(subject.user_agent).to eq('email@minhaempresa.com.br')
45
+ end
46
+
52
47
  describe 'cache' do
53
- it { expect(subject.cache).to be_nil }
54
- it { expect(Her::API.default_api.connection.builder.handlers).not_to include(Faraday::HttpCache) }
48
+ it do
49
+ expect(subject.cache).to be_nil
50
+ expect(Her::API.default_api.connection.builder.handlers).not_to include(Faraday::HttpCache)
51
+ end
55
52
  end
56
53
  end
54
+
57
55
  describe 'configuration' do
56
+ subject { BoletoSimples.configuration }
57
+
58
58
  let(:cache_object) { double('Dalli') }
59
- before {
59
+
60
+ before do
60
61
  BoletoSimples.configure do |c|
61
62
  c.environment = :production
62
- c.application_id = 'app-id'
63
- c.application_secret = 'app-secret'
64
- c.access_token = 'access-token'
65
63
  c.cache = cache_object
66
64
  c.user_agent = 'Meu agent'
67
- end
68
- }
69
- subject { BoletoSimples.configuration }
70
- it { expect(subject.environment).to eq(:production) }
71
- it { expect(subject.user_agent).to eq("Meu agent") }
72
- it { expect(subject.base_uri).to eq('https://boletosimples.com.br/api/v1') }
73
- it { expect(subject.application_id).to eq('app-id') }
74
- it { expect(subject.application_secret).to eq('app-secret') }
75
- it { expect(subject.access_token).to eq('access-token') }
76
- describe 'cache' do
77
- it { expect(subject.cache).to eq(cache_object) }
78
- it { expect(Her::API.default_api.connection.builder.handlers).to include(Faraday::HttpCache) }
79
- end
80
- describe 'client credentials' do
81
- context 'invalid credentials', vcr: { cassette_name: 'configuration/client_credentials/invalid'} do
82
- before {
83
- BoletoSimples.configure do |c|
84
- c.application_id = 'app-id'
85
- c.application_secret = 'app-secret'
86
- c.access_token = nil
87
- end
65
+ c.custom_headers = {
66
+ 'X-CUSTOM' => 'CONTENT'
88
67
  }
89
- it { expect{subject.client_credentials}.to raise_error(BoletoSimples::ResponseError, "401 POST https://sandbox.boletosimples.com.br/api/v1/oauth2/token (invalid_client)") }
90
68
  end
91
- context 'valid credentials', vcr: { cassette_name: 'configuration/client_credentials/valid'} do
92
- # Before running this spec again, you need to set environment variable BOLETOSIMPLES_APP_ID and BOLETOSIMPLES_APP_SECRET
93
- before {
94
- BoletoSimples.configure do |c|
95
- c.access_token = nil
96
- end
97
- }
98
- it { expect(subject.client_credentials).to include(:access_token) }
69
+ end
70
+
71
+ after do
72
+ BoletoSimples.configure
73
+ end
74
+
75
+ it do
76
+ expect(subject.environment).to eq(:production)
77
+ expect(subject.user_agent).to eq('Meu agent')
78
+ expect(subject.custom_headers).to eq({ 'X-CUSTOM' => 'CONTENT' })
79
+ expect(subject.base_uri).to eq('https://api.kobana.com.br/v1')
80
+ end
81
+
82
+ describe 'cache' do
83
+ it do
84
+ expect(subject.cache).to eq(cache_object)
85
+ expect(Her::API.default_api.connection.builder.handlers).to include(Faraday::HttpCache)
99
86
  end
100
87
  end
101
88
  end
@@ -1,34 +1,23 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'spec_helper'
3
4
 
4
5
  RSpec.describe BoletoSimples::LastRequest do
5
- before {
6
- BoletoSimples.configure do |c|
7
- c.application_id = nil
8
- c.application_secret = nil
9
- end
10
- }
11
- describe 'bank_billets', vcr: { cassette_name: 'last_request/bank_billets'} do
12
- before { BoletoSimples::BankBillet.all.size }
13
- subject { BoletoSimples.last_request }
14
- it { expect(subject).to be_kind_of(BoletoSimples::LastRequest) }
15
- it { expect(subject.body).to be_kind_of(Array) }
16
- it { expect(subject.body.first).to be_kind_of(Hash) }
17
- it { expect(subject.response_headers).to be_kind_of(Hash) }
18
- it { expect(subject.total).to be_kind_of(Integer) }
19
- it { expect(subject.ratelimit_limit).to be_kind_of(Integer) }
20
- it { expect(subject.ratelimit_remaining).to be_kind_of(Integer) }
21
- it { expect(subject.links.keys).to match_array([:next, :last]) }
22
- end
23
- describe 'user_info', vcr: { cassette_name: 'last_request/userinfo'} do
24
- before { BoletoSimples::Extra.userinfo }
6
+ describe 'bank_billets', vcr: { cassette_name: 'last_request/bank_billets' } do
25
7
  subject { BoletoSimples.last_request }
26
- it { expect(subject).to be_kind_of(BoletoSimples::LastRequest) }
27
- it { expect(subject.body).to be_kind_of(Hash) }
28
- it { expect(subject.response_headers).to be_kind_of(Hash) }
29
- it { expect(subject.total).to eq(0) }
30
- it { expect(subject.ratelimit_limit).to be_kind_of(Integer) }
31
- it { expect(subject.ratelimit_remaining).to be_kind_of(Integer) }
32
- it { expect(subject.links).to eq({}) }
8
+
9
+ before { BoletoSimples::BankBillet.all(page: 2).size }
10
+
11
+ it do
12
+ expect(subject).to be_kind_of(described_class)
13
+ expect(subject.body).to be_kind_of(Array)
14
+ expect(subject.body.first).to be_kind_of(Hash)
15
+ expect(subject.request_headers).to be_kind_of(Hash)
16
+ expect(subject.response_headers).to be_kind_of(Hash)
17
+ expect(subject.total).to be_kind_of(Integer)
18
+ expect(subject.ratelimit_limit).to be_kind_of(Integer)
19
+ expect(subject.ratelimit_remaining).to be_kind_of(Integer)
20
+ expect(subject.links.keys).to match_array(%i[first next prev])
21
+ end
33
22
  end
34
23
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe BoletoSimples::Middleware::CustomHeaders do
6
+ describe 'bank_billets', vcr: { cassette_name: 'custom_headers' } do
7
+ subject { BoletoSimples.last_request }
8
+
9
+ before do
10
+ BoletoSimples.configure do |c|
11
+ c.custom_headers = {
12
+ 'X-CUSTOM' => 'CONTENT'
13
+ }
14
+ end
15
+ BoletoSimples::BankBillet.all(page: 2).size
16
+ end
17
+
18
+ after do
19
+ BoletoSimples.configure
20
+ end
21
+
22
+ it do
23
+ expect(subject.request_headers).to include({ 'X-CUSTOM' => 'CONTENT' })
24
+ end
25
+ end
26
+ end
@@ -1,62 +1,86 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- # Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
5
+ # Before running this spec again, you need to set environment variable BOLETOSIMPLES_API_TOKEN
6
6
  RSpec.describe BoletoSimples::BankBilletAccount do
7
- before {
8
- BoletoSimples.configure do |c|
9
- c.application_id = nil
10
- c.application_secret = nil
11
- end
12
- }
13
7
  describe 'methods' do
14
- before {
8
+ before do
15
9
  VCR.use_cassette('resources/bank_billet_account/create/valid') do
16
- @bank_billet_account = BoletoSimples::BankBilletAccount.create({
17
- bank_contract_slug: 'sicoob-02',
18
- next_our_number: '1',
19
- agency_number: '4327',
20
- agency_digit: '3',
21
- account_number: '3666',
22
- account_digit: '8',
23
- extra1_length: '1234567'
24
- })
10
+ @bank_billet_account = described_class.create(
11
+ bank_contract_slug: 'sicoob-02',
12
+ next_our_number: '1',
13
+ agency_number: '4327',
14
+ agency_digit: '3',
15
+ account_number: '3666',
16
+ account_digit: '8',
17
+ extra1: '1234567',
18
+ beneficiary_name: 'XPTO S.A.',
19
+ beneficiary_cnpj_cpf: '22.622.867/0001-11',
20
+ beneficiary_address_street: 'Rua S',
21
+ beneficiary_address_city: 'São Paulo',
22
+ beneficiary_address_state: 'SP',
23
+ beneficiary_address_neighborhood: 'Moema',
24
+ beneficiary_address_zipcode: '04524030'
25
+ )
25
26
  end
26
- }
27
+ end
28
+
27
29
  describe 'create' do
28
30
  context 'valid parameters' do
29
31
  subject { @bank_billet_account }
30
- it { expect(subject).to be_a_kind_of(BoletoSimples::BankBilletAccount) }
31
- it { expect(subject.response_errors).to eq({}) }
32
- it { expect(subject.attributes.keys).to match_array(["account_digit", "account_number", "agency_digit", "agency_number", "bank_contract_slug", "extra1", "extra1_digit", "extra1_length", "extra2", "extra2_digit", "id", "next_our_number"]) }
32
+
33
+ it do
34
+ expect(subject).to be_a_kind_of(described_class)
35
+ expect(subject.response_errors).to eq({})
36
+ end
33
37
  end
38
+
34
39
  context 'invalid parameters' do
35
40
  context 'empty bank_billet' do
36
- subject {
41
+ subject do
37
42
  VCR.use_cassette('resources/bank_billet_account/create/invalid_root') do
38
- BoletoSimples::BankBilletAccount.create({})
43
+ described_class.create({})
39
44
  end
45
+ end
46
+
47
+ it {
48
+ expect(subject.response_errors).to eq([{ code: 422, status: 422,
49
+ title: 'bank_billet_account não pode ficar em branco' }])
40
50
  }
41
- it { expect(subject.response_errors).to eq({ bank_billet_account: ["não pode ficar em branco"] }) }
42
51
  end
52
+
43
53
  context 'invalid params' do
44
- subject {
54
+ subject do
45
55
  VCR.use_cassette('resources/bank_billet_account/create/invalid_params') do
46
- BoletoSimples::BankBilletAccount.create({ bank_contract_slug: '' })
56
+ described_class.create({ bank_contract_slug: '' })
47
57
  end
58
+ end
59
+
60
+ it {
61
+ expect(subject.response_errors).to eq({ bank_contract_slug: ['não pode ficar em branco'],
62
+ beneficiary_name: ['não pode ficar em branco'],
63
+ beneficiary_cnpj_cpf: ['não pode ficar em branco'],
64
+ beneficiary_address_street: ['não pode ficar em branco'],
65
+ beneficiary_address_city: ['não pode ficar em branco'],
66
+ beneficiary_address_neighborhood: ['não pode ficar em branco'],
67
+ beneficiary_address_state: ['não pode ficar em branco'],
68
+ beneficiary_address_zipcode: ['não pode ficar em branco'] })
48
69
  }
49
- it { expect(subject.response_errors).to eq({ :agency_number => ["não pode ficar em branco"], :account_number => ["não pode ficar em branco"], :bank_contract_slug => ["não pode ficar em branco"] }) }
50
70
  end
51
71
  end
52
72
  end
73
+
53
74
  describe 'find', vcr: { cassette_name: 'resources/bank_billet_account/find' } do
54
- subject { BoletoSimples::BankBilletAccount.find(@bank_billet_account.id) }
55
- it { expect(subject).to be_a_kind_of(BoletoSimples::BankBilletAccount) }
75
+ subject { described_class.find(@bank_billet_account.id) }
76
+
77
+ it { expect(subject).to be_a_kind_of(described_class) }
56
78
  end
79
+
57
80
  describe 'all', vcr: { cassette_name: 'resources/bank_billet_account/all' } do
58
- subject { BoletoSimples::BankBilletAccount.all }
59
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::BankBilletAccount) }
81
+ subject { described_class.all }
82
+
83
+ it { expect(subject.first).to be_a_kind_of(described_class) }
60
84
  end
61
85
  end
62
- end
86
+ end
@@ -1,17 +1,12 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- # Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
5
+ # Before running this spec again, you need to set environment variable BOLETOSIMPLES_API_TOKEN
6
6
  RSpec.describe BoletoSimples::BankBilletDischarge do
7
- before {
8
- BoletoSimples.configure do |c|
9
- c.application_id = nil
10
- c.application_secret = nil
11
- end
12
- }
13
- describe 'all', vcr: { cassette_name: 'resources/bank_billet_discharge/all'} do
14
- subject { BoletoSimples::BankBilletDischarge.all }
15
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::BankBilletDischarge) }
7
+ describe 'all', vcr: { cassette_name: 'resources/bank_billet_discharge/all' } do
8
+ subject { described_class.all }
9
+
10
+ it { expect(subject.first).to be_a_kind_of(described_class) }
16
11
  end
17
- end
12
+ end
@@ -1,17 +1,12 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- # Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
5
+ # Before running this spec again, you need to set environment variable BOLETOSIMPLES_API_TOKEN
6
6
  RSpec.describe BoletoSimples::BankBilletPayment do
7
- before {
8
- BoletoSimples.configure do |c|
9
- c.application_id = nil
10
- c.application_secret = nil
11
- end
12
- }
13
- describe 'all', vcr: { cassette_name: 'resources/bank_billet_payment/all'} do
14
- subject { BoletoSimples::BankBilletPayment.all }
15
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::BankBilletPayment) }
7
+ describe 'all', vcr: { cassette_name: 'resources/bank_billet_payment/all' } do
8
+ subject { described_class.all }
9
+
10
+ it { expect(subject.first).to be_a_kind_of(described_class) }
16
11
  end
17
- end
12
+ end
@@ -1,17 +1,12 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- # Before running this spec again, you need to set environment variable BOLETOSIMPLES_ACCESS_TOKEN
5
+ # Before running this spec again, you need to set environment variable BOLETOSIMPLES_API_TOKEN
6
6
  RSpec.describe BoletoSimples::BankBilletRemittance do
7
- before {
8
- BoletoSimples.configure do |c|
9
- c.application_id = nil
10
- c.application_secret = nil
11
- end
12
- }
13
- describe 'all', vcr: { cassette_name: 'resources/bank_billet_remittance/all'} do
14
- subject { BoletoSimples::BankBilletRemittance.all }
15
- it { expect(subject.first).to be_a_kind_of(BoletoSimples::BankBilletRemittance) }
7
+ describe 'all', vcr: { cassette_name: 'resources/bank_billet_remittance/all' } do
8
+ subject { described_class.all }
9
+
10
+ it { expect(subject.first).to be_a_kind_of(described_class) }
16
11
  end
17
- end
12
+ end