Skip to content

Commit

Permalink
mobile API request
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed May 7, 2018
1 parent 67db8bd commit 39e20f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/controllers/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ object Api extends LilaController {
token = get("token", req)
)

def userGames(name: String) = ApiRequest { req =>
// for mobile app
def userGames(name: String) = MobileApiRequest { req =>
val page = (getInt("page", req) | 1) atLeast 1 atMost 200
val nb = (getInt("nb", req) | 10) atLeast 1 atMost 100
val cost = page * nb + 10
Expand Down Expand Up @@ -314,6 +315,10 @@ object Api extends LilaController {
def ApiRequest(js: RequestHeader => Fu[ApiResult]) = Action.async { req =>
js(req) map toHttp
}
def MobileApiRequest(js: RequestHeader => Fu[ApiResult]) = Action.async { req =>
if (lila.api.Mobile.Api requested req) js(req) map toHttp
else fuccess(NotFound)
}

private[controllers] val tooManyRequests = TooManyRequest(jsonError("Error 429: Too many requests! Try again later."))

Expand Down
4 changes: 3 additions & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ GET /stat/rating/distribution/:perf controllers.Stat.ratingDistribution(perf:
GET /api controllers.Api.index
POST /api/users controllers.Api.usersByIds
GET /api/user/:name controllers.Api.user(name: String)
GET /api/user/:name/games controllers.Api.userGames(name: String)
GET /api/user/:name/activity controllers.Api.activity(name: String)
GET /api/game/:id controllers.Api.game(id: String)
GET /api/games/team/:teamId controllers.Api.gamesVsTeam(teamId: String)
Expand All @@ -511,6 +510,9 @@ GET /api/account/preferences controllers.Pref.apiGet
POST /api/challenge/$id<\w{8}>/accept controllers.Challenge.apiAccept(id: String)
POST /api/challenge/$id<\w{8}>/decline controllers.Challenge.apiDecline(id: String)

# Mobile API only
GET /api/user/:name/games controllers.Api.userGames(name: String)

# Bot API
GET /api/bot/game/stream/:id controllers.Bot.gameStream(id: String)
POST /api/bot/game/:id/move/:uci controllers.Bot.move(id: String, uci: String)
Expand Down
3 changes: 3 additions & 0 deletions modules/common/src/main/mon.scala
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@ object mon {
}
}
object api {
object userGames {
val cost = incX("api.user-games.cost")
}
object users {
val cost = incX("api.users.cost")
}
Expand Down

0 comments on commit 39e20f2

Please sign in to comment.