Class: HTTPWrapper::Request

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

Constant Summary collapse

KNOWN_PARAMS_KEYS =
%i[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

rubocop:disable Metrics/AbcSize



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

def initialize(url, method, params = {}) # rubocop:disable Metrics/AbcSize
  Util.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.



32
33
34
# File 'lib/http_wrapper/request.rb', line 32

def uri
  @uri
end

Instance Method Details

#createObject



39
40
41
42
# File 'lib/http_wrapper/request.rb', line 39

def create
  merge_uri_query
  create_method_specific_request
end