예제 #1
0
def api_enter_game(machine_id, game_id):
    try:

        if not is_machine(machine_id):
            return str(
                generate_error_reply_JSON(
                    "machine with that id don't exists!"))

        enter_game(machine_id, game_id)

        return str(generate_success_reply_JSON())

    except Exception as e:
        return str(generate_error_reply_JSON(str(e)))
예제 #2
0
def api_register_card(card_serial_number):

    try:
        validation_result = validate_card_serial_number(card_serial_number)
        if validation_result is not None:
            return str(generate_error_reply_JSON(validation_result))

        new_card = Card(serial_number=card_serial_number)
        db.session.add(new_card)
        db.session.commit()

        return str(generate_success_reply_JSON())

    except Exception as e:
        return str(generate_error_reply_JSON(str(e)))
예제 #3
0
def api_spin(machine_id):
    try:

        if not is_machine(machine_id):
            return str(
                generate_error_reply_JSON(
                    "machine with that id don't exists!"))

        body = request.get_json(force=True)

        spin(machine_id, body['bet'], body['timestamp'])

        return str(generate_success_reply_JSON())

    except Exception as e:
        return str(generate_error_reply_JSON(str(e)))
예제 #4
0
def api_login_card_into_machine(machine_id, card_serial_number):
    try:

        if not is_machine(machine_id):
            return str(
                generate_error_reply_JSON(
                    "machine with that id don't exists!"))

        if not is_card(card_serial_number):
            return str(generate_error_reply_JSON("this card don't exists!"))

        card_login(machine_id, card_serial_number)

        return str(generate_success_reply_JSON())

    except Exception as e:
        return str(generate_error_reply_JSON(str(e)))
예제 #5
0
 def test_generate_success_reply_JSON(self):
     self.assertEqual(generate_success_reply_JSON(), '{"success": 1}')