def post(self):
        try:
            self.parser.add_argument('username',
                                     required=True,
                                     help="username cannot be blank!")
            self.parser.add_argument('password',
                                     required=True,
                                     help="password cannot be blank!")
            args = self.parser.parse_args()
            response = self.shared_api_client.login(args["username"],
                                                    args["password"])
            if not response:
                return ErrorHandler.create_error_response("Invalid Login", 401)

            return ResponseBuilder.build_response(response, 201)

        except RequestException as e:
            return ErrorHandler.create_error_response(str(e), 500)

        except BadRequest as ex:
            return ErrorHandler.create_error_response(
                "Fields username and password are mandatory", 400)

        except UserNotExistsException as e:
            return ErrorHandler.create_error_response(str(e), 409)
Esempio n. 2
0
	def put(self, id):
		try:
			self.parser.add_argument('_id', required=True, help="Field id is mandatory")
			self.parser.add_argument('_rev', required=True, help="Field rev is mandatory")
			self.parser.add_argument('title', required=True, help="Field title is mandatory")
			self.parser.add_argument('location', required=True, help="Field location is mandatory")
			self.parser.add_argument('visibility', required=True, help="Field visibility is mandatory")
			self.parser.add_argument('multimedia', required=True, help="Field multimedia is mandatory")
			self.parser.add_argument('story_type', required=True, help="Field story_type is mandatory")
			self.parser.add_argument('user_id', required=True, help="Field user_id is mandatory")

			self._validate_author(id)
			args = self.parser.parse_args()
			
			body = json.loads(request.data.decode('utf-8'))

			storie = StorieModel.update_storie(id, body)
			UserActivityModel.log_storie_activity(storie["user_id"], storie["_id"], "EDIT")
			return ResponseBuilder.build_response(storie, 200)

		except BadRequest as ex:
			return ErrorHandler.create_error_response("Fields id, rev, title, location, user_id, visibility, multimedia and story_type are mandatory", 400)
		except NoStorieFoundException as e:
			return ErrorHandler.create_error_response(str(e), 404)
		except DataVersionException as e:
			return ErrorHandler.create_error_response(str(e), 409)
		except UserMismatchException as e:
			return ErrorHandler.create_error_response(str(e), 409)
		except DBConnectionError as e:
			return ErrorHandler.create_error_response(str(e), 500)
Esempio n. 3
0
 def get(self):
     try:
         fromHour = request.args.get('from')
         toHour = request.args.get('to')
         requests = RequestCounterModel.get_requests(fromHour=fromHour,
                                                     toHour=toHour)
         return ResponseBuilder.build_response(requests, 200)
     except DBConnectionError as e:
         return ErrorHandler.create_error_response(str(e), 500)
 def _create_get_response(self, user_data, stories, friends,
                          friends_requests_rcv, friends_requests_sent):
     profile_json = self.__get_profile_json(user_data)
     profile_json['stories'] = stories
     profile_json['friends'] = friends
     profile_json['requests'] = {
         "sent": friends_requests_sent,
         "rcv": friends_requests_rcv
     }
     return ResponseBuilder.get_build_response(profile_json, 'profile', 200)
Esempio n. 5
0
 def post(self):
     app = Flask(__name__)
     registration_id, message = self._get_notification_request_data(request)
     push_service = FCMNotification(api_key=FCM_SERVER_KEY)
     result = push_service.notify_single_device(
         registration_id=registration_id,
         message_title='Stories',
         message_body=message)
     if not result:
         return ErrorHandler.create_error_response(
             "Error communicating with firebase cloud messaging", 40)
     return ResponseBuilder.build_response(result, 200)
Esempio n. 6
0
	def delete(self, id):
		try:
			self._validate_author(id)
			body = json.loads(request.data.decode('utf-8'))
			storie_user_id = body['user_id']
			storie = StorieModel.delete_storie(id, storie_user_id)
			UserActivityModel.log_storie_activity(storie["user_id"], storie["_id"], "DELETE")
			return ResponseBuilder.build_response(storie, 204)
		except NoStorieFoundException as e:
			return ErrorHandler.create_error_response(str(e), 404)
		except UserMismatchException as e:
			return ErrorHandler.create_error_response(str(e), 409)
		except DBConnectionError as e:
			return ErrorHandler.create_error_response(str(e), 500)
    def _get_appserver_stats_response(self):
        stats = {
            "numUsers": self._get_num_users(),
            "numUsersActiveToday": self._get_num_users_today(),
            "numStories": self._get_num_stories(),
            "numStoriesToday": self._get_num_stories_today(),
            "numFastStoriesToday": self._get_num_fast_stories_today(),
            "numUsersMessages": self._get_num_user_messages(),
            "numUsersMessagesToday": self._get_num_user_messages_today(),
            "numAcceptedContactsToday":
            self._get_num_accepted_contacts_today()
        }

        return ResponseBuilder.get_build_response(stats, 'stats', 200)
