module IBM::Cloud::SDKHTTP::BaseHTTPMixin

Generic methods for accessing VPC.

Attributes

endpoint[R]

Public Instance Methods

adhoc(method: 'get', path: nil, params: nil, payload: nil, payload_type: 'json') click to toggle source

Run a custom query and verify response is 2xx or 404. @param method [String] The HTTP method to use. @param path [String] The relative path from the current object location. @param params [Hash] A hash of query parameters. @param payload [Hash] A hash to send as the body. @param payload_type [Hash] If json then convert to json string, else send as form data. @return [SDKResponse] @raise [Exceptions::HttpStatusError] Raise if status checks failed.

# 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) click to toggle source

Send a DELETE request and verify response is 2xx or 404. @param path [String] The relative path from the current object location. @param params [Hash] A hash of query parameters. @raise [Exceptions::HttpStatusError] Raise if status checks failed. @return [SDKResponse]

# 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) click to toggle source

Perform a GET request and verify response is 2xx or 404. @param path [String] The relative path from the current object location. @param params [Hash] A hash of query parameters. @return [SDKResponse] @raise [Exceptions::HttpStatusError] Raise if status checks failed.

# 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') click to toggle source

Preprocess request parameters with any additional data. @param query [Hash] A hash of query parameters. @param payload [Hash] A hash to send as the body. @param payload_type [Hash] If json then convert to json string, else send as form data. @return [Hash]

# File lib/ibm/cloud/sdk_http/base_http_mixin.rb, line 93
def metadata(query = nil, payload = nil, payload_type = 'json')
  @params ||= {}
  @params.merge!(query) if query

  send_parameters = {
    query: @params,
    headers: { "Authorization": @token.authorization_header }
  }

  # 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') click to toggle source

Send a PATCH request and verify response is 2xx or 404. @param path [String] The relative path from the current object location. @param params [Hash] A hash of query parameters. @param payload [Hash] A hash to send as the body. @param payload_type [Hash] If json then convert to json string, else send as form data. @raise [Exceptions::HttpStatusError] Raise if status checks failed. @return [SDKResponse]

# 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') click to toggle source

Send a POST request and verify response is 2xx or 404. @param path [String] The relative path from the current object location. @param params [Hash] A hash of query parameters. @param payload [Hash] A hash to send as the body. @param payload_type [Hash] If json then convert to json string, else send as form data. @raise [Exceptions::HttpStatusError] Raise if status checks failed. @return [SDKResponse]

# 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') click to toggle source

Send a PUT request and verify response is 2xx or 404. @param path [String] The relative path from the current object location. @param params [Hash] A hash of query parameters. @param payload [Hash] A hash to send as the body. @param payload_type [Hash] If json then convert to json string, else send as form data. @raise [Exceptions::HttpStatusError] Raise if status checks failed. @return [SDKResponse]

# 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') click to toggle source

Run a custom query do not verify the response. @param method [String] The HTTP method to use. @param path [String] The relative path from the current object location. @param params [Hash] A hash of query parameters. @param payload [Hash] A hash to send as the body. @param payload_type [Hash] If json then convert to json string, else send as form data.

# 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), metadata(params, payload, payload_type))
end
url(path = nil) click to toggle source

Merge path with current class's endpoint.

# 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