Class: CoreLibrary::HttpRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/apimatic-core/http/request/http_request.rb

Overview

An http request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_method, query_url, headers: {}, parameters: {}, context: {}) ⇒ HttpRequest

The constructor.

Parameters:

  • http_method (HttpMethodEnum)

    The HTTP method.

  • query_url (String)

    The URL to send the request to.

  • headers (Hash, Optional) (defaults to: {})

    The headers for the HTTP Request.

  • parameters (Hash, Optional) (defaults to: {})

    The parameters for the HTTP Request.

  • context (Hash, Optional) (defaults to: {})

    The context for the HTTP Request.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/apimatic-core/http/request/http_request.rb', line 14

def initialize(http_method,
               query_url,
               headers: {},
               parameters: {},
               context: {})
  @http_method = http_method
  @query_url = query_url
  @headers = headers
  @parameters = parameters
  @context = context
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



4
5
6
# File 'lib/apimatic-core/http/request/http_request.rb', line 4

def context
  @context
end

#headersObject

Returns the value of attribute headers.



4
5
6
# File 'lib/apimatic-core/http/request/http_request.rb', line 4

def headers
  @headers
end

#http_methodObject

Returns the value of attribute http_method.



4
5
6
# File 'lib/apimatic-core/http/request/http_request.rb', line 4

def http_method
  @http_method
end

#parametersObject

Returns the value of attribute parameters.



4
5
6
# File 'lib/apimatic-core/http/request/http_request.rb', line 4

def parameters
  @parameters
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/apimatic-core/http/request/http_request.rb', line 4

def password
  @password
end

#query_urlObject

Returns the value of attribute query_url.



4
5
6
# File 'lib/apimatic-core/http/request/http_request.rb', line 4

def query_url
  @query_url
end

#usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/apimatic-core/http/request/http_request.rb', line 4

def username
  @username
end

Instance Method Details

#add_header(name, value) ⇒ Object

Add a header to the HttpRequest.

Parameters:

  • name (String)

    The name of the header.

  • value (String)

    The value of the header.



29
30
31
# File 'lib/apimatic-core/http/request/http_request.rb', line 29

def add_header(name, value)
  @headers[name] = value
end

#add_parameter(name, value) ⇒ Object

Add a parameter to the HttpRequest.

Parameters:

  • name (String)

    The name of the parameter.

  • value (String)

    The value of the parameter.



36
37
38
# File 'lib/apimatic-core/http/request/http_request.rb', line 36

def add_parameter(name, value)
  @parameters[name] = value
end

#add_query_parameter(name, value) ⇒ Object

Add a query parameter to the HttpRequest.

Parameters:

  • name (String)

    The name of the query parameter.

  • value (String)

    The value of the query parameter.



43
44
45
46
47
48
# File 'lib/apimatic-core/http/request/http_request.rb', line 43

def add_query_parameter(name, value)
  @query_url = ApiHelper.append_url_with_query_parameters(@query_url,
                                                          { name => value },
                                                          ArraySerializationFormat::INDEXED)
  @query_url = ApiHelper.clean_url(@query_url)
end