Class: Bubbles::RestClientResources
- Inherits:
-
Object
- Object
- Bubbles::RestClientResources
- Defined in:
- lib/bubbles/rest_client_resources.rb
Direct Known Subclasses
Class Method Summary collapse
-
.execute_delete_authenticated(env, endpoint, auth_token, uri_params) ⇒ RestClient::Response
Execute a DELETE request with authentication in the form of an authorization token.
-
.execute_get_authenticated(env, endpoint, auth_token, uri_params) ⇒ RestClient::Response
Execute a GET request with authentication.
-
.execute_get_unauthenticated(env, endpoint) ⇒ RestClient::Response
Execute a GET request without authentication.
-
.execute_head_authenticated(env, endpoint, auth_token, uri_params) ⇒ RestClient::Response
Execute a HEAD request with authentication.
-
.execute_head_unauthenticated(env, endpoint, uri_params, additional_headers) ⇒ RestClient::Response
Execute a HEAD request without authentication.
-
.execute_patch_authenticated(env, endpoint, auth_token, uri_params, data) ⇒ RestClient::Response
Execute a PATCH request with authentication in the form of an authorization token.
-
.execute_post_authenticated(env, endpoint, auth_token, data) ⇒ RestClient::Response
Execute a POST request with authentication in the form of an authorization token.
-
.execute_post_with_api_key(env, endpoint, api_key, data, headers = nil) ⇒ RestClient::Response
Execute a POST request without authentication, but requiring an API key.
-
.execute_put_authenticated(env, endpoint, auth_token, uri_params, data) ⇒ RestClient::Response
Execute a PUT request with authentication in the form of an authorization token.
Instance Method Summary collapse
- #environment ⇒ Object
-
#initialize(env, api_key) ⇒ RestClientResources
constructor
Create a new instance of
RestClientResources.
Constructor Details
#initialize(env, api_key) ⇒ RestClientResources
Create a new instance of RestClientResources.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bubbles/rest_client_resources.rb', line 16 def initialize(env, api_key) unless env env = :local end unless api_key api_key = '' end @environment = get_environment env @api_key = api_key @auth_token = nil end |
Class Method Details
.execute_delete_authenticated(env, endpoint, auth_token, uri_params) ⇒ RestClient::Response
Execute a DELETE request with authentication in the form of an authorization token.
232 233 234 235 236 237 238 239 240 241 |
# File 'lib/bubbles/rest_client_resources.rb', line 232 def self.execute_delete_authenticated(env, endpoint, auth_token, uri_params) execute_rest_call(env, endpoint, nil, auth_token, nil, uri_params) do |env, url, data, headers| if env.scheme == 'https' next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE) .delete(headers) else next RestClient.delete(url.to_s, headers) end end end |
.execute_get_authenticated(env, endpoint, auth_token, uri_params) ⇒ RestClient::Response
Execute a GET request with authentication.
Currently, only Authorization: Bearer is supported.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bubbles/rest_client_resources.rb', line 61 def self.execute_get_authenticated(env, endpoint, auth_token, uri_params) execute_rest_call(env, endpoint, nil, auth_token, nil, uri_params) do |env, url, data, headers| if env.scheme == 'https' next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE) .get(headers) else next RestClient.get(url.to_s, headers) end end end |
.execute_get_unauthenticated(env, endpoint) ⇒ RestClient::Response
Execute a GET request without authentication.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bubbles/rest_client_resources.rb', line 38 def self.execute_get_unauthenticated(env, endpoint) execute_rest_call(env, endpoint, nil, nil, nil) do |env, url, data, headers| if env.scheme == 'https' next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE) .get(headers) else next RestClient.get(url.to_s, headers) end end end |
.execute_head_authenticated(env, endpoint, auth_token, uri_params) ⇒ 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.
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/bubbles/rest_client_resources.rb', line 106 def self.execute_head_authenticated(env, endpoint, auth_token, uri_params) execute_rest_call(env, endpoint, nil, auth_token, nil, uri_params) do |env, url, data, headers| if env.scheme == 'https' next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE) .head(headers) else next RestClient.head(url.to_s, headers) end end end |
.execute_head_unauthenticated(env, endpoint, uri_params, additional_headers) ⇒ 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.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/bubbles/rest_client_resources.rb', line 82 def self.execute_head_unauthenticated(env, endpoint, uri_params, additional_headers) execute_rest_call(env, endpoint, nil, nil, additional_headers, uri_params) do |env, url, data, headers| if env.scheme == 'https' next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE) .head(headers) else next RestClient.head(url.to_s, headers) end end end |
.execute_patch_authenticated(env, endpoint, auth_token, uri_params, data) ⇒ RestClient::Response
Execute a PATCH request with authentication in the form of an authorization token.
185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/bubbles/rest_client_resources.rb', line 185 def self.execute_patch_authenticated(env, endpoint, auth_token, uri_params, data) return execute_rest_call(env, endpoint, data, auth_token, nil, uri_params) do |env, url, data, headers| if env.scheme == 'https' next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE) .patch(data.to_json, headers) else next RestClient.patch(url.to_s, data.to_json, headers) end end end |
.execute_post_authenticated(env, endpoint, auth_token, data) ⇒ RestClient::Response
Execute a POST request with authentication in the form of an authorization token.
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/bubbles/rest_client_resources.rb', line 161 def self.execute_post_authenticated(env, endpoint, auth_token, data) return execute_rest_call(env, endpoint, data, auth_token, nil) do |env, url, data, headers| if env.scheme == 'https' next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE) .post(data.to_json, headers) else next RestClient.post(url.to_s, data.to_json, headers) end end end |
.execute_post_with_api_key(env, endpoint, api_key, data, headers = nil) ⇒ RestClient::Response
Execute a POST request without authentication, but requiring an API key.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/bubbles/rest_client_resources.rb', line 129 def self.execute_post_with_api_key(env, endpoint, api_key, data, headers=nil) additional_headers = { 'X-Api-Key' => api_key } unless headers.nil? headers.each { |nextHeader| additional_headers[nextHeader[0]] = nextHeader[1] } end execute_rest_call(env, endpoint, data, nil, additional_headers) do |env, url, data, headers| if env.scheme == 'https' next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE) .post(data.to_json, additional_headers) else next RestClient.post url.to_s, data.to_json, additional_headers end end end |
.execute_put_authenticated(env, endpoint, auth_token, uri_params, data) ⇒ RestClient::Response
Execute a PUT request with authentication in the form of an authorization token.
209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/bubbles/rest_client_resources.rb', line 209 def self.execute_put_authenticated(env, endpoint, auth_token, uri_params, data) return execute_rest_call(env, endpoint, data, auth_token, nil, uri_params) do |env, url, data, headers| if env.scheme == 'https' next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE) .put(data.to_json, headers) else next RestClient.put(url.to_s, data.to_json, headers) end end end |
Instance Method Details
#environment ⇒ Object
6 7 8 |
# File 'lib/bubbles/rest_client_resources.rb', line 6 def environment Bubbles.configuration.environment end |