Class: ApimaticCalculator::HttpRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/apimatic_calculator/http/http_request.rb

Overview

Represents a single Http Request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

The constructor.

Parameters:

  • The (HttpMethodEnum)

    HTTP method.

  • The (String)

    URL to send the request to.

  • The (Hash, Optional)

    headers for the HTTP Request.

  • The (Hash, Optional)

    parameters for the HTTP Request.



17
18
19
20
21
22
23
24
25
# File 'lib/apimatic_calculator/http/http_request.rb', line 17

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

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



9
10
11
# File 'lib/apimatic_calculator/http/http_request.rb', line 9

def headers
  @headers
end

#http_methodObject

Returns the value of attribute http_method.



9
10
11
# File 'lib/apimatic_calculator/http/http_request.rb', line 9

def http_method
  @http_method
end

#parametersObject

Returns the value of attribute parameters.



9
10
11
# File 'lib/apimatic_calculator/http/http_request.rb', line 9

def parameters
  @parameters
end

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'lib/apimatic_calculator/http/http_request.rb', line 9

def password
  @password
end

#query_urlObject

Returns the value of attribute query_url.



9
10
11
# File 'lib/apimatic_calculator/http/http_request.rb', line 9

def query_url
  @query_url
end

#usernameObject

Returns the value of attribute username.



9
10
11
# File 'lib/apimatic_calculator/http/http_request.rb', line 9

def username
  @username
end

Instance Method Details

#add_header(name, value) ⇒ Object

Add a header to the HttpRequest.

Parameters:

  • The (String)

    name of the header.

  • The (String)

    value of the header.



30
31
32
# File 'lib/apimatic_calculator/http/http_request.rb', line 30

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

#add_parameter(name, value) ⇒ Object

Add a parameter to the HttpRequest.

Parameters:

  • The (String)

    name of the parameter.

  • The (String)

    value of the parameter.



37
38
39
# File 'lib/apimatic_calculator/http/http_request.rb', line 37

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

#add_query_parameter(name, value) ⇒ Object

Add a query parameter to the HttpRequest.

Parameters:

  • The (String)

    name of the query parameter.

  • The (String)

    value of the query parameter.



44
45
46
47
48
# File 'lib/apimatic_calculator/http/http_request.rb', line 44

def add_query_parameter(name, value)
  @query_url = APIHelper.append_url_with_query_parameters(@query_url,
                                                          name => value)
  @query_url = APIHelper.clean_url(@query_url)
end