Class: Bubbles::RestClientResources
- Inherits:
-
Object
- Object
- Bubbles::RestClientResources
- Defined in:
- lib/bubbles/rest_client_resources.rb
Direct Known Subclasses
Class Method Summary collapse
-
.build_composite_headers(headers, additional_headers) ⇒ Object
Build a set of headers from two existing sets.
-
.execute_delete_authenticated(env, endpoint, auth_token, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a DELETE request with authentication in the form of an authorization token.
-
.execute_delete_unauthenticated(env, endpoint, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-Api-Key') ⇒ RestClient::Response
Execute a DELETE request without authentication.
-
.execute_get_authenticated(env, endpoint, auth_token, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a GET request with authentication.
-
.execute_get_unauthenticated(env, endpoint, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a GET request without authentication.
-
.execute_head_authenticated(env, endpoint, auth_token, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a HEAD request with authentication.
-
.execute_head_unauthenticated(env, endpoint, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a HEAD request without authentication.
-
.execute_patch_authenticated(env, endpoint, auth_token, uri_params, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a PATCH request with authentication in the form of an authorization token.
-
.execute_patch_unauthenticated(env, endpoint, uri_params, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a PATCH request without authentication.
-
.execute_post_authenticated(env, endpoint, auth_token, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a POST request with authentication in the form of an authorization token.
-
.execute_post_unauthenticated(env, endpoint, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a POST request without authentication, but requiring an API key.
-
.execute_put_authenticated(env, endpoint, auth_token, uri_params, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a PUT request with authentication in the form of an authorization token.
-
.execute_put_unauthenticated(env, endpoint, uri_params, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a PUT request without authentication.
-
.get_encoded_authorization(endpoint, data) ⇒ Object
Retrieve an encoded authorization (username and password) for a given
Endpointand data set.
Instance Method Summary collapse
- #environment ⇒ Object
-
#initialize(env, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClientResources
constructor
Create a new instance of
RestClientResources.
Constructor Details
#initialize(env, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClientResources
Create a new instance of RestClientResources.
19 20 21 22 23 24 25 26 27 |
# File 'lib/bubbles/rest_client_resources.rb', line 19 def initialize(env, api_key = nil, api_key_name='X-API-Key') unless api_key api_key = '' end @api_key = api_key @auth_token = nil @api_key_name = api_key_name end |
Class Method Details
.build_composite_headers(headers, additional_headers) ⇒ Object
Build a set of headers from two existing sets.
This takes two sets of headers, as Hashes and merges them to create a single Hash with all of the members of the previous two.
354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/bubbles/rest_client_resources.rb', line 354 def self.build_composite_headers(headers, additional_headers) composite_headers = headers unless additional_headers.empty? additional_headers.each { |nextHeader| composite_headers[nextHeader[0]] = nextHeader[1] } end composite_headers end |
.execute_delete_authenticated(env, endpoint, auth_token, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a DELETE request with authentication in the form of an authorization token.
291 292 293 294 295 296 297 |
# File 'lib/bubbles/rest_client_resources.rb', line 291 def self.execute_delete_authenticated(env, endpoint, auth_token, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) execute_rest_call(env, endpoint, nil, auth_token, composite_headers, uri_params) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).delete(headers) end end |
.execute_delete_unauthenticated(env, endpoint, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-Api-Key') ⇒ RestClient::Response
Execute a DELETE request without authentication.
314 315 316 317 318 319 320 |
# File 'lib/bubbles/rest_client_resources.rb', line 314 def self.execute_delete_unauthenticated(env, endpoint, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-Api-Key') composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) execute_rest_call(env, endpoint, nil, nil, composite_headers, uri_params) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).delete(headers) end end |
.execute_get_authenticated(env, endpoint, auth_token, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a GET request with authentication.
Currently, only Authorization: Bearer is supported.
65 66 67 68 69 70 71 |
# File 'lib/bubbles/rest_client_resources.rb', line 65 def self.execute_get_authenticated(env, endpoint, auth_token, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) execute_rest_call(env, endpoint, nil, auth_token, composite_headers, uri_params) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).get(headers) end end |
.execute_get_unauthenticated(env, endpoint, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a GET request without authentication.
39 40 41 42 43 44 45 |
# File 'lib/bubbles/rest_client_resources.rb', line 39 def self.execute_get_unauthenticated(env, endpoint, uri_params, additional_headers = {}, api_key = nil, api_key_name='X-API-Key') composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) execute_rest_call(env, endpoint, nil, nil, composite_headers, uri_params) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).get(headers) end end |
.execute_head_authenticated(env, endpoint, auth_token, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a HEAD request with authentication.
Currently, only Authorization: Bearer is supported. This is the same as a GET request, but will only return headers and not the response body.
117 118 119 120 121 122 123 |
# File 'lib/bubbles/rest_client_resources.rb', line 117 def self.execute_head_authenticated(env, endpoint, auth_token, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) execute_rest_call(env, endpoint, nil, auth_token, composite_headers, uri_params) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).head(headers) end end |
.execute_head_unauthenticated(env, endpoint, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a HEAD request without authentication.
This is the same as a GET request, but will only return headers and not the response body.
90 91 92 93 94 95 96 |
# File 'lib/bubbles/rest_client_resources.rb', line 90 def self.execute_head_unauthenticated(env, endpoint, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) execute_rest_call(env, endpoint, nil, nil, composite_headers, uri_params) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).head(headers) end end |
.execute_patch_authenticated(env, endpoint, auth_token, uri_params, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a PATCH request with authentication in the form of an authorization token.
192 193 194 195 196 197 198 |
# File 'lib/bubbles/rest_client_resources.rb', line 192 def self.execute_patch_authenticated(env, endpoint, auth_token, uri_params, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) return execute_rest_call(env, endpoint, data, auth_token, composite_headers, uri_params) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).patch(data.to_json, headers) end end |
.execute_patch_unauthenticated(env, endpoint, uri_params, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a PATCH request without authentication.
216 217 218 219 220 221 222 |
# File 'lib/bubbles/rest_client_resources.rb', line 216 def self.execute_patch_unauthenticated(env, endpoint, uri_params, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) return execute_rest_call(env, endpoint, data, nil, composite_headers, uri_params) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).patch(data.to_json, headers) end end |
.execute_post_authenticated(env, endpoint, auth_token, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a POST request with authentication in the form of an authorization token.
166 167 168 169 170 171 172 |
# File 'lib/bubbles/rest_client_resources.rb', line 166 def self.execute_post_authenticated(env, endpoint, auth_token, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) return execute_rest_call(env, endpoint, data, auth_token, composite_headers) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).post(data.to_json, headers) end end |
.execute_post_unauthenticated(env, endpoint, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a POST request without authentication, but requiring an API key.
141 142 143 144 145 146 147 |
# File 'lib/bubbles/rest_client_resources.rb', line 141 def self.execute_post_unauthenticated(env, endpoint, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) execute_rest_call(env, endpoint, data, nil, composite_headers) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).post(data.to_json, headers) end end |
.execute_put_authenticated(env, endpoint, auth_token, uri_params, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a PUT request with authentication in the form of an authorization token.
242 243 244 245 246 247 248 |
# File 'lib/bubbles/rest_client_resources.rb', line 242 def self.execute_put_authenticated(env, endpoint, auth_token, uri_params, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) return execute_rest_call(env, endpoint, data, auth_token, composite_headers, uri_params) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).put(data.to_json, headers) end end |
.execute_put_unauthenticated(env, endpoint, uri_params, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestClient::Response
Execute a PUT request without authentication.
266 267 268 269 270 271 272 |
# File 'lib/bubbles/rest_client_resources.rb', line 266 def self.execute_put_unauthenticated(env, endpoint, uri_params, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) return execute_rest_call(env, endpoint, data, nil, composite_headers, uri_params) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).put(data.to_json, headers) end end |
.get_encoded_authorization(endpoint, data) ⇒ Object
Retrieve an encoded authorization (username and password) for a given Endpoint and data set.
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/bubbles/rest_client_resources.rb', line 377 def self.(endpoint, data) count = 0 auth_value = '' endpoint..each { |auth_key| if data[auth_key] if count > 0 auth_value = auth_value + ':' + data[auth_key] else auth_value = data[auth_key] end count = count + 1 data.delete(auth_key) end } auth_value end |
Instance Method Details
#environment ⇒ Object
6 7 8 |
# File 'lib/bubbles/rest_client_resources.rb', line 6 def environment Bubbles.configuration.environment end |