import requests
import RiotConsts as Consts

class RiotAPI(object):

    def __init__(self, api_key, region = Consts.REGIONS['europe_west']):
        self.api_key = api_key
        self.region = region

    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(
                proxy = self.region,
                region = self.region,
                url = api_url
            ),
            params = args
        )
        # print(response.url)
        return response.json()

    def summoner_by_name(self, name):
        api_url = Consts.URL['summoner_by_name'].format(
            version = Consts.API_VERSIONS['summoner'],
            names = name
        )
        return self._request(api_url)

    def summoner_id(self, id):
        api_url = Consts.URL['summoner_id'].format(
            version = Consts.API_VERSIONS['summoner'],
            summonerids = id
        )
        return self._request(api_url)

    def summoner_masteries(self, id):
        api_url = Consts.URL['summoner_masteries'].format(
            version = Consts.API_VERSIONS['summoner'],
            summonerids = id
        )
        return self._request(api_url)

    def summoner_game(self, id):
        api_url = Consts.URL['game'].format(
            version = Consts.API_VERSIONS['game'],
            summonerids = id
        )
        return self._request(api_url)
 
