def recieve_code(self, request): """Uses the login code provided by Facebook and logs in the user.""" account = actions.grant_user_access_from_code(REDIRECT_URL, code=request.code) user = account.key.parent().get() return_msg = mmglue.message_from_model(account, fbmsgs.FacebookAccountWithUser) return_msg.user = mmglue.message_from_model(user, usrmessages.UserMe) return_msg.user.token = user.get_token() return return_msg
def test_message_from_model(): model = DummyModel(name="Adrian", alias=["Bob", "Mac"]) msg = mmglue.message_from_model(model, DummyMessage) assert msg.name == 'Adrian'
def game_model_to_message(game): """Convert a game model into a message.""" msg = mmglue.message_from_model(game, messages.Game) msg.key = game.key.urlsafe() if game.geo: msg.lat = game.geo.lat msg.lon = game.geo.lon categories = ndb.get_multi(game.category) msg.categories_full = [ sport_category_to_message(category) for category in categories ] list_of_player_keys = game.players[-5:] list_of_players = ndb.get_multi(list_of_player_keys) # Sanity Check if None in list_of_players: none_index = list_of_players.index(None) user_key = list_of_player_keys[none_index] user_id = user_key.id() raise NotFoundException( "A user (key: %s id: %d) in this game (key: %s id: %d) could not be found in the database!" % (user_key, user_id, game.key, game.key.id())) msg.players = [user_to_message(player) for player in list_of_players] msg.player_ids = [player.id() for player in game.players] msg.time_as_UTC_timestamp = int(misc.datetime_to_timestamp(game.time)) return msg
def me_to_message(user): """ Takes a user and returns a user message containing their credentials. """ msg = mmglue.message_from_model(user, messages.UserMe) msg.token = user.get_token() return msg
def friend_request(self, request): """Send a friend request.""" auth_user = actions.verify_and_get_user(token=request.token) relationship = actions.friend_request(auth_user.key.id(), request.user) msg = mmglue.message_from_model(relationship, messages.Relationship) msg.users = [k.id() for k in relationship.users] return msg
def get_relationship(self, request): """ Returns the relationship between two users. """ actions.verify_and_get_user(token=request.token) relationship = actions.get_relationship(request.userA, request.userB) msg = mmglue.message_from_model(relationship, messages.Relationship) msg.users = [k.id() for k in relationship.users] return msg
def unfriend(self, request): """ Remove the specified user as a friend of the authenticating user. """ auth_user = actions.verify_and_get_user(token=request.token) relationship = actions.unfriend(auth_user.key.id(), request.user) msg = mmglue.message_from_model(relationship, messages.Relationship) msg.users = [k.id() for k in relationship.users] return msg
def respond_to_friend_request(self, request): """ Answer a friend request from a user to the authenticating user. """ auth_user = actions.verify_and_get_user(token=request.token) relationship = actions.respond_to_friend_request( auth_user, request.user, request.accept) msg = mmglue.message_from_model(relationship, messages.Relationship) msg.users = [k.id() for k in relationship.users] return msg
def sport_category_to_message(category): """Convert a sport category model into a message.""" msg = mmglue.message_from_model(category, messages.SportCategory) msg.paths = category.paths msg.parent_ids = [c.id() for c in category.parents] return msg
def user_to_message(user): """ Takes a user and returns a general user message. """ msg = mmglue.message_from_model(user, messages.User) return msg