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_type, auth_value, 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_type, auth_value, 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
Endpoint
and data set.
Instance Method Summary collapse
- #environment(env_name = nil) ⇒ 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.
369 370 371 372 373 374 375 376 377 378 379 |
# File 'lib/bubbles/rest_client_resources.rb', line 369 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.
306 307 308 309 310 311 312 |
# File 'lib/bubbles/rest_client_resources.rb', line 306 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.
329 330 331 332 333 334 335 |
# File 'lib/bubbles/rest_client_resources.rb', line 329 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_type, auth_value, 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.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bubbles/rest_client_resources.rb', line 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') if auth_type == :basic composite_headers = RestClientResources.build_composite_headers(endpoint.additional_headers, { Authorization: 'Basic ' + Base64.strict_encode64(auth_value) }) auth_value = nil else composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) end execute_rest_call(env, endpoint, nil, auth_value, 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.
125 126 127 128 129 130 131 |
# File 'lib/bubbles/rest_client_resources.rb', line 125 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.
98 99 100 101 102 103 104 |
# File 'lib/bubbles/rest_client_resources.rb', line 98 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.
207 208 209 210 211 212 213 |
# File 'lib/bubbles/rest_client_resources.rb', line 207 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.
231 232 233 234 235 236 237 |
# File 'lib/bubbles/rest_client_resources.rb', line 231 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_type, auth_value, 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.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/bubbles/rest_client_resources.rb', line 174 def self.execute_post_authenticated(env, endpoint, auth_type, auth_value, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') if auth_type == :basic composite_headers = RestClientResources.build_composite_headers(endpoint.additional_headers, { Authorization: 'Basic ' + Base64.strict_encode64(auth_value) }) auth_value = nil else composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) end execute_rest_call(env, endpoint, data, auth_value, 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.
149 150 151 152 153 154 155 |
# File 'lib/bubbles/rest_client_resources.rb', line 149 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.
257 258 259 260 261 262 263 |
# File 'lib/bubbles/rest_client_resources.rb', line 257 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.
281 282 283 284 285 286 287 |
# File 'lib/bubbles/rest_client_resources.rb', line 281 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.
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/bubbles/rest_client_resources.rb', line 392 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(env_name = nil) ⇒ Object
6 7 8 |
# File 'lib/bubbles/rest_client_resources.rb', line 6 def environment(env_name = nil) Bubbles.configuration.environment(env_name) end |