Beispiel #1
0
        def POST():
            ourUser = self.db.users.get(self.steamID)
            if not ourUser.superuser:
                returnValue(ForbiddenResource())

            r = q.parse(
                { 'superuser': q.one(q.Boolean)
                }, request.args)
            superuser = r['superuser']

            url = request.content.read().strip()
            steamID = yield getSteamIDFromURL(url, self.steamAPI)
            if not steamID: returnValue(InvalidCommunityURL())

            response = yield self.steamAPI['ISteamUser'].GetPlayerSummaries(
                (steamID,))['response']
            if not len(response['players']):
                returnValue(
                    APIError(http.BAD_REQUEST, 'Steam user does not exist.'))

            try:
                user = self.db.users.add(steamID=steamID, superuser=superuser,
                                         adderSteamID=self.steamID)
            except ValueError:
                returnValue(APIError(http.BAD_REQUEST, 'User already exists.'))

            returnValue(user.toDict())
Beispiel #2
0
 def GET():
     args = q.parse({'steamids': q.one(q.Text)}, request.args)
     steamids = args['steamids'].split(',')
     def _tx():
         raw = self.steamAPI['ISteamUser'].GetPlayerSummaries(steamids)
         result = {}
         for player in raw['response']['players']:
             if player.get('gameid'):
                 status = 'in-game'
             else:
                 if player['personastate'] > 0:
                     status = 'online'
                 else:
                     status = 'offline'
             result[player['steamid']] = {
                 'status': status,
                 'personaname': player['personaname'],
                 'avatar': {
                     'small': player['avatar'],
                     'medium': player['avatarmedium'],
                     'large': player['avatarfull']
                 }
             }
         return result
     return deferToThread(_tx)
Beispiel #3
0
 def test_nonexistentExpected(self):
     """
     Query arguments that are not expected do not appear in the result.
     """
     self.assertThat(
         parse({}, {b'foo': [b'1']}),
         Equals({}))
Beispiel #4
0
 def test_nonexistentArgument(self):
     """
     If a query argument is expected but not found it appears as ``None`` in
     the result.
     """
     self.assertThat(
         parse({b'foo': one(Text)}, {}),
         Equals({b'foo': None}))
Beispiel #5
0
 def test_empty(self):
     """
     Parsing empty query arguments with no expected arguments results in an
     empty result.
     """
     self.assertThat(
         parse({}, {}),
         Equals({}))
Beispiel #6
0
    def test_parse(self):
        """
        Parse a query string.
        """
        query = {
            b'foo': [b'1', b'2'],
            b'bar': [],
            b'baz': [b'yes', b'1', b'False', b'huh'],
            b'quux': [b'hello', b'world']}

        self.assertThat(
            parse({b'foo': one(Integer),
                   b'bar': many(Integer),
                   b'baz': many(Boolean),
                   b'quux': many(Text),
                   b'notathing': many(Integer),
                   b'alsonotathing': one(Text)}, query),
            Equals({b'foo': 1,
                    b'bar': [],
                    b'baz': [True, True, False, None],
                    b'quux': [u'hello', u'world'],
                    b'notathing': [],
                    b'alsonotathing': None}))