class Delphix::Request
Attributes
all[R]
@!attribute [r] all
The raw_body un-parsed response body. @return [JSON]
body[R]
@!attribute [r] body
The parsed response body where applicable (JSON responses are parsed to Objects/Associative Arrays). @return [Hash]
headers[R]
@!attribute [r] headers
The HTTP headers, symbolized and underscored. @return [Hash]
method[R]
@!attribute [r] method
The HTTP method used, 'GET', 'POST', or 'DELETE'. @return [String]
url[R]
@!attribute [r] url
The API path/URL to POST, GET, DELETE from/to. @return [String]
Public Class Methods
new(method, url, headers = {}, body = nil)
click to toggle source
@param [Symnol] method
A valid HTTP verb `GET`, `POST`, `PUT`, `PATCH` or `DELETE`.
@param [String] url
Endpoint (address or uri) to send request.
@param [String, Hash, Object] body
The request Body.
@param [Proc] callback
Asychronous callback method to be invoked upon result.
# File lib/delphix/request.rb, line 64 def initialize(method, url, headers = {}, body = nil) @method = method if method == :get if body.respond_to?(:keys) && body.respond_to?(:[]) && body.length > 0 url += url.include?('?') ? '&' : '?' uri = Addressable::URI.new uri.query_values = body url += uri.query end else @body = body end if url =~ URI.regexp @url = url.gsub(/\s+/, '%20') else raise "Invalid URL: #{url}" end @headers = { 'Date' => utc_httpdate, 'Request-ID' => request_id } headers.each_pair { |key, value| @headers[key.downcase] = value } Delphix.last_request = { headers: @headers, method: @method, url: @url } begin Delphix.last_request[:body] = JSON.parse(@body) if body.length > 2 rescue Exception end end
Public Instance Methods
add_header(name, value)
click to toggle source
# File lib/delphix/request.rb, line 48 def add_header(name, value) @headers[name] = value end