The API is based on MySQL and PHP.
Edit MySQL database server, user name, and password in /api/db.php
.
$db_servername = "localhost"; // Database server
$db_dbname = "bowling"; // Scheme name
$db_username = "dbadmin"; // Database user name
$db_password = "123456"; // Database user password
Run /api/db_setup.php
in web browser to create the scheme and the tables.
All the following usages can be found in index.html
.
POST /api/bowler.php
(Returns the id of the bowler added)
Sample Request
{
"firstname":"Xiaotian",
"lastname":"Le",
"email":"[email protected]",
"password":"123456"
}
Sample Response
{
"id":"1"
}
GET /api/bowler_list.php
Sample Response
[{
"id":"1",
"firstname":"Xiaotian",
"lastname":"Le",
"email":"[email protected]",
"reg_date":"2015-11-12 12:41:44",
"payouts":"30"
},
{
"id":"2",
"firstname":"Xiaotian",
"lastname":"Le",
"email":"[email protected]",
"reg_date":"2015-11-12 12:41:55",
"payouts":"0"
}]
GET /api/bowler.php
Sample Request
{
"bowler_id":"1"
}
Sample Response
{
"id":"1",
"firstname":"Xiaotian",
"lastname":"Le",
"email":"[email protected]",
"reg_date":"2015-11-12 01:11:15",
"payouts":"30"
}
POST /api/league.php
(Set capacity to 0 for unlimited capacity) (Returns the id of the league added)
Sample Request
{
"name":"Alpha",
"descr":"Description of Alpha League",
"capacity":"0"
}
Sample Response
{
"id":"1"
}
GET /api/league_list.php
Sample Response
[{
"id":"1",
"name":"Alpha",
"ticket_price":"1",
"estab_date":"2015-11-12 12:45:53",
"descr":"Description of Alpha League",
"capacity":"0",
"lottery_pool":"270",
"lottery_id":"201546",
"lottery_winner":"1"
},
{
"id":"2",
"name":"Beta",
"ticket_price":"1",
"estab_date":"2015-11-12 12:43:50",
"descr":"Description of Beta League",
"capacity":"10",
"lottery_pool":"0",
"lottery_id":null,
"lottery_winner":null
}]
GET /api/league.php
Sample Request
{
"league_id":"1"
}
Sample Response
{
"id":"1",
"name":"Alpha",
"ticket_price":"1",
"estab_date":"2015-11-12 12:45:53",
"descr":"Description of Alpha League",
"capacity":"0",
"lottery_pool":"270",
"lottery_id":"201546",
"lottery_winner":"1"
}
POST /api/league_members.php
(Returns the corresponding record id)
Sample Request
{
"league_id":"1",
"bowler_id":"1"
}
Sample Response
{
"id":"1"
}
GET /api/league_members.php
Sample Request
{
"league_id":"1"
}
Sample Response
[{
"id":"1",
"league_id":"1",
"bowler_id":"1",
"join_date":"2015-11-12 12:44:01"
},
{
"id":"2",
"league_id":"1",
"bowler_id":"2",
"join_date":"2015-11-12 12:44:02"
}]
POST /api/lottery_tickets.php
(Returns the lottery event id, the new amount of tickets owned, and the new lottery pool)
Sample Request
{
"league_id":"1",
"bowler_id":"1",
"tickets":"100"
}
Sample Response
{
"lotteryId":201546,
"newTickets":100,
"newLotteryPool":300
}
GET /api/lottery_tickets.php
Sample Request
{
"league_id":"1",
"bowler_id":"1"
}
Sample Response
{
"ticketPrice":"1",
"lotteryId":201546,
"tickets":"100",
"lotteryPool":"300"
}
POST /api/lottery_winner.php
(Returns the lottery event id, the lottery pool, and the winner's id)
Sample Request
{
"league_id":"1"
}
Sample Response
{
"lotteryId":201546,
"lotteryPool":"270",
"lotteryWinner":"1"
}
GET /api/lottery_winner.php
Sample Request
{
"league_id":"1"
}
Sample Response
{
"lotteryId":201546,
"lotteryPool":"270",
"lotteryWinner":"1"
}
POST /api/lottery_attempt.php
(Returns the lottery event id, the new lottery pool, the new payouts, and the money earned in the event)
Sample Request
{
"league_id":"1",
"bowler_id":"1",
"pins_knocked":"5"
}
Sample Response
{
"lotteryId":201546,
"newLotteryPool":270,
"newPayouts":60,
"earned":"30"
}
GET /api/lottery_attempt.php
Sample Request
{
"league_id":"1",
"bowler_id":"1",
}
Sample Response
{
"pins_knocked":"5"
}
All the exception texts are defined in /api/util_errors.php
.
Sample Response in Case of an Exception
{
"error":"Bowler not found."
}