Beispiel #1
0
 async def delete(self, session):
     async with session.delete(self.base_url() + '.json',
                               params={'api_key': challonge.api_key}) as r:
         if r.status == 200:
             return True
         else:
             error.raise_error(r)
Beispiel #2
0
 async def checkin(self, session):
     async with session.post(self.base_url() + '/check_in.json',
                             json={'api_key': challonge.api_key}) as r:
         if r.status == 200:
             return True
         else:
             error.raise_error(r)
Beispiel #3
0
 async def clear_participants(self):
     async with session.delete(self.base_url() + '/participants/clear.json',
                               params={'api_key': challonge.api_key}) as r:
         if r.status == 200:
             return True
         else:
             error.raise_error(r)
Beispiel #4
0
 async def svg(self, session):
     async with session.get('https://challonge.com/' + str(self.url) +
                            '.svg',
                            params={'api_key': challonge.api_key}) as r:
         if r.status == 200:
             return await r.text()
         else:
             error.raise_error(r)
Beispiel #5
0
 async def randomize_participants(self):
     async with session.post(self.base_url() +
                             '/participants/randomize.json',
                             params={'api_key': challonge.api_key}) as r:
         if r.status == 200:
             return True
         else:
             error.raise_error(r)
Beispiel #6
0
 async def get(self, session, include_matches=False):
     async with session.get(self.base_url() + '.json',
                            params={'api_key': challonge.api_key}) as r:
         if r.status == 200:
             data = await r.json()
             return Participant(data=data)
         else:
             error.raise_error(r)
Beispiel #7
0
    async def update(self, session):
        params = self.update_params()

        async with session.put(self.base_url() + '.json', json=params) as r:
            if r.status == 200:
                data = await r.json()
                return self.update_object(data['tournament'])
            else:
                error.raise_error(r)
Beispiel #8
0
 async def create(self, session):
     params = self.update_params()
     if 'id' in params: params.pop('id', None)
     async with session.post(self.base_url() + '.json', json=params) as r:
         if r.status == 200:
             data = await r.json()
             return self.update_object(data['participant'])
         else:
             error.raise_error(r)
Beispiel #9
0
    async def add_participant(self, session, data={}):
        data.update({'api_key': challonge.api_key})

        async with session.post(self.base_url() + '/participants.json',
                                json=data) as r:
            if r.status == 200:
                data = await r.json()
                return Participant(data=data['participant'])
            else:
                error.raise_error(r)
Beispiel #10
0
 async def create(self):
     params = self.update_params()
     if 'id' in params: params.pop('id', None)
     async with session.post(api_base + 'tournaments/' + str(self.id) +
                             '.json?api_key=' + challonge.api_key,
                             json=params) as r:
         if r.status == 200:
             data = await r.json()
             return self.update_object(data['tournament'])
         else:
             error.raise_error(r)
Beispiel #11
0
    async def match(self, session, mid, include_attachments=False):
        url = self.base_url() + '/matches/' + str(mid) + '.json'
        if include_attachments: url += '?include_attachments=1'

        async with session.get(url, params={'api_key':
                                            challonge.api_key}) as r:
            if r.status == 200:
                data = await r.json()
                return Match(data=data)
            else:
                error.raise_error(r)
Beispiel #12
0
    async def get_by_misc(self, session, misc, include_matches=False):
        async with session.get(self.tournament_url() + '/participants.json',
                               params={'api_key': challonge.api_key}) as r:
            if r.status == 200:
                data = await r.json()

                for p in data:
                    if p['participant']['misc'] == misc:
                        return Participant(data=p['participant'])

                return None
            else:
                error.raise_error(r)
Beispiel #13
0
    async def get(self,
                  session,
                  include_participants=False,
                  include_matches=False):
        url = self.base_url() + '.json?'
        if include_participants: url += 'include_participants=1&'
        if include_matches: url += 'include_matches=1&'

        async with session.get(url, params={'api_key':
                                            challonge.api_key}) as r:
            if r.status == 200:
                data = await r.json()
                return self.update_object(data['tournament'])
            else:
                error.raise_error(r)
Beispiel #14
0
    async def matches(self,
                      session,
                      include_attachments=False,
                      reload_array=False):
        url = self.base_url() + '/matches.json'
        if include_attachments: url += '?include_attachments=1'

        async with session.get(url, params={'api_key':
                                            challonge.api_key}) as r:
            if r.status == 200:
                data = await r.json()
                plist = self.build_matches(data)
                if reload_array:
                    setattr(self, 'matches', plist)
                return plist
            else:
                error.raise_error(r)
Beispiel #15
0
 async def delete(self, session):
     async with session.delete(self.base_url() + '.json') as r:
         if r.status == 200:
             return True
         else:
             error.raise_error(r)