-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhttp_request.py
84 lines (65 loc) · 2.67 KB
/
http_request.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
from apimatic_core.utilities.api_helper import ApiHelper
class HttpRequest(object):
"""Information about an HTTP Request including its method, headers,
parameters, URL, and Basic Auth details
Attributes:
http_method (HttpMethodEnum): The HTTP Method that this request should
perform when called.
headers (dict): A dictionary of headers (key : value) that should be
sent along with the request.
query_url (string): The URL that the request should be sent to.
parameters (dict): A dictionary of parameters that are to be sent along
with the request in the form body of the request
"""
def __init__(self,
http_method,
query_url,
headers=None,
query_parameters=None,
parameters=None,
files=None):
"""Constructor for the HttpRequest class
Args:
http_method (HttpMethodEnum): The HTTP Method.
query_url (string): The URL to send the request to.
headers (dict, optional): The headers for the HTTP Request.
query_parameters (dict, optional): Query parameters to add in the
URL.
parameters (dict, optional): Form or body parameters to be included
in the body.
files (dict, optional): Files to be sent with the request.
"""
self.http_method = http_method
self.query_url = query_url
self.headers = headers
self.query_parameters = query_parameters
self.parameters = parameters
self.files = files
def add_header(self, name, value):
""" Add a header to the HttpRequest.
Args:
name (string): The name of the header.
value (string): The value of the header.
"""
self.headers[name] = value
def add_parameter(self, name, value): # pragma: no cover
""" Add a parameter to the HttpRequest.
Args:
name (string): The name of the parameter.
value (string): The value of the parameter.
"""
self.parameters[name] = value
def add_query_parameter(self, name, value):
""" Add a query parameter to the HttpRequest.
Args:
name (string): The name of the query parameter.
value (string): The value of the query parameter.
"""
self.query_url = ApiHelper.append_url_with_query_parameters(
self.query_url,
{name: value}
)
self.query_url = ApiHelper.clean_url(self.query_url)
def __repr__(self):
return str(self.__dict__)