This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathendpoints.py
66 lines (54 loc) · 2.08 KB
/
endpoints.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
import requests
import urllib3
import socket
from exceptions import ValorantAPIError
from auth import Auth
class Endpoints:
def __init__(self) -> None:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
auth = Auth()
self.headers = auth.getHeaders()
self.config = auth.getConfig()
self.port = self.config["port"]
def gameGetRequest(self, endpoint):
response = requests.get(
"https://127.0.0.1:{port}{endpoint}".format(
port=self.port, endpoint=endpoint
),
headers=self.headers,
verify=False,
)
# custom exceptions for http status codes
self.__verify_status_code(response.status_code)
try:
r = response.json()
return r
except:
raise ValorantAPIError("An error ocurred trying to get game APIs")
def __gamePostRequest(self, endpoint, data):
response = requests.post(
"https://127.0.0.1:{port}{endpoint}".format(
port=self.port, endpoint=endpoint
),
headers=self.headers,
verify=False,
json=data,
)
# custom exceptions for http status codes
self.__verify_status_code(response.status_code)
try:
r = response.json()
return r
except:
raise ValorantAPIError("An error ocurred trying to get game APIs")
def __verify_status_code(self, status_code):
"""Verify that the request was successful according to exceptions"""
if status_code in [404, 401, 500]:
raise ValorantAPIError("An invalid status code returned from game APIs")
def getChatToken(self):
return self.gameGetRequest("/chat/v6/conversations/ares-coregame")
def getChatHistorty(self, cid):
return self.gameGetRequest(f"/chat/v6/messages?cid={cid}")
def postNewChatMessage(self, cid, message):
data = {"cid": cid, "message": message, "type": "groupchat"}
return self.__gamePostRequest("/chat/v6/messages", data)