boletosimples 2.0.0 → 2.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45f7d3c3d88c50c61728838d4c3b1e3664c8dd555cadb1d57379220d51aaba9a
4
- data.tar.gz: ea7d7fc35cb62433fc8fb7da44d01ff29d1a340f26c9f882c1ad91c4e3687b37
3
+ metadata.gz: 4b0b065f756a9ee10d080e10686637aee38ca6b63306878dc4879dbf56fd676c
4
+ data.tar.gz: c83c0eadff5245a19d07ea7a6cbe8c184eeed809e0895db4eb9ca78802250cf8
5
5
  SHA512:
6
- metadata.gz: 3d22dd9edf36f28e3e0caf282a7ce20fc75a4652cdbe1270f66708912f17b35b6a6e17c18c9aac1f3c38f7c8e8de08b4951f9338e5828a158664731ce4a49c35
7
- data.tar.gz: 3b3f5acf48399f3bf6964d1bd91c3208900fbc295f00b1755bf38435b4f6a1630e9247c84340eead8adef2b75ccc527bfccb57b8b8ea561d3a3337fa4a4ad1fe
6
+ metadata.gz: 977fb2769a02f9fcc6da3e2a4a4fe35ba9fe9f80327584bfc3b48dbb1446ea666f1b1cb0c5b61d09422cc1f1ff702a88768e3b58c820b8c83121972dab9ae4cd
7
+ data.tar.gz: fa35fda07bc7f85c31c03f4991fed958107e4709418292798c22122da79940719688bc337c5ab686224877102c30e475421e79e9d117b4f7ba66c883fba7c333
data/README.md CHANGED
@@ -35,6 +35,7 @@ BoletoSimples.configure do |c|
35
35
  c.api_token = 'api-token'
36
36
  c.user_agent = 'email@minhaempresa.com.br' #Colocar um e-mail válido para contatos técnicos relacionado ao uso da API.
37
37
  # c.debug = true
38
+ # c.custom_headers = { 'X-CUSTOM' => 'CONTENT' }
38
39
  end