Esempio n. 8
0
 def delete(self, id):
     try:
         self._validate_friendship(id)
         friend = FriendModel.delete_friend(id)
         UserActivityModel.log_friend_activity(friend["user_id_rcv"],
                                               friend["user_id_sender"],
                                               "DELETE")
         UserActivityModel.log_friend_activity(friend["user_id_sender"],
                                               friend["user_id_rcv"],
                                               "DELETE")
         return ResponseBuilder.build_response(friend, 204)
     except NoFriendFoundException as e:
         return ErrorHandler.create_error_response(str(e), 404)
     except UserMismatchException as e:
         return ErrorHandler.create_error_response(str(e), 409)
     except DBConnectionError as e:
         return ErrorHandler.create_error_response(str(e), 500)
    def get(self, user_id):
        if not user_id:
            return ErrorHandler.create_error_response("Field id is mandatory",
                                                      400)

        try:
            response = self.shared_api_client.getUserById(user_id)
            if not response:
                return ErrorHandler.create_error_response(
                    "User doesn't exists", 404)

            return ResponseBuilder.build_response(response, 200)

        except RequestException as e:
            return ErrorHandler.create_error_response(str(e), 500)

        except BadRequest as ex:
            return ErrorHandler.create_error_response(str(ex), 400)
    def put(self, comment_id):
        try:
            self.parser.add_argument('_id',
                                     required=True,
                                     help="Field id is mandatory")
            self.parser.add_argument('_rev',
                                     required=True,
                                     help="Field rev is mandatory")
            self.parser.add_argument('storie_id',
                                     required=True,
                                     help="Field storie_id is mandatory")
            self.parser.add_argument('user_id',
                                     required=True,
                                     help="Field user_id is mandatory")
            self.parser.add_argument('message',
                                     required=True,
                                     help="Field message is mandatory")

            self._validate_author(comment_id)
            args = self.parser.parse_args()

            body = json.loads(request.data.decode('utf-8'))
            comment = CommentModel.update_comment(comment_id, body)
            UserActivityModel.log_comment_activity(comment["user_id"],
                                                   comment["storie_id"],
                                                   "EDIT")

            return ResponseBuilder.build_response(comment, 200)

        except BadRequest as ex:
            return ErrorHandler.create_error_response(
                "Fields id, rev, storie_id, user_id and message are mandatory",
                400)
        except NoUserDataFoundException as e:
            return ErrorHandler.create_error_response(str(e), 400)
        except NoCommentFoundException as e:
            return ErrorHandler.create_error_response(str(e), 404)
        except DataVersionException as e:
            return ErrorHandler.create_error_response(str(e), 409)
        except UserMismatchException as e:
            return ErrorHandler.create_error_response(str(e), 409)
        except DBConnectionError as e:
            return ErrorHandler.create_error_response(str(e), 500)
Esempio n. 11
0
    def post(self):
        try:
            # save mandatory fields on app server
            self.parser.add_argument('id',
                                     required=True,
                                     help="Field id is mandatory")  # fb id
            self.parser.add_argument(
                'username', required=True,
                help="Field username is mandatory")  # fb email
            self.parser.add_argument('password',
                                     required=True,
                                     help="Field password is mandatory")

            args = self.parser.parse_args()

        except BadRequest as ex:
            return ErrorHandler.create_error_response(
                "Fields id, username and password are mandatory", 400)

        try:
            # save optionals fields on app server
            self.parser.add_argument('name', required=False)
            self.parser.add_argument('first_name', required=False)
            self.parser.add_argument('last_name', required=False)
            self.parser.add_argument('gender', required=False)
            self.parser.add_argument('picture', required=False)
            self.parser.add_argument('facebookAccount', required=False)

            response = self.shared_api_client.userCreate(
                args["id"], args["username"], args["password"])
            if not response:
                return ErrorHandler.create_error_response("Invalid Login", 401)

            user_id = response["user"]["id"]
            username = response["user"]["username"]
            UserDataModel.insert_user(user_id, username)
            return ResponseBuilder.build_response(response, 200)

        except RequestException as e:
            return ErrorHandler.create_error_response(str(e), 500)

        except BadRequest as ex:
            return ErrorHandler.create_error_response(str(ex), 400)
Esempio n. 12
0
	def _create_get_response(self, user_data):
		return ResponseBuilder.get_build_response(user_data, 'users', 200)
Esempio n. 13
0
 def get(self):
     response = {'hello': "appServer"}
     return ResponseBuilder.build_response(response, 200)
 def __create_put_response(self, user_data):
     return ResponseBuilder.build_response(user_data, 200)