rest-client-wrapper 4.0.0 → 5.0.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.
metadata CHANGED
@@ -1,145 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-client-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - University of Adelaide
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-21 00:00:00.000000000 Z
11
+ date: 2023-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 1.8.3
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 1.8.3
27
- - !ruby/object:Gem::Dependency
28
- name: oauth2
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '1.2'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '1.2'
41
- - !ruby/object:Gem::Dependency
42
- name: rack
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 2.0.5
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 2.0.5
55
- - !ruby/object:Gem::Dependency
56
- name: rest-client
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: 2.0.2
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: 2.0.2
69
- - !ruby/object:Gem::Dependency
70
- name: typhoeus
71
15
  requirement: !ruby/object:Gem::Requirement
72
16
  requirements:
73
17
  - - "~>"
74
18
  - !ruby/object:Gem::Version
75
- version: '1.0'
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: 1.0.1
19
+ version: 2.6.3
79
20
  type: :runtime
80
21
  prerelease: false
81
22
  version_requirements: !ruby/object:Gem::Requirement
82
23
  requirements:
83
24
  - - "~>"
84
25
  - !ruby/object:Gem::Version
85
- version: '1.0'
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: 1.0.1
26
+ version: 2.6.3
89
27
  - !ruby/object:Gem::Dependency
90
- name: colorize
28
+ name: oauth2
91
29
  requirement: !ruby/object:Gem::Requirement
92
30
  requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: 0.7.0
96
31
  - - "~>"
97
32
  - !ruby/object:Gem::Version
98
- version: '0.7'
99
- type: :development
33
+ version: 2.0.9
34
+ type: :runtime
100
35
  prerelease: false
101
36
  version_requirements: !ruby/object:Gem::Requirement
102
37
  requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: 0.7.0
106
38
  - - "~>"
107
39
  - !ruby/object:Gem::Version
108
- version: '0.7'
40
+ version: 2.0.9
109
41
  - !ruby/object:Gem::Dependency
110
- name: geminabox
42
+ name: rest-client
111
43
  requirement: !ruby/object:Gem::Requirement
112
44
  requirements:
113
45
  - - "~>"
114
46
  - !ruby/object:Gem::Version
115
- version: 0.13.0
116
- type: :development
47
+ version: 2.1.0
48
+ type: :runtime
117
49
  prerelease: false
118
50
  version_requirements: !ruby/object:Gem::Requirement
119
51
  requirements:
120
52
  - - "~>"
121
53
  - !ruby/object:Gem::Version
122
- version: 0.13.0
54
+ version: 2.1.0
123
55
  - !ruby/object:Gem::Dependency
124
- name: rspec
56
+ name: typhoeus
125
57
  requirement: !ruby/object:Gem::Requirement
126
58
  requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- version: 3.4.0
130
59
  - - "~>"
131
60
  - !ruby/object:Gem::Version
132
- version: '3.4'
133
- type: :development
61
+ version: '1.4'
62
+ type: :runtime
134
63
  prerelease: false
135
64
  version_requirements: !ruby/object:Gem::Requirement
136
65
  requirements:
137
- - - ">="
138
- - !ruby/object:Gem::Version
139
- version: 3.4.0
140
66
  - - "~>"
141
67
  - !ruby/object:Gem::Version
142
- version: '3.4'
68
+ version: '1.4'
143
69
  description: Generic REST client wrapper
144
70
  email:
145
71
  - myuni.admin@adelaide.edu.au
@@ -167,19 +93,12 @@ files:
167
93
  - lib/rest_client_wrapper/rest_client.rb
168
94
  - lib/rest_client_wrapper/version.rb
169
95
  - rest-client-wrapper.gemspec
170
- - spec/authenticators/oauth_spec.rb
171
- - spec/factories/request.rb
172
- - spec/factories/response.rb
173
- - spec/request_spec.rb
174
- - spec/rest_client_spec.rb
175
- - spec/spec_helper.rb
176
- - spec/support/factory_bot.rb
177
- - spec/support/stub_helper.rb
178
96
  homepage: https://github.com/universityofadelaide/rest-client-wrapper
179
97
  licenses:
180
98
  - GPL 3.0
181
99
  metadata:
182
100
  allowed_push_host: https://rubygems.org
101
+ rubygems_mfa_required: 'true'
183
102
  post_install_message:
184
103
  rdoc_options: []
185
104
  require_paths:
@@ -188,23 +107,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
188
107
  requirements:
189
108
  - - ">="
190
109
  - !ruby/object:Gem::Version
