-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRiotAPI.py
More file actions
76 lines (60 loc) · 2.36 KB
/
RiotAPI.py
File metadata and controls
76 lines (60 loc) · 2.36 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
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
import requests
import RiotConsts as Consts
import json
class RiotAPI(object):
def __init__(self, api_key):
self.api_key = api_key
def _request(self, api_url, params={}):
args = {'api_key': self.api_key}
for key, value in params.items():
if key not in args:
args[key] = value
response = requests.get(
Consts.URL['base'].format(
url = api_url
),
params = args
)
if response.status_code == 200:
return response.json()
elif response.status_code == 500:
print('The server seems to be having issues please try again later')
response.raise_for_status()
exit()
elif response.status_code == 404:
print('Please enter a valid Summoner name')
response = 'bad username'
return response
elif response.status_code == 403:
print('Please enter a current api')
response = 'bad api'
return response
else:
print('Please confirm your Api is up to date and was entered correctly')
response.raise_for_status()
exit()
def get_entries_by_summonerid(self, encryptedSummonerId):
api_url = Consts.URL['entries_by_summoner'].format(
version = Consts.API_VERSIONS['V4'],
summonerid = encryptedSummonerId
)
return self._request(api_url)
def get_summoner_by_name(self, name):
api_url = Consts.URL['summoner_by_name'].format(
version = Consts.API_VERSIONS['V4'],
names = name
)
return self._request(api_url)
def get_masteries_by_summonerid(self, encryptedSummonerId, championId):
api_url = Consts.URL['masteries_by_summoner'].format(
version = Consts.API_VERSIONS['V4'],
summonerid = encryptedSummonerId,
Id = championId
)
return self._request(api_url)
def get_all_masteries_by_summonerid(self, encryptedSummonerId):
api_url = Consts.URL['all_masteries_by_summoner'].format(
version = Consts.API_VERSIONS['V4'],
summonerid = encryptedSummonerId
)
return self._request(api_url)