|
@@ -25,30 +25,55 @@ object Utils {
|
|
|
|
|
|
|
|
ujson.read(r.text())
|
|
ujson.read(r.text())
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ def read[T: Reader](json: ujson.Value): T = {
|
|
|
|
|
+ upickle.default.read[T](json)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
case class GamesResponse(data: List[GameData], meta: ResponseMetadata)
|
|
case class GamesResponse(data: List[GameData], meta: ResponseMetadata)
|
|
|
object GamesResponse {
|
|
object GamesResponse {
|
|
|
implicit val gamesResponseR: Reader[GamesResponse] = macroR[GamesResponse]
|
|
implicit val gamesResponseR: Reader[GamesResponse] = macroR[GamesResponse]
|
|
|
|
|
+ val endpoint = "https://www.balldontlie.io/api/v1/games"
|
|
|
|
|
|
|
|
val getGames = (season: Int, teams: List[Int]) => {
|
|
val getGames = (season: Int, teams: List[Int]) => {
|
|
|
- val json = Utils.get_json(
|
|
|
|
|
- "https://www.balldontlie.io/api/v1/games",
|
|
|
|
|
- Map(
|
|
|
|
|
- "seasons[]" -> List(season).mkString(","),
|
|
|
|
|
- "team_ids[]" -> teams.mkString(",")
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ val baseParams = Map(
|
|
|
|
|
+ "seasons[]" -> List(season).mkString(","),
|
|
|
|
|
+ "team_ids[]" -> teams.mkString(",")
|
|
|
)
|
|
)
|
|
|
- upickle.default.read[GamesResponse](json)
|
|
|
|
|
|
|
+ val json =
|
|
|
|
|
+ Utils.get_json(endpoint, baseParams)
|
|
|
|
|
+
|
|
|
|
|
+ val response: GamesResponse = upickle.default.read[GamesResponse](json)
|
|
|
|
|
+ if (response.meta.current_page != response.meta.total_pages) {
|
|
|
|
|
+ val json = Utils.get_json(
|
|
|
|
|
+ endpoint,
|
|
|
|
|
+ baseParams + ("page" -> response.meta.next_page.toString())
|
|
|
|
|
+ )
|
|
|
|
|
+ Utils.read[GamesResponse](json)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ response
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
case class TeamsResponse(data: List[Team], meta: ResponseMetadata)
|
|
case class TeamsResponse(data: List[Team], meta: ResponseMetadata)
|
|
|
object TeamsResponse {
|
|
object TeamsResponse {
|
|
|
implicit val teamsResponseR: Reader[TeamsResponse] = macroR[TeamsResponse]
|
|
implicit val teamsResponseR: Reader[TeamsResponse] = macroR[TeamsResponse]
|
|
|
|
|
+ val endpoint = "https://www.balldontlie.io/api/v1/teams"
|
|
|
|
|
+
|
|
|
|
|
+ val getTeams: TeamsResponse = {
|
|
|
|
|
+ val json = Utils.get_json(endpoint, Nil)
|
|
|
|
|
+ val response: TeamsResponse = Utils.read[TeamsResponse](json)
|
|
|
|
|
|
|
|
- val getTeams = {
|
|
|
|
|
- val json = Utils.get_json("https://www.balldontlie.io/api/v1/teams", Nil)
|
|
|
|
|
- upickle.default.read[TeamsResponse](json)
|
|
|
|
|
|
|
+ if (response.meta.current_page != response.meta.total_pages) {
|
|
|
|
|
+ val json = Utils.get_json(
|
|
|
|
|
+ endpoint,
|
|
|
|
|
+ Map("page" -> response.meta.next_page.toString())
|
|
|
|
|
+ )
|
|
|
|
|
+ Utils.read[TeamsResponse](json)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ response
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|