bubbles-rest-client 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/bubbles/config.rb +29 -14
- data/lib/bubbles/rest_client_resources.rb +42 -0
- data/lib/bubbles/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ad75198eea8a1ae90b920cdaf131f8835eec848
|
4
|
+
data.tar.gz: 2213e42c80108c736a737edf350763b934013056
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c4cef54a47849f040fc3e1c73978f6408d50690e7ef78a7dc72ffb166fd539427535cd4c7c5456c3837188fa256e44b21b5e5128d449fbaab912341f0aac883
|
7
|
+
data.tar.gz: 7d2a4630c75ba13393f49c262ecccab694ff0e46ba3f574503233057245bc5d91b8ea270bef50e235ec7b01da4bb04769d4459c0eb6f9d98a0d1976172f51127
|
data/README.md
CHANGED
@@ -29,8 +29,7 @@ _bubbles_ is a Gem that seeks to provide this same behavior.
|
|
29
29
|
Currently, bubbles has a number of limitations that make it likely not suitable for use in a production environment. Each of these is tracked by an issue on our [issues page](https://github.com/FoamFactory/bubbles/issues).
|
30
30
|
|
31
31
|
- Passing an API key with a request is restricted to using `X-Api-Key` as a header key (#10).
|
32
|
-
- Some request methods (
|
33
|
-
- Only three types of environment are currently allowed. Only `local`, `staging` and `production` are recognized as possible environments to connect to for the purposes of using bubbles. You can add any scheme, host, and port to any of these, but the names are currently hardcoded, as is the number of possible hosts. (#4)
|
32
|
+
- Some request methods (specifically `DELETE`) do not currently allow unauthenticated access. In other words, it is not possible to perform a `DELETE` request on your API without passing an authorization token. (#16)
|
34
33
|
- Not all possible combinations of `has_uri_params`, `authenticated`, and `api_key_required` are tested. In some cases, such as with `GET` requests, there aren't any tests for possible configuration cases that might cause issues when combined. (#12)
|
35
34
|
|
36
35
|
If you're interested in working on any of the issues above, please feel free to submit a pull request and a member of our team will review that pull request within a couple of days.
|
data/lib/bubbles/config.rb
CHANGED
@@ -218,17 +218,24 @@ module Bubbles
|
|
218
218
|
end
|
219
219
|
else
|
220
220
|
define_method(endpoint_name_as_sym) do |auth_token, data|
|
221
|
-
|
221
|
+
# TODO: Nothing tests this case. We need something to test this case or we run the risk of
|
222
|
+
# it having bugs (uri_params was nil previously!)
|
223
|
+
RestClientResources.execute_patch_authenticated self, endpoint, auth_token, {}, data
|
222
224
|
end
|
223
225
|
end
|
224
226
|
end
|
225
227
|
else
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
228
|
+
Bubbles::RestEnvironment.class_exec do
|
229
|
+
if endpoint.has_uri_params?
|
230
|
+
define_method(endpoint_name_as_sym) do |uri_params, data|
|
231
|
+
RestClientResources.execute_patch_unauthenticated self, endpoint, uri_params, data
|
232
|
+
end
|
233
|
+
else
|
234
|
+
define_method(endpoint_name_as_sym) do |data|
|
235
|
+
RestClientResources.execute_patch_unauthenticated self, endpoint, {}, data
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
232
239
|
end
|
233
240
|
elsif endpoint.method == :put
|
234
241
|
if endpoint.authenticated?
|
@@ -239,17 +246,25 @@ module Bubbles
|
|
239
246
|
end
|
240
247
|
else
|
241
248
|
define_method(endpoint_name_as_sym) do |auth_token, data|
|
242
|
-
|
249
|
+
# TODO: Nothing tests this case. We need something to test this case or we run the risk of
|
250
|
+
# it having bugs (uri_params was nil previously!)
|
251
|
+
RestClientResources.execute_put_authenticated self, endpoint, auth_token, {}, data
|
243
252
|
end
|
244
253
|
end
|
245
254
|
end
|
246
255
|
else
|
247
|
-
raise 'Unauthenticated PUT requests are not implemented'
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
256
|
+
# raise 'Unauthenticated PUT requests are not implemented'
|
257
|
+
Bubbles::RestEnvironment.class_exec do
|
258
|
+
if endpoint.has_uri_params?
|
259
|
+
define_method(endpoint_name_as_sym) do |uri_params, data|
|
260
|
+
RestClientResources.execute_put_unauthenticated self, endpoint, uri_params, data
|
261
|
+
end
|
262
|
+
else
|
263
|
+
define_method(endpoint_name_as_sym) do |data|
|
264
|
+
RestClientResources.execute_put_unauthenticated self, endpoint, {}, data
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
253
268
|
end
|
254
269
|
elsif endpoint.method == :head
|
255
270
|
if endpoint.authenticated?
|
@@ -194,6 +194,27 @@ module Bubbles
|
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
|
+
##
|
198
|
+
# Execute a PATCH request without authentication.
|
199
|
+
#
|
200
|
+
# @param [RestEnvironment] env The +RestEnvironment+ to use to execute the request
|
201
|
+
# @param [Endpoint] endpoint The +Endpoint+ which should be requested
|
202
|
+
# @param [Hash] uri_params A +Hash+ of identifiers to values to replace in the URI string.
|
203
|
+
# @param [Hash] data A +Hash+ of key-value pairs that will be sent in the body of the http request.
|
204
|
+
#
|
205
|
+
# @return [RestClient::Response] The +Response+ resulting from the execution of the PATCH call.
|
206
|
+
#
|
207
|
+
def self.execute_patch_unauthenticated(env, endpoint, uri_params, data)
|
208
|
+
return execute_rest_call(env, endpoint, data, nil, nil, uri_params) do |env, url, data, headers|
|
209
|
+
if env.scheme == 'https'
|
210
|
+
next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE)
|
211
|
+
.patch(data.to_json, headers)
|
212
|
+
else
|
213
|
+
next RestClient.patch(url.to_s, data.to_json, headers)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
197
218
|
##
|
198
219
|
# Execute a PUT request with authentication in the form of an authorization token.
|
199
220
|
#
|
@@ -218,6 +239,27 @@ module Bubbles
|
|
218
239
|
end
|
219
240
|
end
|
220
241
|
|
242
|
+
##
|
243
|
+
# Execute a PUT request without authentication.
|
244
|
+
#
|
245
|
+
# @param [RestEnvironment] env The +RestEnvironment+ to use to execute the request
|
246
|
+
# @param [Endpoint] endpoint The +Endpoint+ which should be requested
|
247
|
+
# @param [Hash] uri_params A +Hash+ of identifiers to values to replace in the URI string.
|
248
|
+
# @param [Hash] data A +Hash+ of key-value pairs that will be sent in the body of the http request.
|
249
|
+
#
|
250
|
+
# @return [RestClient::Response] The +Response+ resulting from the execution of the PUT call.
|
251
|
+
#
|
252
|
+
def self.execute_put_unauthenticated(env, endpoint, uri_params, data)
|
253
|
+
return execute_rest_call(env, endpoint, data, nil, nil, uri_params) do |env, url, data, headers|
|
254
|
+
if env.scheme == 'https'
|
255
|
+
next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE)
|
256
|
+
.put(data.to_json, headers)
|
257
|
+
else
|
258
|
+
next RestClient.put(url.to_s, data.to_json, headers)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
221
263
|
##
|
222
264
|
# Execute a DELETE request with authentication in the form of an authorization token.
|
223
265
|
#
|
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.3.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: 2019-04
|
11
|
+
date: 2019-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|