-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_client.py
More file actions
44 lines (33 loc) · 1.07 KB
/
Copy pathbase_client.py
File metadata and controls
44 lines (33 loc) · 1.07 KB
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
import requests
class BaseClient:
# URL vk api
BASE_URL = None
# метод vk api
method = None
# GET, POST, ...
http_method = None
# Получение GET параметров запроса
def get_params(self):
return None
# Получение данных POST запроса
def get_json(self):
return None
# Получение HTTP заголовков
def get_headers(self):
return None
# Склейка url
def generate_url(self, method):
return '{0}{1}'.format(self.BASE_URL, method)
# Отправка запроса к VK API
def _get_data(self, method, http_method):
resp = requests.get(self.BASE_URL + self.method, params=self.get_params())
return self.response_handler(resp)
# Обработка ответа от VK API
def response_handler(self, response):
return response
# Запуск клиента
def execute(self):
return self._get_data(
self.method,
http_method=self.http_method
)