class RestClientWrapper::Request

Request

Constants

DEFAULT_CONTENT_TYPE
HTTP_METHOD_FOR_JSON
VALID_HTTP_METHODS

Attributes

headers[R]
http_method[R]
payload[R]
query_params[R]
segment_params[R]
uri[RW]

Public Class Methods

new(**params) click to toggle source
# File lib/rest_client_wrapper/request.rb, line 31
def initialize(**params)
  @uri = params[:uri]
  self.headers = params[:headers].nil? ? {} : params[:headers]
  self.http_method = params[:http_method]
  self.segment_params = params[:segment_params].nil? ? {} : params[:segment_params]
  self.payload = params[:payload].nil? ? {} : params[:payload]
  self.query_params = params[:query_params].nil? ? {} : params[:query_params]
end

Public Instance Methods

headers=(headers) click to toggle source
# File lib/rest_client_wrapper/request.rb, line 67
def headers=(headers)
  raise TypeError, "Request headers parameters is not a hash" unless headers.is_a?(Hash)

  @headers.nil? ? @headers = headers : @headers.merge!(headers)
end
http_method=(http_method) click to toggle source
# File lib/rest_client_wrapper/request.rb, line 40
def http_method=(http_method)
  raise TypeError, "Request http_method parameters is not a symbol" unless http_method.is_a?(Symbol)
  raise ArgumentError, "Not a valid http method" unless VALID_HTTP_METHODS.include?(http_method)

  headers[:content_type] = DEFAULT_CONTENT_TYPE[:content_type] unless headers.key?(:content_type) || !HTTP_METHOD_FOR_JSON.include?(http_method)
  headers[:accept] = DEFAULT_CONTENT_TYPE[:accept] unless headers.key?(:accept) || !HTTP_METHOD_FOR_JSON.include?(http_method)
  @http_method = http_method
end
payload=(payload) click to toggle source
# File lib/rest_client_wrapper/request.rb, line 49
def payload=(payload)
  raise TypeError, "Request payload parameters is not a hash" if !payload.is_a?(Hash) && self.headers[:content_type] == :json

  @payload = payload
end
query_params=(query_params) click to toggle source
# File lib/rest_client_wrapper/request.rb, line 61
def query_params=(query_params)
  raise TypeError, "Request query parameters is not a hash" unless query_params.is_a?(Hash)

  @query_params = query_params
end
segment_params=(segment_params) click to toggle source
# File lib/rest_client_wrapper/request.rb, line 55
def segment_params=(segment_params)
  raise TypeError, "Request segment parameters is not a hash" unless segment_params.is_a?(Hash)

  @segment_params = segment_params
end