Create struct for match

This commit is contained in:
2024-05-01 12:07:07 +02:00
parent 7406b11504
commit df34d7b8c5
7 changed files with 175 additions and 2 deletions
+7 -1
View File
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,3 @@
defmodule Scrapper.Data.Model.Match.Metadata do
defstruct [:dataVersion, :matchId, :participants]
end
@@ -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
+2 -1
View File
@@ -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}