From df34d7b8c5ebc80a1a0c2f18d62d61f9dd55e72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro?= Date: Wed, 1 May 2024 12:07:07 +0200 Subject: [PATCH] Create struct for match --- apps/scrapper/lib/scrapper/data/match_api.ex | 8 +- .../lib/scrapper/data/model/match/info.ex | 20 +++ .../data/model/match/match_response.ex | 7 + .../lib/scrapper/data/model/match/metadata.ex | 3 + .../scrapper/data/model/match/participant.ex | 135 ++++++++++++++++++ apps/scrapper/mix.exs | 3 +- mix.lock | 1 + 7 files changed, 175 insertions(+), 2 deletions(-) create mode 100644 apps/scrapper/lib/scrapper/data/model/match/info.ex create mode 100644 apps/scrapper/lib/scrapper/data/model/match/match_response.ex create mode 100644 apps/scrapper/lib/scrapper/data/model/match/metadata.ex create mode 100644 apps/scrapper/lib/scrapper/data/model/match/participant.ex diff --git a/apps/scrapper/lib/scrapper/data/match_api.ex b/apps/scrapper/lib/scrapper/data/match_api.ex index 4db3379..b11ddd4 100644 --- a/apps/scrapper/lib/scrapper/data/match_api.ex +++ b/apps/scrapper/lib/scrapper/data/match_api.ex @@ -2,6 +2,11 @@ defmodule Scrapper.Data.MatchApi do @match_base_endpoint "https://europe.api.riotgames.com/lol/match/v5/matches/%{matchid}" @puuid_matches_base_endpoint "https://europe.api.riotgames.com/lol/match/v5/matches/by-puuid/%{puuid}/ids" + @doc """ + Get match by id + + iex> Scrapper.Data.MatchApi.get_match_by_id("EUW1_6921743825") + """ @spec get_match_by_id(String.t()) :: any() def get_match_by_id(match_id) do url = String.replace(@match_base_endpoint, "%{matchid}", match_id) @@ -12,7 +17,8 @@ defmodule Scrapper.Data.MatchApi do case response.status_code do 200 -> # process the response here - IO.inspect(response.body) + response.body + Poison.decode!(response.body, as: %Scrapper.Data.Model.Match.MatchResponse{}) _ -> # handle error responses diff --git a/apps/scrapper/lib/scrapper/data/model/match/info.ex b/apps/scrapper/lib/scrapper/data/model/match/info.ex new file mode 100644 index 0000000..a2ee26f --- /dev/null +++ b/apps/scrapper/lib/scrapper/data/model/match/info.ex @@ -0,0 +1,20 @@ +defmodule Scrapper.Data.Model.Match.Info do + alias Scrapper.Data.Model.Match.Participant + + defstruct endOfGameResult: "", + gameCreation: "", + gameDuration: "", + gameEndTimestamp: "", + gameId: "", + gameMode: "", + gameName: "", + gameStartTimestamp: "", + gameType: "", + gameVersion: "", + mapId: "", + participants: [%Participant{}], + platformId: "", + queueId: "", + teams: "", + tournamentCode: "" +end diff --git a/apps/scrapper/lib/scrapper/data/model/match/match_response.ex b/apps/scrapper/lib/scrapper/data/model/match/match_response.ex new file mode 100644 index 0000000..4dd0fe9 --- /dev/null +++ b/apps/scrapper/lib/scrapper/data/model/match/match_response.ex @@ -0,0 +1,7 @@ +defmodule Scrapper.Data.Model.Match.MatchResponse do + alias Scrapper.Data.Model.Match.Info + alias Scrapper.Data.Model.Match.Metadata + + defstruct metadata: %Metadata{}, + info: %Info{} +end diff --git a/apps/scrapper/lib/scrapper/data/model/match/metadata.ex b/apps/scrapper/lib/scrapper/data/model/match/metadata.ex new file mode 100644 index 0000000..248626a --- /dev/null +++ b/apps/scrapper/lib/scrapper/data/model/match/metadata.ex @@ -0,0 +1,3 @@ +defmodule Scrapper.Data.Model.Match.Metadata do + defstruct [:dataVersion, :matchId, :participants] +end diff --git a/apps/scrapper/lib/scrapper/data/model/match/participant.ex b/apps/scrapper/lib/scrapper/data/model/match/participant.ex new file mode 100644 index 0000000..7b8dfa8 --- /dev/null +++ b/apps/scrapper/lib/scrapper/data/model/match/participant.ex @@ -0,0 +1,135 @@ +defmodule Scrapper.Data.Model.Match.Participant do + # Enum.map(participant, fn {k,_v} -> ":#{k}" end) |> Enum.join(", ") + defstruct [ + :onMyWayPings, + :totalDamageDealt, + :summoner1Casts, + :totalEnemyJungleMinionsKilled, + :summoner2Casts, + :totalTimeCCDealt, + :eligibleForProgression, + :enemyVisionPings, + :assists, + :teamPosition, + :objectivesStolenAssists, + :perks, + :spell3Casts, + :totalHeal, + :doubleKills, + :missions, + :physicalDamageDealt, + :summonerName, + :champExperience, + :quadraKills, + :neutralMinionsKilled, + :basicPings, + :pushPings, + :playerAugment2, + :wardsPlaced, + :individualPosition, + :damageSelfMitigated, + :dangerPings, + :largestMultiKill, + :puuid, + :subteamPlacement, + :turretsLost, + :role, + :visionClearedPings, + :goldSpent, + :inhibitorTakedowns, + :summoner2Id, + :trueDamageDealtToChampions, + :needVisionPings, + :champLevel, + :championTransform, + :bountyLevel, + :teamEarlySurrendered, + :championName, + :largestKillingSpree, + :gameEndedInSurrender, + :summoner1Id, + :getBackPings, + :nexusKills, + :baronKills, + :item6, + :firstTowerKill, + :summonerLevel, + :damageDealtToTurrets, + :commandPings, + :totalHealsOnTeammates, + :turretTakedowns, + :playerSubteamId, + :longestTimeSpentLiving, + :item0, + :summonerId, + :assistMePings, + :wardsKilled, + :physicalDamageTaken, + :magicDamageDealt, + :timePlayed, + :item2, + :firstBloodKill, + :goldEarned, + :magicDamageDealtToChampions, + :item1, + :nexusLost, + :itemsPurchased, + :tripleKills, + :sightWardsBoughtInGame, + :placement, + :consumablesPurchased, + :item5, + :totalDamageTaken, + :item4, + :playerAugment4, + :physicalDamageDealtToChampions, + :spell1Casts, + :totalTimeSpentDead, + :nexusTakedowns, + :gameEndedInEarlySurrender, + :dragonKills, + :totalAllyJungleMinionsKilled, + :killingSprees, + :detectorWardsPlaced, + :trueDamageDealt, + :damageDealtToObjectives, + :damageDealtToBuildings, + :totalDamageDealtToChampions, + :lane, + :totalMinionsKilled, + :playerAugment3, + :spell2Casts, + :pentaKills, + :firstTowerAssist, + :enemyMissingPings, + :turretKills, + :championId, + :trueDamageTaken, + :deaths, + :win, + :magicDamageTaken, + :item3, + :riotIdGameName, + :firstBloodAssist, + :profileIcon, + :inhibitorsLost, + :visionScore, + :playerAugment1, + :allInPings, + :largestCriticalStrike, + :inhibitorKills, + :riotIdTagline, + :unrealKills, + :totalDamageShieldedOnTeammates, + :visionWardsBoughtInGame, + :holdPings, + :participantId, + :kills, + :challenges, + :objectivesStolen, + :spell4Casts, + :totalUnitsHealed, + :teamId, + :timeCCingOthers + ] +end diff --git a/apps/scrapper/mix.exs b/apps/scrapper/mix.exs index eb0322b..62c12d2 100644 --- a/apps/scrapper/mix.exs +++ b/apps/scrapper/mix.exs @@ -26,7 +26,8 @@ defmodule Scrapper.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:httpoison, "~> 2.2"} + {:httpoison, "~> 2.2"}, + {:poison, "~> 5.0"} # {:dep_from_hexpm, "~> 0.3.0"}, # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, # {:sibling_app_in_umbrella, in_umbrella: true} diff --git a/mix.lock b/mix.lock index 84d3525..ef02990 100644 --- a/mix.lock +++ b/mix.lock @@ -32,6 +32,7 @@ "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, "plug": {:hex, :plug, "1.15.3", "712976f504418f6dff0a3e554c40d705a9bcf89a7ccef92fc6a5ef8f16a30a97", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cc4365a3c010a56af402e0809208873d113e9c38c401cabd88027ef4f5c01fd2"}, "plug_crypto": {:hex, :plug_crypto, "2.0.0", "77515cc10af06645abbfb5e6ad7a3e9714f805ae118fa1a70205f80d2d70fe73", [:mix], [], "hexpm", "53695bae57cc4e54566d993eb01074e4d894b65a3766f1c43e2c61a1b0f45ea9"}, + "poison": {:hex, :poison, "5.0.0", "d2b54589ab4157bbb82ec2050757779bfed724463a544b6e20d79855a9e43b24", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "11dc6117c501b80c62a7594f941d043982a1bd05a1184280c0d9166eb4d8d3fc"}, "postgrex": {:hex, :postgrex, "0.17.5", "0483d054938a8dc069b21bdd636bf56c487404c241ce6c319c1f43588246b281", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "50b8b11afbb2c4095a3ba675b4f055c416d0f3d7de6633a595fc131a828a67eb"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"}, "tailwind": {:hex, :tailwind, "0.2.2", "9e27288b568ede1d88517e8c61259bc214a12d7eed271e102db4c93fcca9b2cd", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "ccfb5025179ea307f7f899d1bb3905cd0ac9f687ed77feebc8f67bdca78565c4"},