oauth2_api_client 2.0.0 → 2.1.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: cb758d909c7cbeae49beef096ef7b8b0eedb5e038c8a403fac15388d6fc71884
4
- data.tar.gz: 86186e7192b22b2fddb16e6bd03c005efbe58d3f159585ef8ad2ec1cd9a79d4b
3
+ metadata.gz: '09a8c7819bfff19e85236301e161cf9481d4f53357bc9952084e5582d509337c'
4
+ data.tar.gz: d047883ee8e1fd35ff7ffce55f0983653dc862050e1aea786ee410259fbc44d1
5
5
  SHA512:
6
- metadata.gz: 5cbb79317198bd5c8bf2e3139ee5646be1d035ef7a95950ed05e0b35aad4b8bde1556b80294e73ee2c3823e6ce863fbc09ce26989fb6677b81fed0157c04aae6
7
- data.tar.gz: ce5ef6661c8226f38770f2abc8cae7f33bc6b5efb6eaac11819fd8848ab084cc236374797d92c5d505a4d2142a6e677b0d17f1e2c0d0d910fb44b201bdf0537c
6
+ metadata.gz: e52fed4a4c43fa3cc4db0ddc9d0cd6fc0e628b65a0aeaa1b50b9761c7774e8f72d8b08e0eba8ccce6cb69032da9ef92eedb5edb3fb5aa988b6ab5f9ce5527584
7
+ data.tar.gz: 1ebf22539000c9fb75ca536bc71f59e0476d4ce99c5236c1752d793e6a25fd428f996aae6d9b8cc544f1852f213f7481020d9ff6a8c582369ae26b75aa2dfa7b
@@ -1,6 +1,10 @@
1
1
 
2
2
  # CHANGELOG
3
3
 
4
+ # v2.1.0
5
+
6
+ * Include the response code and body in `HttpError#to_s`
7
+
4
8
  # v2.0.0
5
9
 
6
10
  * `TokenProvider` added
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build Status](https://secure.travis-ci.org/mrkamel/oauth2_api_client.svg?branch=master)](http://travis-ci.org/mrkamel/oauth2_api_client)
4
4
  [![Gem Version](https://badge.fury.io/rb/oauth2_api_client.svg)](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:
@@ -79,7 +79,7 @@ class Oauth2ApiClient
79
79
 
80
80
  return response if response.status.success?
81
81
 
82
- raise HttpError.new(response.status.to_s, response)
82
+ raise HttpError, response
83
83
  end
84
84
  end
85
85
 
@@ -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 :message, :response
14
+ attr_reader :response
4
15
 
5
- def initialize(message, response)
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
@@ -1,3 +1,3 @@
1
1
  class Oauth2ApiClient
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  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
@@ -123,7 +123,7 @@ RSpec.describe Oauth2ApiClient do
123
123
  )
124
124
  )
125
125
 
126
- expect { client.get("/path") }.to raise_error(described_class::HttpError)
126
+ expect { client.get("/path") }.to raise_error("Oauth2ApiClient::HttpError (401): unauthorized")
127
127
  end
128
128
  end
129
129
  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.0.0
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-06-21 00:00:00.000000000 Z
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