Class: HTTPWrapper::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/http_wrapper/request.rb

Constant Summary collapse

KNOWN_PARAMS_KEYS =
[:headers, :query, :cookie, :auth, :body, :user_agent, :content_type, :multipart].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, method, params = {}) ⇒ Request

Returns a new instance of Request.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/http_wrapper/request.rb', line 7

def initialize(url, method, params = {})
  Utils.validate_hash_keys params, KNOWN_PARAMS_KEYS

  self.uri = url

  @query   = params[:query] || {}
  @headers = normalize_headers params[:headers]
  @method  = http_method_class_for method
  @cookie  = params[:cookie]

  @body_data      = params[:body]
  @multipart_data = params[:multipart]
  @user_agent     = params[:user_agent]
  @content_type   = params[:content_type] || default_content_type_for(method)

  if params[:auth]
    @login    = params[:auth].fetch(:login)
    @password = params[:auth].fetch(:password)
  end

  initialize_headers
end

Instance Attribute Details

#uriObject

Returns the value of attribute uri.



30
31
32
# File 'lib/http_wrapper/request.rb', line 30

def uri
  @uri
end

Instance Method Details

#createObject



37
38
39
40
# File 'lib/http_wrapper/request.rb', line 37

def create
  merge_uri_query
  create_method_specific_request
end