bubbles-rest-client 0.6.0 → 0.7.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/bubbles.gemspec +1 -1
- data/lib/bubbles/config.rb +44 -13
- data/lib/bubbles/rest_client_resources.rb +22 -7
- data/lib/bubbles/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e98610b1755842e9daf75e52a69e406f76ee3726c5b1d5b7094b519a289a8dd
|
4
|
+
data.tar.gz: eef0efcad84ca786a3e425c3251020f54539015ed199b4ccf00d5aaa7acc8e60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d57f7ef6b948deec157e1109e17912c0fb923d4bc21626d6df2a91d4958c7cb0ac60c377507f27b3c142a88d09bc09e6e391f9ec8c9ebbe08566fca5c9ba76ce
|
7
|
+
data.tar.gz: 6649af7c90e05d2260bc7fd51ba26c43693b09f9a1e38df18483f78873f761e7261ab13f7fe615909e5da66a299b13eb1830dee3663e6f7bdc881265e72ab374
|
data/bubbles.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
33
|
spec.require_paths = ["lib"]
|
34
34
|
|
35
|
-
spec.add_development_dependency "bundler", "~> 2.
|
35
|
+
spec.add_development_dependency "bundler", "~> 2.2.26"
|
36
36
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
37
37
|
spec.add_development_dependency "minitest", "~> 5.0"
|
38
38
|
spec.add_development_dependency "minitest-reporters", "~> 1.1"
|
data/lib/bubbles/config.rb
CHANGED
@@ -171,12 +171,35 @@ module Bubbles
|
|
171
171
|
if endpoint.authenticated?
|
172
172
|
Bubbles::RestEnvironment.class_exec do
|
173
173
|
if endpoint.has_uri_params?
|
174
|
-
|
175
|
-
|
174
|
+
if endpoint.encode_authorization_header?
|
175
|
+
define_method(endpoint_name_as_sym) do |username, password, uri_params|
|
176
|
+
login_data = {
|
177
|
+
:login => username,
|
178
|
+
:password => password
|
179
|
+
}
|
180
|
+
auth_value = RestClientResources.get_encoded_authorization(endpoint, login_data)
|
181
|
+
RestClientResources.execute_get_authenticated self, endpoint, :basic, auth_value, uri_params, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
|
182
|
+
end
|
183
|
+
else
|
184
|
+
define_method(endpoint_name_as_sym) do |auth_token, uri_params|
|
185
|
+
RestClientResources.execute_get_authenticated self, endpoint, :bearer, auth_token, uri_params, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
|
186
|
+
end
|
176
187
|
end
|
177
188
|
else
|
178
|
-
|
179
|
-
|
189
|
+
if endpoint.encode_authorization_header?
|
190
|
+
define_method(endpoint_name_as_sym) do |username, password|
|
191
|
+
login_data = {
|
192
|
+
:username => username,
|
193
|
+
:password => password
|
194
|
+
}
|
195
|
+
auth_value = RestClientResources.get_encoded_authorization(endpoint, login_data)
|
196
|
+
|
197
|
+
RestClientResources.execute_get_authenticated self, endpoint, :basic, auth_value, {}, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
|
198
|
+
end
|
199
|
+
else
|
200
|
+
define_method(endpoint_name_as_sym) do |auth_token|
|
201
|
+
RestClientResources.execute_get_authenticated self, endpoint, :bearer, auth_token, {}, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
|
202
|
+
end
|
180
203
|
end
|
181
204
|
end
|
182
205
|
end
|
@@ -194,23 +217,31 @@ module Bubbles
|
|
194
217
|
end
|
195
218
|
end
|
196
219
|
elsif endpoint.method == :post
|
197
|
-
if endpoint.authenticated?
|
220
|
+
if endpoint.authenticated? and !endpoint.encode_authorization_header?
|
198
221
|
Bubbles::RestEnvironment.class_exec do
|
199
222
|
define_method(endpoint_name_as_sym) do |auth_token, data|
|
200
|
-
RestClientResources.execute_post_authenticated self, endpoint, auth_token, data, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
|
223
|
+
RestClientResources.execute_post_authenticated self, endpoint, :bearer, auth_token, data, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
|
224
|
+
end
|
225
|
+
end
|
226
|
+
elsif endpoint.encode_authorization_header?
|
227
|
+
Bubbles::RestEnvironment.class_exec do
|
228
|
+
define_method(endpoint_name_as_sym) do |username, password, data = {}|
|
229
|
+
login_data = {
|
230
|
+
:username => username,
|
231
|
+
:password => password
|
232
|
+
}
|
233
|
+
|
234
|
+
auth_value = RestClientResources.get_encoded_authorization(endpoint, login_data)
|
235
|
+
# composite_headers = RestClientResources.build_composite_headers(endpoint.additional_headers, {
|
236
|
+
# Authorization: 'Basic ' + Base64.strict_encode64(auth_value)
|
237
|
+
# })
|
238
|
+
RestClientResources.execute_post_authenticated self, endpoint, :basic, auth_value, data, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
|
201
239
|
end
|
202
240
|
end
|
203
241
|
else
|
204
242
|
Bubbles::RestEnvironment.class_exec do
|
205
243
|
define_method(endpoint_name_as_sym) do |data|
|
206
244
|
composite_headers = endpoint.additional_headers
|
207
|
-
if endpoint.encode_authorization_header?
|
208
|
-
auth_value = RestClientResources.get_encoded_authorization(endpoint, data)
|
209
|
-
composite_headers = RestClientResources.build_composite_headers(endpoint.additional_headers, {
|
210
|
-
Authorization: 'Basic ' + Base64.strict_encode64(auth_value)
|
211
|
-
})
|
212
|
-
end
|
213
|
-
|
214
245
|
RestClientResources.execute_post_unauthenticated self, endpoint, data, composite_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
|
215
246
|
end
|
216
247
|
end
|
@@ -51,7 +51,8 @@ module Bubbles
|
|
51
51
|
#
|
52
52
|
# @param [RestEnvironment] env The +RestEnvironment+ to use to execute the request
|
53
53
|
# @param [Endpoint] endpoint The +Endpoint+ which should be requested
|
54
|
-
# @param [
|
54
|
+
# @param [Symbol] auth_type The authorization type to use (Bearer, or Basic)
|
55
|
+
# @param [String] auth_value The authorization token OR encoded value (login/password )to use for authentication.
|
55
56
|
# @param [Hash] uri_params A +Hash+ of identifiers to values to replace in the URI string.
|
56
57
|
# @param [Hash] additional_headers A +Hash+ of key-value pairs that will be sent as additional headers in the API
|
57
58
|
# call. Defaults to an empty +Hash+.
|
@@ -62,10 +63,17 @@ module Bubbles
|
|
62
63
|
#
|
63
64
|
# @return [RestClient::Response] The +Response+ resulting from the execution of the GET call.
|
64
65
|
#
|
65
|
-
def self.execute_get_authenticated(env, endpoint,
|
66
|
-
|
66
|
+
def self.execute_get_authenticated(env, endpoint, auth_type, auth_value, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key')
|
67
|
+
if auth_type == :basic
|
68
|
+
composite_headers = RestClientResources.build_composite_headers(endpoint.additional_headers, {
|
69
|
+
Authorization: 'Basic ' + Base64.strict_encode64(auth_value)
|
70
|
+
})
|
71
|
+
auth_value = nil
|
72
|
+
else
|
73
|
+
composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers)
|
74
|
+
end
|
67
75
|
|
68
|
-
execute_rest_call(env, endpoint, nil,
|
76
|
+
execute_rest_call(env, endpoint, nil, auth_value, composite_headers, uri_params) do |env, url, data, headers|
|
69
77
|
next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).get(headers)
|
70
78
|
end
|
71
79
|
end
|
@@ -163,10 +171,17 @@ module Bubbles
|
|
163
171
|
#
|
164
172
|
# @return [RestClient::Response] The +Response+ resulting from the execution of the POST call.
|
165
173
|
#
|
166
|
-
def self.execute_post_authenticated(env, endpoint,
|
167
|
-
|
174
|
+
def self.execute_post_authenticated(env, endpoint, auth_type, auth_value, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key')
|
175
|
+
if auth_type == :basic
|
176
|
+
composite_headers = RestClientResources.build_composite_headers(endpoint.additional_headers, {
|
177
|
+
Authorization: 'Basic ' + Base64.strict_encode64(auth_value)
|
178
|
+
})
|
179
|
+
auth_value = nil
|
180
|
+
else
|
181
|
+
composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers)
|
182
|
+
end
|
168
183
|
|
169
|
-
|
184
|
+
execute_rest_call(env, endpoint, data, auth_value, composite_headers) do |env, url, data, headers|
|
170
185
|
next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).post(data.to_json, headers)
|
171
186
|
end
|
172
187
|
end
|
data/lib/bubbles/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bubbles-rest-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Johnson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.2.26
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.2.26
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -210,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
210
|
- !ruby/object:Gem::Version
|
211
211
|
version: '0'
|
212
212
|
requirements: []
|
213
|
-
rubygems_version: 3.0.
|
213
|
+
rubygems_version: 3.0.9
|
214
214
|
signing_key:
|
215
215
|
specification_version: 4
|
216
216
|
summary: A gem for easily defining client REST interfaces in Ruby
|