oauth2_api_client 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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +4 -1
- data/lib/oauth2_api_client.rb +1 -1
- data/lib/oauth2_api_client/http_error.rb +17 -3
- data/lib/oauth2_api_client/version.rb +1 -1
- data/spec/oauth2_api_client/http_error_spec.rb +11 -0
- data/spec/oauth2_api_client_spec.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09a8c7819bfff19e85236301e161cf9481d4f53357bc9952084e5582d509337c'
|
4
|
+
data.tar.gz: d047883ee8e1fd35ff7ffce55f0983653dc862050e1aea786ee410259fbc44d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e52fed4a4c43fa3cc4db0ddc9d0cd6fc0e628b65a0aeaa1b50b9761c7774e8f72d8b08e0eba8ccce6cb69032da9ef92eedb5edb3fb5aa988b6ab5f9ce5527584
|
7
|
+
data.tar.gz: 1ebf22539000c9fb75ca536bc71f59e0476d4ce99c5236c1752d793e6a25fd428f996aae6d9b8cc544f1852f213f7481020d9ff6a8c582369ae26b75aa2dfa7b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](http://travis-ci.org/mrkamel/oauth2_api_client)
|
4
4
|
[](http://badge.fury.io/rb/oauth2_api_client)
|
5
5
|
|
6
|
-
Oauth2ApiClient is small, but powerful client around
|
6
|
+
Oauth2ApiClient is a small, but powerful client around
|
7
7
|
[oauth2](https://github.com/oauth-xx/oauth2) and
|
8
8
|
[http-rb](https://github.com/httprb/http) to interact with APIs which use
|
9
9
|
oauth2 for authentication.
|
@@ -33,6 +33,9 @@ client = Oauth2ApiClient.new(
|
|
33
33
|
)
|
34
34
|
```
|
35
35
|
|
36
|
+
Please note, `get`, `post`, `put`, etc. will raise `Oauth2ApiClient::HttpError`
|
37
|
+
unless the response code is 2xx.
|
38
|
+
|
36
39
|
## Install
|
37
40
|
|
38
41
|
Add this line to your application's Gemfile:
|
data/lib/oauth2_api_client.rb
CHANGED
@@ -1,10 +1,24 @@
|
|
1
1
|
class Oauth2ApiClient
|
2
|
+
# The HttpError class is the main exception class of Oauth2ApiClient and is
|
3
|
+
# raised when a request fails with some status code other than 2xx. Using
|
4
|
+
# the exception object, you still have access to the response.
|
5
|
+
#
|
6
|
+
# @example
|
7
|
+
# begin
|
8
|
+
# client.post("/orders", json: { address: "..." })
|
9
|
+
# rescue Oauth2ApiClient::HttpError => e
|
10
|
+
# e.response # => HTTP::Response
|
11
|
+
# end
|
12
|
+
|
2
13
|
class HttpError < StandardError
|
3
|
-
attr_reader :
|
14
|
+
attr_reader :response
|
4
15
|
|
5
|
-
def initialize(
|
6
|
-
@message = message
|
16
|
+
def initialize(response)
|
7
17
|
@response = response
|
8
18
|
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"#{self.class.name} (#{response.code}): #{response.body}"
|
22
|
+
end
|
9
23
|
end
|
10
24
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path("../spec_helper", __dir__)
|
2
|
+
|
3
|
+
RSpec.describe Oauth2ApiClient::HttpError do
|
4
|
+
describe "#to_s" do
|
5
|
+
it "returns the message" do
|
6
|
+
response = double(code: 401, body: "unauthorized")
|
7
|
+
|
8
|
+
expect(described_class.new(response).to_s).to eq("Oauth2ApiClient::HttpError (401): unauthorized")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
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: 2.
|
4
|
+
version: 2.1.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: 2020-
|
11
|
+
date: 2020-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- lib/oauth2_api_client/token_provider.rb
|
158
158
|
- lib/oauth2_api_client/version.rb
|
159
159
|
- oauth2_api_client.gemspec
|
160
|
+
- spec/oauth2_api_client/http_error_spec.rb
|
160
161
|
- spec/oauth2_api_client/token_provider_spec.rb
|
161
162
|
- spec/oauth2_api_client_spec.rb
|
162
163
|
- spec/spec_helper.rb
|
@@ -184,6 +185,7 @@ signing_key:
|
|
184
185
|
specification_version: 4
|
185
186
|
summary: Small but powerful client around oauth2 and http-rb to interact with APIs
|
186
187
|
test_files:
|
188
|
+
- spec/oauth2_api_client/http_error_spec.rb
|
187
189
|
- spec/oauth2_api_client/token_provider_spec.rb
|
188
190
|
- spec/oauth2_api_client_spec.rb
|
189
191
|
- spec/spec_helper.rb
|