-
Notifications
You must be signed in to change notification settings - Fork 2
/
abstract_request.py
42 lines (35 loc) · 1.2 KB
/
abstract_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
#!/usr/local/lib/python2.7/
#Abstract request class
import requests
from config import auth_config
AUTH = auth_config()
class AbstractSimpleRequest:
""" Abstract request class """
def __init__(self, url):
self.url = url
def post(self):
""" Post request """
response = requests.post(url=self.url)
return response
def get(self):
""" Get request """
headers = {'Authorization': 'Token '+ AUTH.get_auth_token()}
response = requests.get(self.url, headers=headers)
return response
class AbstractDataRequest:
""" Abstract request class """
def __init__(self, url, data):
self.url = url
self.data = data
def post(self):
""" Post request """
headers = {'Authorization': 'Token '+ AUTH.get_auth_token(), 'Content-Type': 'application/json'}
print self.data
response = requests.post(url=self.url, data=self.data, headers=headers)
print response.text
return response
def get(self):
""" Get request """
headers = {'Authorization': 'Token '+ AUTH.get_auth_token()}
response = requests.get(self.url, data=self.data, headers=headers)
return response