Module: IBM::Cloud::SDKHTTP::BaseHTTPMixin
- Included in:
- IBM::Cloud::SDK::VPC::VpcHTTP, BaseCollection, BaseInstance, IAMToken
- Defined in:
- lib/ibm/cloud/sdk_http/base_http_mixin.rb
Overview
Generic methods for accessing VPC.
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
-
#adhoc(method: 'get', path: nil, params: nil, payload: nil, payload_type: 'json') ⇒ SDKResponse
Run a custom query and verify response is 2xx or 404.
-
#delete(path: nil, params: nil) ⇒ SDKResponse
Send a DELETE request and verify response is 2xx or 404.
-
#get(path: nil, params: nil) ⇒ SDKResponse
Perform a GET request and verify response is 2xx or 404.
-
#metadata(query = nil, payload = nil, payload_type = 'json') ⇒ Hash
Preprocess request parameters with any additional data.
-
#patch(payload: nil, path: nil, params: nil, payload_type: 'json') ⇒ SDKResponse
Send a PATCH request and verify response is 2xx or 404.
-
#post(payload: nil, path: nil, params: nil, payload_type: 'json') ⇒ SDKResponse
Send a POST request and verify response is 2xx or 404.
-
#put(payload: nil, path: nil, params: nil, payload_type: 'json') ⇒ SDKResponse
Send a PUT request and verify response is 2xx or 404.
-
#unchecked_response(method: 'get', path: nil, params: nil, payload: nil, payload_type: 'json') ⇒ Object
Run a custom query do not verify the response.
-
#url(path = nil) ⇒ Object
Merge path with current class’s endpoint.
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
35 36 37 |
# File 'lib/ibm/cloud/sdk_http/base_http_mixin.rb', line 35 def endpoint @endpoint end |
Instance Method Details
#adhoc(method: 'get', path: nil, params: nil, payload: nil, payload_type: 'json') ⇒ SDKResponse
Run a custom query and verify response is 2xx or 404.
21 22 23 |
# File 'lib/ibm/cloud/sdk_http/base_http_mixin.rb', line 21 def adhoc(method: 'get', path: nil, params: nil, payload: nil, payload_type: 'json') unchecked_response(method: method, path: path, params: params, payload: payload, payload_type: payload_type).raise_for_status! end |
#delete(path: nil, params: nil) ⇒ SDKResponse
Send a DELETE request and verify response is 2xx or 404.
84 85 86 |
# File 'lib/ibm/cloud/sdk_http/base_http_mixin.rb', line 84 def delete(path: nil, params: nil) adhoc(method: 'delete', path: path, params: params) end |
#get(path: nil, params: nil) ⇒ SDKResponse
Perform a GET request and verify response is 2xx or 404.
42 43 44 |
# File 'lib/ibm/cloud/sdk_http/base_http_mixin.rb', line 42 def get(path: nil, params: nil) adhoc(method: 'get', path: path, params: params) end |
#metadata(query = nil, payload = nil, payload_type = 'json') ⇒ Hash
Preprocess request parameters with any additional data.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ibm/cloud/sdk_http/base_http_mixin.rb', line 93 def (query = nil, payload = nil, payload_type = 'json') @params ||= {} @params.merge!(query) if query send_parameters = { query: @params, headers: { "Authorization": @token. } } # Add payload if it is not nil. if payload && payload.empty? == false payload = payload.to_json if payload_type == 'json' send_parameters[:body] = payload end send_parameters end |
#patch(payload: nil, path: nil, params: nil, payload_type: 'json') ⇒ SDKResponse
Send a PATCH request and verify response is 2xx or 404.
75 76 77 |
# File 'lib/ibm/cloud/sdk_http/base_http_mixin.rb', line 75 def patch(payload: nil, path: nil, params: nil, payload_type: 'json') adhoc(method: 'patch', path: path, params: params, payload: payload, payload_type: payload_type) end |
#post(payload: nil, path: nil, params: nil, payload_type: 'json') ⇒ SDKResponse
Send a POST request and verify response is 2xx or 404.
53 54 55 |
# File 'lib/ibm/cloud/sdk_http/base_http_mixin.rb', line 53 def post(payload: nil, path: nil, params: nil, payload_type: 'json') adhoc(method: 'post', path: path, params: params, payload: payload, payload_type: payload_type) end |
#put(payload: nil, path: nil, params: nil, payload_type: 'json') ⇒ SDKResponse
Send a PUT request and verify response is 2xx or 404.
64 65 66 |
# File 'lib/ibm/cloud/sdk_http/base_http_mixin.rb', line 64 def put(payload: nil, path: nil, params: nil, payload_type: 'json') adhoc(method: 'put', path: path, params: params, payload: payload, payload_type: payload_type) end |
#unchecked_response(method: 'get', path: nil, params: nil, payload: nil, payload_type: 'json') ⇒ Object
Run a custom query do not verify the response.
31 32 33 |
# File 'lib/ibm/cloud/sdk_http/base_http_mixin.rb', line 31 def unchecked_response(method: 'get', path: nil, params: nil, payload: nil, payload_type: 'json') @connection.request(method.to_sym, url(path), (params, payload, payload_type)) end |
#url(path = nil) ⇒ Object
Merge path with current class’s endpoint.
111 112 113 114 115 116 |
# File 'lib/ibm/cloud/sdk_http/base_http_mixin.rb', line 111 def url(path = nil) return endpoint unless path return path if URI.parse(path).relative? == false "#{endpoint}/#{path}" end |