oauth2_api_client 3.4.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9361c724e72de0bbebb82eb1d3a70d62bf9c12488d665eea40ad25c090ab2ed0
4
- data.tar.gz: a025968d9268a17b2fce69056575e48b3133f2621042f0e682d711d9dc4319ad
3
+ metadata.gz: 71751084c3e42bbdea2ccd3aae3e33716c4cea4d175ef709474de146c94dc7b8
4
+ data.tar.gz: 78c01d8725a63ad148f3ffa9570f9524a5496bd35c901212cefcbd02f18b4cb7
5
5
  SHA512:
6
- metadata.gz: df519ea81f617078eb44f734de18e3543f1d44fcc0db2be030436401c3e504f11b8ed54b5eb5bf0a57af744bec36678bf52f9daa055b51b9ee48e27bc7d340db
7
- data.tar.gz: a2eec2a4d5ad53fcda9386e890d5cf7067410a6e5452a5263206ae6bfe62c8b122c829bee140090e742ba5d151e8a2ce11bae5df0515ca6449605033b248f6d8
6
+ metadata.gz: 48c6453955a713e5d144e7788c4c970dc3405801410525b9d561c2bc7ede63556dfaf737221f27b38edf37c0342c029c6c17f8c03b2d87ac334d1fa88d125d19
7
+ data.tar.gz: a62a3aa0814ed3dd096a37ea6ad7ebc7ef304445bbfd7e70fe282e85c060c77607923a08bdbc6f4074bae62e34be56a3731d7e3024f908a61c1f3d14cbff6aba
@@ -15,7 +15,6 @@ jobs:
15
15
  - uses: ruby/setup-ruby@v1
16
16
  with:
17
17
  ruby-version: ${{ matrix.ruby }}
18
- - run: gem install bundler
19
18
  - run: bundle
20
19
  - run: bundle exec rspec
21
20
  - run: bundle exec rubocop
data/CHANGELOG.md CHANGED
@@ -1,6 +1,32 @@
1
1
 
2
2
  # CHANGELOG
3
3
 
4
+ # v4.0.0
5
+
6
+ * [BREAKING] Rescue `HTTP::Error` and raise `Oauth2ApiClient::Error` instead
7
+
8
+ In case you currently use:
9
+
10
+ ```ruby
11
+ begin
12
+ client = Oauth2ApiClient.new(base_url: "...")
13
+ client.get("...")
14
+ rescue HTTP::Error # or HTTP::ConnectionError, etc.
15
+ # ...
16
+ end
17
+ ```
18
+
19
+ please change it to:
20
+
21
+ ```ruby
22
+ begin
23
+ client = Oauth2ApiClient.new(base_url: "...")
24
+ client.get("...")
25
+ rescue Oauth2ApiClient::Error
26
+ # ...
27
+ end
28
+ ```
29
+
4
30
  # v3.4.1
5
31
 
6
32
  * fix duplicate auth calls if NullStore is used
@@ -15,7 +15,9 @@ class Oauth2ApiClient
15
15
  # # ...
16
16
  # end
17
17
 
18
- class ResponseError < StandardError
18
+ class Error < StandardError; end
19
+
20
+ class ResponseError < Error
19
21
  STATUSES = {
20
22
  400 => "Bad Request",
21
23
  401 => "Unauthorized",
@@ -93,7 +95,7 @@ class Oauth2ApiClient
93
95
  message.gsub(/[^a-zA-Z0-9]/, "")
94
96
  end
95
97
 
96
- STATUSES.each do |_code, message|
98
+ STATUSES.each_value do |message|
97
99
  const_set(const_name(message), Class.new(self))
98
100
  end
99
101
  end
@@ -1,3 +1,3 @@
1
1
  class Oauth2ApiClient
2
- VERSION = "3.4.1"
2
+ VERSION = "4.0.0"
3
3
  end
@@ -4,7 +4,7 @@ require "http"
4
4
  require "active_support"
5
5
 
6
6
  require "oauth2_api_client/version"
7
- require "oauth2_api_client/response_error"
7
+ require "oauth2_api_client/errors"
8
8
  require "oauth2_api_client/token_provider"
9
9
 
10
10
  # The Oauth2ApiClient class is a client wrapped around the oauth2 and http-rb
@@ -91,7 +91,12 @@ class Oauth2ApiClient
91
91
  opts = options.dup
92
92
  opts[:params] = @params.merge(opts.fetch(:params, {})) if @params
93
93
 
94
- response = request.send(verb, "#{@base_url}#{path}", opts)
94
+ response =
95
+ begin
96
+ request.send(verb, "#{@base_url}#{path}", opts)
97
+ rescue HTTP::Error => e
98
+ raise Error, e.message
99
+ end
95
100
 
96
101
  return response if response.status.success?
97
102
 
@@ -222,5 +222,13 @@ RSpec.describe Oauth2ApiClient do
222
222
 
223
223
  expect { client.get("/path") }.to raise_error("Oauth2ApiClient::ResponseError::Unauthorized (401, http://localhost/api/path): unauthorized")
224
224
  end
225
+
226
+ it "rescues HTTP::Error and raises a Oauth2ApiClient::Error instead" do
227
+ stub_request(:get, "http://localhost/api/path").to_raise(HTTP::Error.new("error"))
228
+
229
+ client = described_class.new(base_url: "http://localhost/api", token: "token")
230
+
231
+ expect { client.get("/path") }.to raise_error(Oauth2ApiClient::Error, "error")
232
+ end
225
233
  end
226
234
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth2_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.1
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Vetter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-25 00:00:00.000000000 Z
11
+ date: 2024-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -83,7 +83,7 @@ files:
83
83
  - README.md
84
84
  - Rakefile
85
85
  - lib/oauth2_api_client.rb
86
- - lib/oauth2_api_client/response_error.rb
86
+ - lib/oauth2_api_client/errors.rb
87
87
  - lib/oauth2_api_client/token_provider.rb
88
88
  - lib/oauth2_api_client/version.rb
89
89
  - oauth2_api_client.gemspec