bubbles-rest-client 0.6.0 → 0.7.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: 7f077a290f6996a9d6b17eaed8ad1cb4218dc63d1303ac98dd3ac7100e77a03a
4
- data.tar.gz: b6737cdf8435852167b508fe3a3b231ab2c98cb0f87489c1111c498d1eac2af1
3
+ metadata.gz: 0e98610b1755842e9daf75e52a69e406f76ee3726c5b1d5b7094b519a289a8dd
4
+ data.tar.gz: eef0efcad84ca786a3e425c3251020f54539015ed199b4ccf00d5aaa7acc8e60
5
5
  SHA512:
6
- metadata.gz: a899787ccb3ebcca5fc4bc6407e33d9c9fb96c478864f7eaf1b64c75b8d4bfd96ee638c3da6125f30bd1c81cbfd360a14962cbde03b2fd4f9f73c1f51eccb206
7
- data.tar.gz: 70e5a4dbf61c052fb0a0af1a6cf8590132aeaea66aee30f30b99d66a968d34a02606c490782d6cdcf0b0fa14f98d3dfaf15ed88b15f00350638a9b8dca810d89
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.1.4"
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"
@@ -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
- define_method(endpoint_name_as_sym) do |auth_token, uri_params|
175
- RestClientResources.execute_get_authenticated self, endpoint, auth_token, uri_params, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
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
- define_method(endpoint_name_as_sym) do |auth_token|
179
- RestClientResources.execute_get_authenticated self, endpoint, auth_token, {}, endpoint.additional_headers, self.get_api_key_if_needed(endpoint), self.api_key_name
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 [String] auth_token The authorization token to use for authentication.
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, auth_token, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key')
66
- composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers)
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, auth_token, composite_headers, uri_params) do |env, url, data, headers|
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, auth_token, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key')
167
- composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers)
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
- return execute_rest_call(env, endpoint, data, auth_token, composite_headers) do |env, url, data, headers|
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
@@ -7,7 +7,7 @@ module Bubbles
7
7
  end
8
8
 
9
9
  def self.version_name
10
- '0.6.0'
10
+ '0.7.0'
11
11
  end
12
12
 
13
13
  def self.version_code
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.6.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: 2020-10-18 00:00:00.000000000 Z
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.1.4
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.1.4
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.8
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