39
40
  ```
40
41
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module BoletoSimples
4
4
  class Configuration
5
- attr_accessor :environment, :cache, :user_agent, :api_token, :debug
5
+ attr_accessor :environment, :cache, :user_agent, :custom_headers, :api_token, :debug
6
6
 
7
7
  BASE_URI = {
8
8
  sandbox: 'https://api-sandbox.kobana.com.br/v1',
@@ -11,11 +11,12 @@ module BoletoSimples
11
11
  }.freeze
12
12
 
13
13
  def initialize
14
- @environment = (ENV['BOLETOSIMPLES_ENV'] || :sandbox).to_sym
15
- @api_token = ENV['BOLETOSIMPLES_API_TOKEN']
16
- @user_agent = ENV['BOLETOSIMPLES_USER_AGENT']
14
+ @environment = ENV.fetch('BOLETOSIMPLES_ENV', :sandbox).to_sym
15
+ @api_token = ENV.fetch('BOLETOSIMPLES_API_TOKEN', nil)
16
+ @user_agent = ENV.fetch('BOLETOSIMPLES_USER_AGENT', nil)
17
+ @custom_headers = {}
17
18
  @cache = nil
18
- @debug = ENV['BOLETOSIMPLES_DEBUG']
19
+ @debug = ENV.fetch('BOLETOSIMPLES_DEBUG', nil)
19
20
  end
20
21
 
21
22
  def base_uri
@@ -35,6 +36,7 @@ module BoletoSimples
35
36
  # Request
36
37
  c.use BoletoSimples::Middleware::UserAgent
37
38
  c.use BoletoSimples::Middleware::Bearer if api_token?
39
+ c.use BoletoSimples::Middleware::CustomHeaders
38
40
  c.use Faraday::Request::Multipart
39
41
  c.use FaradayMiddleware::EncodeJson
40
42
  c.use Her::Middleware::AcceptJSON
@@ -2,7 +2,7 @@
2
2
 
3
3
  module BoletoSimples
4
4
  class LastRequest
5
- attr_reader :body, :response_headers, :total, :ratelimit_limit, :ratelimit_remaining, :links
5
+ attr_reader :body, :request_headers, :response_headers, :total, :ratelimit_limit, :ratelimit_remaining, :links
6
6
 
7
7
  def initialize(env)
8
8
  @env = env
@@ -12,6 +12,10 @@ module BoletoSimples
12
12
  @body ||= @env[:body][:data]
13
13
  end
14
14
 
15
+ def request_headers
16
+ @request_headers ||= @env.request_headers
17
+ end
18
+
15
19
  def response_headers
16
20
  @response_headers ||= @env[:response_headers]
17
21
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BoletoSimples
4
+ module Middleware
5
+ class CustomHeaders < Faraday::Middleware
6
+ def call(env)
7
+ env[:request_headers].merge!(BoletoSimples.configuration.custom_headers)
8
+ @app.call(env)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BoletoSimples
4
- VERSION = '2.0.0'
4
+ VERSION = '2.1.0'
5
5
  end
data/lib/boletosimples.rb CHANGED
@@ -32,6 +32,7 @@ module BoletoSimples
32
32
 
33
33
  module Middleware
34
34
  autoload :UserAgent, 'boletosimples/middlewares/user_agent'
35
+ autoload :CustomHeaders, 'boletosimples/middlewares/custom_headers'
35
36
  autoload :RaiseError, 'boletosimples/middlewares/raise_error'
36
37
  autoload :LastRequest, 'boletosimples/middlewares/last_request'
37
38
  autoload :Debug, 'boletosimples/middlewares/debug'
@@ -1,72 +1,89 @@
1
1
  # # frozen_string_literal: true
2
2
 
3
- # require 'spec_helper'
4
-
5
- # RSpec.describe BoletoSimples::Configuration do
6
- # describe 'defaults' do
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
- # it do
16
- # expect(subject.environment).to eq(:sandbox)
17
- # expect(subject.base_uri).to eq('https://api-sandbox.kobana.com.br/v1')
18
- # expect(subject.cache).to be_nil
19
- # expect(subject.user_agent).to be_nil
20
- # end
21
- # end
22
-
23
- # describe 'environment variables' do
24
- # subject { BoletoSimples.configuration }
25
-
26
- # before do
27
- # stub_env('BOLETOSIMPLES_ENV', 'production')
28
- # stub_env('BOLETOSIMPLES_USER_AGENT', 'email@minhaempresa.com.br')
29
- # BoletoSimples.configure
30
- # end
31
-
32
- # it do
33
- # expect(subject.environment).to eq(:production)
34
- # expect(subject.base_uri).to eq('https://api.kobana.com.br/v1')
35
- # expect(subject.user_agent).to eq('email@minhaempresa.com.br')
36
- # end
37
-
38
- # describe 'cache' do
39
- # it do
40
- # expect(subject.cache).to be_nil
41
- # expect(Her::API.default_api.connection.builder.handlers).not_to include(Faraday::HttpCache)
42
- # end
43
- # end
44
- # end
45
-
46
- # describe 'configuration' do
47
- # subject { BoletoSimples.configuration }
48
-
49
- # let(:cache_object) { double('Dalli') }
50
-
51
- # before do
52
- # BoletoSimples.configure do |c|
53
- # c.environment = :production
54
- # c.cache = cache_object
55
- # c.user_agent = 'Meu agent'
56
- # end
57
- # end
58
-
59
- # it do
60
- # expect(subject.environment).to eq(:production)
61
- # expect(subject.user_agent).to eq('Meu agent')
62
- # expect(subject.base_uri).to eq('https://api.kobana.com.br/v1')
63
- # end
64
-
65
- # describe 'cache' do
66
- # it do
67
- # expect(subject.cache).to eq(cache_object)
68
- # expect(Her::API.default_api.connection.builder.handlers).to include(Faraday::HttpCache)
69
- # end
70
- # end
71
- # end
72
- # end
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe BoletoSimples::Configuration do
6
+ describe 'defaults' do
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
26
+ end
27
+
28
+ describe 'environment variables' do
29
+ subject { BoletoSimples.configuration }
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
+
47
+ describe 'cache' do
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
52
+ end
53
+ end
54
+
55
+ describe 'configuration' do
56
+ subject { BoletoSimples.configuration }
57
+
58
+ let(:cache_object) { double('Dalli') }
59
+
60
+ before do
61
+ BoletoSimples.configure do |c|
62
+ c.environment = :production
63
+ c.cache = cache_object
64
+ c.user_agent = 'Meu agent'
65
+ c.custom_headers = {
66
+ 'X-CUSTOM' => 'CONTENT'
67
+ }
68
+ end
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)
86
+ end
87
+ end
88
+ end
89
+ end
@@ -12,6 +12,7 @@ RSpec.describe BoletoSimples::LastRequest do
12
12
  expect(subject).to be_kind_of(described_class)
13
13
  expect(subject.body).to be_kind_of(Array)
14
14
  expect(subject.body.first).to be_kind_of(Hash)
15
+ expect(subject.request_headers).to be_kind_of(Hash)
15
16
  expect(subject.response_headers).to be_kind_of(Hash)
16
17
  expect(subject.total).to be_kind_of(Integer)
17
18
  expect(subject.ratelimit_limit).to be_kind_of(Integer)
@@ -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,3 +1,3 @@
1
- 02RETORNO01COBRANCA 16511300049999999999 SISTEMAS S.A 033SANTANDER 20032000000000009483012 325000001
2
- 1027879661300014165199000999990009999 04958535 510200320495853 0495853500 12111900000000300350331651901000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 N 200320 SOLUCOES DIGITAIS L 00000000000000000000000000000000000000000C 325000002
3
- 9201033 000025050000053763329700000518 000000000000000000000000000000 000000000000000000000000000000 325000632
1
+ 02RETORNO01COBRANCA 16511300049999999999 SISTEMAS S.A 033SANTANDER 20032000000000009483012 325000001
2
+ 1027879661300014165199000999990009999 04958535 510200320495853 0495853500 12111900000000300350331651901000000000003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 N 200320 SOLUCOES DIGITAIS L 00000000000000000000000000000000000000000C 325000002
3
+ 9201033 000025050000053763329700000518 000000000000000000000000000000 000000000000000000000000000000 325000632
@@ -0,0 +1,113 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api-sandbox.kobana.com.br/v1/bank_billets?page=2
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Authorization:
11
+ - Bearer BOLETOSIMPLES_API_TOKEN
12
+ X-Custom:
13
+ - CONTENT
14
+ Accept:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Server:
32
+ - Cowboy
33
+ X-Frame-Options:
34
+ - DENY
35
+ X-Xss-Protection:
36
+ - 1; mode=block
37
+ X-Content-Type-Options:
38
+ - nosniff
39
+ X-Download-Options:
40
+ - noopen
41
+ X-Permitted-Cross-Domain-Policies:
42
+ - none
43
+ Referrer-Policy:
44
+ - strict-origin-when-cross-origin
45
+ Expect-Ct:
46
+ - max-age=0, report-uri="https://boletosimples.report-uri.com/r/d/ct/reportOnly"
47
+ Cross-Origin-Resource-Policy:
48
+ - cross-origin
49
+ Cross-Origin-Embedder-Policy:
50
+ - unsafe-none
51
+ Cross-Origin-Opener-Policy:
52
+ - unsafe-none
53
+ Link:
54
+ - <https://api-sandbox.kobana.com.br/api/v1/bank_billets?page=1>; rel="first",
55
+ <https://api-sandbox.kobana.com.br/api/v1/bank_billets?page=>; rel="prev",
56
+ <https://api-sandbox.kobana.com.br/api/v1/bank_billets?page=>; rel="next"
57
+ Per-Page:
58
+ - '50'
59
+ Page:
60
+ - '2'
61
+ X-Ratelimit-Limit:
62
+ - '60'
63
+ X-Ratelimit-Remaining:
64
+ - '59'
65
+ Etag:
66
+ - W/"4f53cda18c2baa0c0354bb5f9a3ecbe5"
67
+ Cache-Control:
68
+ - must-revalidate, private, max-age=0
69
+ Content-Security-Policy-Report-Only:
70
+ - 'default-src ''self'' https: app-sandbox.kobana.com.br; font-src ''self''
71
+ https: data: app-sandbox.kobana.com.br fonts.googleapis.com fonts.gstatic.com
72
+ themes.googleusercontent.com; img-src ''self'' https: data: maps.googleapis.com
73
+ bole.test:5001 bole.to www.google-analytics.com boletosimples-sandbox.s3.amazonaws.com
74
+ d3caatrp30sdc5.cloudfront.net; object-src ''self'' https: app-sandbox.kobana.com.br;
75
+ media-src ''self'' https: data: app-sandbox.kobana.com.br; script-src ''self''
76
+ https: ''unsafe-inline'' app-sandbox.kobana.com.br zapier.com www.google-analytics.com
77
+ www.googleadservices.com app.popupdomination.com js-agent.newrelic.com doug1izaerwt3.cloudfront.net
78
+ cdn.ywxi.net bam.nr-data.net cdnjs.cloudflare.com widget.pluga.co www.google.com
79
+ www.gstatic.com cdn.mxpnl.com cdn.amplitude.com www.draw.io; style-src ''self''
80
+ https: ''unsafe-inline'' app-sandbox.kobana.com.br fonts.googleapis.com; child-src
81
+ ''self'' app-sandbox.kobana.com.br www.googleadservices.com docs.google.com
82
+ googleads.g.doubleclick.net www.google.com www.google.com.br app.popupdomination.com
83
+ bid.g.doubleclick.net widget.pluga.co www.googletagmanager.com www.facebook.com
84
+ www.youtube.com; connect-src ''self'' https: ws: wss: boletosimples.com.br
85
+ *.boletosimples.com.br kobana.com.br *.kobana.com.br api.mixpanel.com *.cloudfront.net
86
+ *.google-analytics.com *.amplitude.com; report-uri https://boletosimples.report-uri.com/r/d/csp/reportOnly'
87
+ X-Request-Id:
88
+ - 97404e79-3ee9-4b3b-ac85-73bf55a49eb9
89
+ X-Runtime:
90
+ - '0.031604'
91
+ Date:
92
+ - Mon, 16 May 2022 01:47:15 GMT
93
+ X-Rack-Cache:
94
+ - miss
95
+ Strict-Transport-Security:
96
+ - max-age=31556952; includeSubDomains; preload
97
+ Vary:
98
+ - Origin,Accept-Encoding
99
+ X-Rack-Cors:
100
+ - miss; no-origin
101
+ Via:
102
+ - 1.1 vegur, 1.1 5d90b9fb6ab804caa33b8aa5260094e8.cloudfront.net (CloudFront)
103
+ X-Cache:
104
+ - Miss from cloudfront
105
+ X-Amz-Cf-Pop:
106
+ - BOS50-C3
107
+ X-Amz-Cf-Id:
108
+ - BgmGgAdTdYoBOyDh0-HynXgB_vgYgX8s41CtoUxRaGOuAtdOJer_-A==
109
+ body:
110
+ encoding: UTF-8
111
+ string: "[]"
112
+ recorded_at: Mon, 16 May 2022 01:47:14 GMT
113
+ recorded_with: VCR 6.1.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boletosimples
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kivanio Barbosa
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-02-22 00:00:00.000000000 Z
13
+ date: 2022-05-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday-http-cache
@@ -70,6 +70,7 @@ files:
70
70
  - lib/boletosimples/configuration.rb
71
71
  - lib/boletosimples/last_request.rb
72
72
  - lib/boletosimples/middlewares/bearer.rb
73
+ - lib/boletosimples/middlewares/custom_headers.rb
73
74
  - lib/boletosimples/middlewares/debug.rb
74
75
  - lib/boletosimples/middlewares/last_request.rb
75
76
  - lib/boletosimples/middlewares/raise_error.rb
@@ -97,6 +98,7 @@ files:
97
98
  - lib/boletosimples/version.rb
98
99
  - spec/boletosimples/configuration_spec.rb
99
100
  - spec/boletosimples/last_request_spec.rb
101
+ - spec/boletosimples/middlewares/custom_headers_spec.rb
100
102
  - spec/boletosimples/resources/bank_billet_account_spec.rb
101
103
  - spec/boletosimples/resources/bank_billet_discharge_spec.rb
102
104
  - spec/boletosimples/resources/bank_billet_payment_spec.rb
@@ -118,6 +120,7 @@ files:
118
120
  - spec/fixtures/customer_imports.csv
119
121
  - spec/fixtures/customer_subscription_imports.csv
120
122
  - spec/fixtures/discharge.RET
123
+ - spec/fixtures/vcr_cassettes/custom_headers.yml
121
124
  - spec/fixtures/vcr_cassettes/last_request/bank_billets.yml
122
125
  - spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml
123
126
  - spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/success.yml
@@ -194,13 +197,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
197
  - !ruby/object:Gem::Version
195
198
  version: '0'
196
199
  requirements: []
197
- rubygems_version: 3.2.32
200
+ rubygems_version: 3.3.7
198
201
  signing_key:
199
202
  specification_version: 4
200
203
  summary: Boleto Simples API wrapper.
201
204
  test_files:
202
205
  - spec/boletosimples/configuration_spec.rb
203
206
  - spec/boletosimples/last_request_spec.rb
207
+ - spec/boletosimples/middlewares/custom_headers_spec.rb
204
208
  - spec/boletosimples/resources/bank_billet_account_spec.rb
205
209
  - spec/boletosimples/resources/bank_billet_discharge_spec.rb
206
210
  - spec/boletosimples/resources/bank_billet_payment_spec.rb
@@ -222,6 +226,7 @@ test_files:
222
226
  - spec/fixtures/customer_imports.csv
223
227
  - spec/fixtures/customer_subscription_imports.csv
224
228
  - spec/fixtures/discharge.RET
229
+ - spec/fixtures/vcr_cassettes/custom_headers.yml
225
230
  - spec/fixtures/vcr_cassettes/last_request/bank_billets.yml
226
231
  - spec/fixtures/vcr_cassettes/resources/bank_billet/all.yml
227
232
  - spec/fixtures/vcr_cassettes/resources/bank_billet/cancel/success.yml