191
- version: 2.6.0
110
+ version: 3.2.2
192
111
  required_rubygems_version: !ruby/object:Gem::Requirement
193
112
  requirements:
194
113
  - - ">="
195
114
  - !ruby/object:Gem::Version
196
115
  version: '0'
197
116
  requirements: []
198
- rubygems_version: 3.0.9
117
+ rubygems_version: 3.4.10
199
118
  signing_key:
200
119
  specification_version: 4
201
120
  summary: Rest client wrapper
202
- test_files:
203
- - spec/authenticators/oauth_spec.rb
204
- - spec/factories/response.rb
205
- - spec/factories/request.rb
206
- - spec/request_spec.rb
207
- - spec/rest_client_spec.rb
208
- - spec/spec_helper.rb
209
- - spec/support/factory_bot.rb
210
- - spec/support/stub_helper.rb
121
+ test_files: []
@@ -1,103 +0,0 @@
1
- # Copyright (C) 2019 The University of Adelaide
2
- #
3
- # This file is part of Rest-Client-Wrapper.
4
- #
5
- # Rest-Client-Wrapper is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # Rest-Client-Wrapper is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with Rest-Client-Wrapper. If not, see <http://www.gnu.org/licenses/>.
17
- #
18
-
19
- require "spec_helper"
20
-
21
- # Authenticator::Oauth Specs
22
- module RestClientWrapper
23
-
24
- describe Authenticator::Oauth do
25
-
26
- before(:context) do
27
- @client_id = "client_id"
28
- @client_secret = "client_secret"
29
- @api_token_uri = URI.parse("http://fake_oauth_token.com/token_url_path")
30
- end
31
-
32
- describe "::get_access_token" do
33
-
34
- before(:example) do
35
- WebMock.reset_executed_requests!
36
- @oauth = Authenticator::Oauth.new(
37
- {
38
- site: "#{ @api_token_uri.scheme }://#{ @api_token_uri.host }",
39
- token_url_path: @api_token_uri.path,
40
- client_id: @client_id,
41
- client_secret: @client_secret
42
- }
43
- )
44
- @current_token = FactoryBot.build(:token).token
45
- request = FactoryBot.build(:oauth_token_request, { headers: FactoryBot.build(:request_headers, { host: @api_token_uri.host }).to_h }).to_h
46
- response = FactoryBot.build(:auth_token_response).to_h
47
- @response_body = response[:body]
48
- response[:body] = lambda { |_request|
49
- sleep 1 # Simulate network latency.
50
- @response_body
51
- }
52
- @authenticate_request = stub_request(:post, @api_token_uri.to_s).with(request).to_return(response)
53
- end
54
-
55
- context "when multiple threads are trying to authenticate" do
56
-
57
- it "will only make one API request to renew the access token" do
58
- t1 = Thread.new do
59
- Authenticator::Oauth.authenticate({ client_id: @client_id })
60
- end
61
-
62
- sleep(1) # Give t1 a head start so that it can get the lock before t2 does
63
- t2 = Thread.new do
64
- Authenticator::Oauth.authenticate({ client_id: @client_id, access_token: @current_token })
65
- end
66
-
67
- t1.join
68
- t2.join
69
-
70
- parsed_response = JSON.parse(@response_body).symbolize_keys
71
-
72
- expect(@oauth.tokens[@client_id][:access_token]).to eq(parsed_response[:access_token])
73
- # Only expect one request as thread 1 (t1) has already got a new token thread 2 (t2) will use the new token.
74
- expect(@authenticate_request).to have_been_requested.times(1)
75
- end
76
-
77
- end
78
-
79
- context "when token is expired" do
80
-
81
- before(:example) do
82
- WebMock.reset_executed_requests!
83
- @expired_token = FactoryBot.build(:token).token
84
- @request = FactoryBot.build(:oauth_token_request, { headers: FactoryBot.build(:request_headers, { host: @api_token_uri.host }).to_h }).to_h
85
- @response = FactoryBot.build(:auth_token_response).to_h
86
- @authenticate_request = stub_request(:post, @api_token_uri.to_s).with(@request).to_return(@response)
87
- end
88
-
89
- it "will make an API call to get a new token" do
90
- Authenticator::Oauth.authenticate({ client_id: @client_id, access_token: @expired_token })
91
- parsed_response = JSON.parse(@response[:body]).symbolize_keys
92
-
93
- expect(@oauth.tokens[@client_id][:access_token]).to eq(parsed_response[:access_token])
94
- expect(@authenticate_request).to have_been_requested.times(1)
95
- end
96
-
97
- end
98
-
99
- end
100
-
101
- end
102
-
103
- end
@@ -1,48 +0,0 @@
1
- # Copyright (C) 2019 The University of Adelaide
2
- #
3
- # This file is part of Rest-Client-Wrapper.
4
- #
5
- # Rest-Client-Wrapper is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # Rest-Client-Wrapper is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with Rest-Client-Wrapper. If not, see <http://www.gnu.org/licenses/>.
17
- #
18
-
19
- FactoryBot.define do
20
- factory :request, { class: OpenStruct } do |f|
21
- skip_create
22
- f.body { FactoryBot.build(:request_body).to_h }
23
- f.headers { FactoryBot.build(:request_headers).to_h }
24
- end
25
-
26
- factory :oauth_token_request, { class: OpenStruct } do |f|
27
- skip_create
28
- f.body { FactoryBot.build(:oauth_request_body).to_h }
29
- f.headers { FactoryBot.build(:request_headers).to_h }
30
- end
31
-
32
- factory :oauth_request_body, { class: OpenStruct } do |f|
33
- skip_create
34
- f.client_id { "client_id" }
35
- f.client_secret { "client_secret" }
36
- f.grant_type { "client_credentials" }
37
- end
38
-
39
- factory :request_body, { class: OpenStruct } do |f|
40
- skip_create
41
- f.course_id { Faker::Hipster.sentence(5) }
42
- end
43
-
44
- factory :request_headers, { class: OpenStruct } do |f|
45
- skip_create
46
- f.host { "fake_oauth_token.com" }
47
- end
48
- end
@@ -1,47 +0,0 @@
1
- # Copyright (C) 2019 The University of Adelaide
2
- #
3
- # This file is part of Rest-Client-Wrapper.
4
- #
5
- # Rest-Client-Wrapper is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # Rest-Client-Wrapper is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with Rest-Client-Wrapper. If not, see <http://www.gnu.org/licenses/>.
17
- #
18
-
19
- FactoryBot.define do
20
- factory :auth_token_response, { class: OpenStruct } do |f|
21
- skip_create
22
- f.status { 200 }
23
- f.body { "{\"token_type\":\"Bearer\",\"access_token\":\"#{ FactoryBot.build(:token).token }\",\"expires_in\":3600,\"refresh_token\":\"#{ FactoryBot.build(:token).token }\"}" }
24
- f.headers { { content_type: "application/json; charset=utf-8" } }
25
- end
26
-
27
- factory :response, { class: OpenStruct } do |f|
28
- skip_create
29
- f.status { 200 }
30
- f.body { "{\"result\":\"success\"}" }
31
- f.headers { { content_type: "application/json; charset=utf-8" } }
32
- end
33
-
34
- factory :paginated_response, { class: OpenStruct } do |_f|
35
- status { 200 }
36
- body { "{\"result\":\"success\"}" }
37
- headers do
38
- { content_type: "application/json; charset=utf-8",
39
- link: "" }
40
- end
41
- end
42
-
43
- factory :token, { class: OpenStruct } do |f|
44
- skip_create
45
- f.token { Faker::Crypto.sha1 }
46
- end
47
- end
data/spec/request_spec.rb DELETED
@@ -1,185 +0,0 @@
1
- # Copyright (C) 2019 The University of Adelaide
2
- #
3
- # This file is part of Rest-Client-Wrapper.
4
- #
5
- # Rest-Client-Wrapper is free software: you can redistribute it and/or modify
6
- # it under the terms of the GNU General Public License as published by
7
- # the Free Software Foundation, either version 3 of the License, or
8
- # (at your option) any later version.
9
- #
10
- # Rest-Client-Wrapper is distributed in the hope that it will be useful,
11
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- # GNU General Public License for more details.
14
- #
15
- # You should have received a copy of the GNU General Public License
16
- # along with Rest-Client-Wrapper. If not, see <http://www.gnu.org/licenses/>.
17
- #
18
-
19
- require "spec_helper"
20
-
21
- # Request Specs
22
- module RestClientWrapper # rubocop:disable Metrics/ModuleLength
23
-
24
- describe Request do
25
- before(:context) do
26
- @api_uri = URI.parse("http://fake_site.com")
27
- @param_hash = { key: "value" }
28
- @non_hash_value = 1
29
- end
30
-
31
- describe "#http_method" do
32
-
33
- before(:example) do
34
- @non_http_method = :test
35
- @non_symbol_value = 1
36
- end
37
-
38
- context "when http_method is not a valid http method" do
39
-
40
- it "will raise TypeError" do
41
- expect { Request.new({ http_method: @non_http_method, uri: @api_uri }) }.to raise_error(ArgumentError)
42
- end
43
-
44
- end
45
-
46
- context "when http_method is not a symbol" do
47
-
48
- it "will raise TypeError" do
49
- expect { Request.new({ http_method: @non_symbol_value, uri: @api_uri }) }.to raise_error(TypeError)
50
- end
51
-
52
- end
53
-
54
- context "when http method :get is assigned" do
55
-
56
- it "value is assigned to request http_method" do
57
- request = Request.new({ http_method: :get, uri: @api_uri })
58
- expect(request.http_method).to eq(:get)
59
- end
60
-
61
- end
62
-
63
- context "when http method :post is assigned" do
64
-
65
- it "value is assigned to request http_method" do
66
- request = Request.new({ http_method: :post, uri: @api_uri })
67
- expect(request.http_method).to eq(:post)
68
- end
69
-
70
- end
71
-
72
- context "when http method :put is assigned" do
73
-
74
- it "value is assigned to request http_method" do
75
- request = Request.new({ http_method: :put, uri: @api_uri })
76
- expect(request.http_method).to eq(:put)
77
- end
78
-
79
- end
80
-
81
- context "when http method :delete is assigned" do
82
-
83
- it "value is assigned to request http_method" do
84
- request = Request.new({ http_method: :delete, uri: @api_uri })
85
- expect(request.http_method).to eq(:delete)
86
- end
87
-
88
- end
89
-
90
- context "when http method :connect is assigned" do
91
-
92
- it "value is assigned to request http_method" do
93
- request = Request.new({ http_method: :connect, uri: @api_uri })
94
- expect(request.http_method).to eq(:connect)
95
- end
96
-
97
- end
98
-
99
- context "when http method :options is assigned" do
100
-
101
- it "value is assigned to request http_method" do
102
- request = Request.new({ http_method: :options, uri: @api_uri })
103
- expect(request.http_method).to eq(:options)
104
- end
105
-
106
- end
107
-
108
- context "when http method :trace is assigned" do
109
-
110
- it "value is assigned to request http_method" do
111
- request = Request.new({ http_method: :trace, uri: @api_uri })
112
- expect(request.http_method).to eq(:trace)
113
- end
114
-
115
- end
116
-
117
- end
118
-
119
- describe "#segment_params" do
120
-
121
- context "when segment_params is not a hash" do
122
-
123
- it "will raise TypeError" do
124
- expect { Request.new({ http_method: :get, uri: @api_uri, segment_params: @non_hash_value }) }.to raise_error(TypeError)
125
- end
126
-
127
- end
128
-
129
- context "when segment_params is a hash" do
130
-
131
- it "value is assigned to request segment_params" do
132
- request = Request.new({ http_method: :get, uri: @api_uri, segment_params: @param_hash })
133
- expect(request.segment_params).to eq(@param_hash)
134
- end
135
-
136
- end
137
-
138
- end
139
-
140
- describe "#payload" do
141
-
142
- context "when payload is not a hash" do
143
-
144
- it "will raise TypeError" do
145
- expect { Request.new({ http_method: :put, uri: @api_uri, segment_params: @param_hash, payload: @non_hash_value }) }.to raise_error(TypeError)
146
- end
147
-
148
- end
149
-
150
- context "when payload is a hash" do
151
-
152
- it "value is assigned to request payload" do
153
- request = Request.new({ http_method: :get, uri: @api_uri, segment_params: @param_hash, payload: @param_hash })
154
- expect(request.payload).to eq(@param_hash)
155
- end
156
-
157
- end
158
-
159
- end
160
-
161
- describe "#headers" do
162
-
163
- context "when headers is not a hash" do
164
-
165
- it "will raise TypeError" do
166
- request = Request.new({ http_method: :get, uri: @api_uri, segment_params: @param_hash, payload: @param_hash })
167
- expect { request.headers = @non_hash_value }.to raise_error(TypeError)
168
- end
169
-
170
- end
171
-
172
- context "when headers is a hash" do
173
-
174
- it "value is assigned to request header" do
175
- request = Request.new({ http_method: :get, uri: @api_uri, segment_params: @param_hash, payload: @param_hash })
176
- expect(request.payload).to eq(@param_hash)
177
- end
178
-
179
- end
180
-
181
- end
182
-
183
- end
184
-
185
- end