iron_bank 1.0.2 → 1.0.3

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: db077e1c6186fc1a24bd7d1ae7cf06e6c9c02a85acb8a651e6c5c84e7a3972c7
4
- data.tar.gz: 84903d8e3515bd8b48b192e32d1cfc6293a7d0c99ea709c4c7106d609db646cd
3
+ metadata.gz: bd43b9afdef13f46266c47a431904c61180c1444c1a31e927a199f423ed0fd4d
4
+ data.tar.gz: 519f3d3d3b33047f8647f00d5480e33c0c7d626656c458082e01d2b975875275
5
5
  SHA512:
6
- metadata.gz: 8afcf559e8a4a0b7c0a70bb4d8faabf179a394a939c6993ae0cdea76c06a1a5f3bf889201af394169e71b1ee119f394460a7c0e5636084198993e847f7d3f82b
7
- data.tar.gz: f9aa741b2ea5b469512e5285db6ecf19fc8c63762b4581bdb29e7803b8b53a3a7dbf3d8dc059bd609d219619c5f7d21dd6a35c5e7ec14eaee08effc3b9ed9de4
6
+ metadata.gz: 7b3367c199eec9ae32daaa5c444f8c578c8d14f639688c05b97fadffd9504df7a502d403f49ea8fc1650c61ab50b698928f2c9f51826e821633b019e4b5cea01
7
+ data.tar.gz: 01a91a2311290dbbb7fdffe7203f94d5c33e26124b5ad19a9b568ae3f6f4144f4bbfecec29a7b88d3b5f6d7059c31f18c80827b8f5a6db1f039680a537cc5a3a
@@ -1,5 +1,3 @@
1
- cc: :whale2: @zendesk/billing
2
-
3
1
  ### Description
4
2
  Describe what your changes are and what is the motivation behind them.
5
3
 
@@ -11,10 +9,5 @@ to be aware of.
11
9
  - [ ] TODO item before it can be reviewed and/or merged
12
10
  - [ ] Another TODO item
13
11
 
14
- ### References
15
- - JIRA ticket or PR link
16
- - Another JIRA ticket or PR link
17
-
18
12
  ### Risks
19
- **High.** Because reasons. Use **High**, **Medium**, or **Low** to indicate risk
20
- profile of the change.
13
+ Use **High**, **Medium**, or **Low** to indicate risk profile of the change.
data/.reek CHANGED
@@ -42,6 +42,10 @@ FeatureEnvy:
42
42
  - IronBank::Actions::Subscribe#hash_args
43
43
  - IronBank::Utils#camelize
44
44
 
45
+ InstanceVariableAssumption:
46
+ exclude:
47
+ - IronBank::FaradayMiddleware::RetriableAuth
48
+
45
49
  IrresponsibleModule:
46
50
  exclude:
47
51
  - Sample
@@ -44,8 +44,10 @@ module IronBank
44
44
  @connection ||= Faraday.new(faraday_config) do |conn|
45
45
  conn.use :ddtrace, open_tracing_options if open_tracing_enabled?
46
46
  conn.use instrumenter, instrumenter_options if instrumenter
47
- conn.use IronBank::Response::RaiseError
47
+ conn.use :raise_error
48
48
  conn.request :json
49
+ conn.request :retry, max: 2, retry_statuses: [401]
50
+ conn.request :retriable_auth, auth
49
51
  conn.response :logger, IronBank.logger
50
52
  conn.response :json, content_type: /\bjson$/
51
53
  conn.adapter Faraday.default_adapter
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # IronBank main module
3
4
  module IronBank
4
- # Faraday response middleware
5
- module Response
5
+ # IronBank Faraday middleware module
6
+ module FaradayMiddleware
6
7
  # This class raises an exception based on the HTTP status code and the
7
8
  # `success` flag (if present in the response) from Zuora.
8
9
  class RaiseError < Faraday::Response::Middleware
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # IronBank main module
4
+ module IronBank
5
+ # IronBank Faraday middleware module
6
+ module FaradayMiddleware
7
+ # This middleware reauthorize the request on unauthorized request
8
+ class RetriableAuth < Faraday::Middleware
9
+ def initialize(app, auth)
10
+ @auth = auth
11
+ super(app)
12
+ end
13
+
14
+ def call(env)
15
+ @env = env
16
+ renew_auth_header if env.status == 401
17
+
18
+ @app.call(env)
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :auth, :env
24
+
25
+ def renew_auth_header
26
+ auth.renew_session
27
+
28
+ # The :retry middleware use cached request's headers which doesn't retry
29
+ # the request headers automatically
30
+ env.request_headers = env.request_headers.merge(auth.header)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # IronBank main module
4
+ module IronBank
5
+ # IronBank Faraday middleware module
6
+ module FaradayMiddleware
7
+ if Faraday::Middleware.respond_to? :register_middleware
8
+ Faraday::Middleware.register_middleware \
9
+ raise_error: -> { RaiseError }
10
+
11
+ Faraday::Request.register_middleware \
12
+ retriable_auth: -> { RetriableAuth }
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IronBank
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.3'
5
5
  API_VERSION = 'v1'
6
6
  end
data/lib/iron_bank.rb CHANGED
@@ -57,7 +57,9 @@ require 'iron_bank/utils'
57
57
  require 'iron_bank/version'
58
58
  require 'iron_bank/csv'
59
59
  require 'iron_bank/error'
60
- require 'iron_bank/response/raise_error'
60
+ require 'iron_bank/faraday_middleware/raise_error'
61
+ require 'iron_bank/faraday_middleware/retriable_auth'
62
+ require 'iron_bank/faraday_middleware'
61
63
 
62
64
  # Helpers
63
65
  require 'iron_bank/open_tracing'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_bank
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickael Pham
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2018-10-05 00:00:00.000000000 Z
14
+ date: 2018-10-11 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bump
@@ -319,6 +319,9 @@ files:
319
319
  - lib/iron_bank/describe/tenant.rb
320
320
  - lib/iron_bank/endpoint.rb
321
321
  - lib/iron_bank/error.rb
322
+ - lib/iron_bank/faraday_middleware.rb
323
+ - lib/iron_bank/faraday_middleware/raise_error.rb
324
+ - lib/iron_bank/faraday_middleware/retriable_auth.rb
322
325
  - lib/iron_bank/instrumentation.rb
323
326
  - lib/iron_bank/local.rb
324
327
  - lib/iron_bank/local_records.rb
@@ -354,7 +357,6 @@ files:
354
357
  - lib/iron_bank/resources/rate_plan_charge_tier.rb
355
358
  - lib/iron_bank/resources/subscription.rb
356
359
  - lib/iron_bank/resources/usage.rb
357
- - lib/iron_bank/response/raise_error.rb
358
360
  - lib/iron_bank/schema.rb
359
361
  - lib/iron_bank/utils.rb
360
362
  - lib/iron_bank/version.rb