document /tv/channels and add jsonp support

pull/3969/head
Thibault Duplessis 2018-01-07 21:05:32 -05:00
parent 784e8257a2
commit 18fe3d425f
3 changed files with 13 additions and 3 deletions

View File

@ -636,6 +636,16 @@ curl 'https://lichess.org/api/tournament/x5WNIngd?page=1'
JSONP is available.
### `GET /tv/channels` fetch current tournaments
Returns the current game ID and best player for each TV channel: https://lichess.org/tv
```
> curl https://lichess.org/tv/channels
```
JSONP is available.
Credits
-------

View File

@ -295,7 +295,7 @@ object Api extends LilaController {
def toApiResult(json: Option[JsValue]): ApiResult = json.fold[ApiResult](NoData)(Data.apply)
def toApiResult(json: Seq[JsValue]): ApiResult = Data(JsArray(json))
private def ApiRequest(js: Context => Fu[ApiResult]) = Open { implicit ctx =>
def ApiRequest(js: Context => Fu[ApiResult]) = Open { implicit ctx =>
js(ctx) map toHttp
}

View File

@ -28,12 +28,12 @@ object Tv extends LilaController {
}
}
def channels = Action.async {
def channels = Api.ApiRequest { implicit ctx =>
import play.api.libs.json._
implicit val championWrites = Json.writes[lila.tv.Tv.Champion]
Env.tv.tv.getChampions map {
_.channels map { case (chan, champ) => chan.name -> champ }
} map { Json.toJson(_) } map { Ok(_) }
} map { Json.toJson(_) } map Api.Data.apply
}
private def lichessTv(channel: lila.tv.Tv.Channel)(implicit ctx: Context) =