Browse Source

Fix teams query using team_ids[] param that actually works

theenglishway (time) 2 năm trước cách đây
mục cha
commit
787dee3eb0
1 tập tin đã thay đổi với 6 bổ sung12 xóa
  1. 6 12
      src/main/scala/BallDontLie.scala

+ 6 - 12
src/main/scala/BallDontLie.scala

@@ -122,7 +122,7 @@ object EndpointResponse {
     getAllData("https://www.balldontlie.io/api/v1/teams")
   }
 
-  def getGames(season: Int, teams: List[Int]): ListOfGames = {
+  def getGames(season: Int, teamIds: List[Int]): ListOfGames = {
     implicit val gamesResponseR: Reader[GamesResponse] = macroR[GamesResponse]
 
     def getAllData(
@@ -150,17 +150,11 @@ object EndpointResponse {
       }
     }
 
-    // Using an array as param to team_ids[] yields a 500 error so we make
-    // several requests instead
-    teams.flatMap(team => {
-      getAllData(
-        "https://www.balldontlie.io/api/v1/games",
-        List(
-          "seasons[]" -> List(season).mkString(","),
-          "team_ids[]" -> team
-        )
-      )
-    })
+    getAllData(
+      "https://www.balldontlie.io/api/v1/games",
+      List("seasons[]" -> List(season).mkString(","))
+        ++ teamIds.map("team_ids[]" -> _)
+    )
   }
 
   def getStats(game_ids: List[Int]): ListOfStats = {