Beispiel #1
0
    def get(self):
        """ Obtains user data for a list of user id's

            Method: GET
            Path: /users

            Request Parameters:
            accessToken     string              token required to gain access to the resource
            users           JSON array          id's of the users
            pretty          [true|false]        whether to output in human readable format or not

            Returns:
            :return: a list with the data of the requested users
        """
        users_data = self.request.get('users')
        if users_data is '':
            self.write_signed_error(400, 'No users data was provided')
        try:
            user_keys = []
            for user_id in loads(users_data):
                user_keys.append(Key(User, user_id))
            query = User.query(User.key.IN(user_keys))
            result = []
            for user in query.fetch():
                result.append({
                    'id': user.key.id(),
                    'countryCode': user.country_code,
                    'rank': user.rank
                })
            self.write_signed_message(200, 'users', result)
        except ValueError:
            self.write_signed_error(400, 'Malformed JSON')
        except AttributeError:
            self.write_signed_error(400, 'Invalid data')
Beispiel #2
0
    def get(self):
        """ Obtains user data for a list of user id's

            Method: GET
            Path: /users

            Request Parameters:
            accessToken     string              token required to gain access to the resource
            users           JSON array          id's of the users
            pretty          [true|false]        whether to output in human readable format or not

            Returns:
            :return: a list with the data of the requested users
        """
        users_data = self.request.get('users')
        if users_data is '':
            self.write_signed_error(400, 'No users data was provided')
        try:
            user_keys = []
            for user_id in loads(users_data):
                user_keys.append(Key(User, user_id))
            query = User.query(User.key.IN(user_keys))
            result = []
            for user in query.fetch():
                result.append({'id': user.key.id(),
                               'countryCode': user.country_code,
                               'rank': user.rank})
            self.write_signed_message(200, 'users', result)
        except ValueError:
            self.write_signed_error(400, 'Malformed JSON')
        except AttributeError:
            self.write_signed_error(400, 'Invalid data')
Beispiel #3
0
    def get(self):
        """ Obtains the global leaderboard

            Method: GET
            Path: /leaderboards

            Request Parameters:
            accessToken     string              token required to gain access to the resource
            offset          int                 number of entries to skip
            limit           int                 maximum number of entries to return
            pretty          [true|false]        whether to output in human readable format or not

            Returns:
            :return: an array of user id's
        """
        query = User.query().order(-User.experience)
        self.query_leaderboard(query)
Beispiel #4
0
    def get(self):
        """ Obtains the global leaderboard

            Method: GET
            Path: /leaderboards

            Request Parameters:
            accessToken     string              token required to gain access to the resource
            offset          int                 number of entries to skip
            limit           int                 maximum number of entries to return
            pretty          [true|false]        whether to output in human readable format or not

            Returns:
            :return: an array of user id's
        """
        query = User.query().order(-User.experience)
        self.query_leaderboard(query)
Beispiel #5
0
    def get(self, country_code):
        """ Obtains the leaderboard for a country

            Method: GET
            Path: /leaderboards/{country_code}

            URI Parameters:
            country_code    sting               code for the country of the leaderboard

            Request Parameters:
            accessToken     string              token required to gain access to the resource
            offset          int                 number of entries to skip
            limit           int                 maximum number of entries to return
            pretty          [true|false]        whether to output in human readable format or not

            Parameters:
            :param country_code: code for the country of the leaderboard

            Returns:
            :return: an array of users id's
        """
        query = User.query().order(-User.experience).filter(User.country_code == country_code)
        self.query_leaderboard(query)
Beispiel #6
0
    def get(self, country_code):
        """ Obtains the leaderboard for a country

            Method: GET
            Path: /leaderboards/{country_code}

            URI Parameters:
            country_code    sting               code for the country of the leaderboard

            Request Parameters:
            accessToken     string              token required to gain access to the resource
            offset          int                 number of entries to skip
            limit           int                 maximum number of entries to return
            pretty          [true|false]        whether to output in human readable format or not

            Parameters:
            :param country_code: code for the country of the leaderboard

            Returns:
            :return: an array of users id's
        """
        query = User.query().order(-User.experience).filter(
            User.country_code == country_code)
        self.query_leaderboard(query)