move storage and api to apps, create base analyzer
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
# Used by "mix format"
|
||||
[
|
||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||
]
|
||||
@@ -0,0 +1,26 @@
|
||||
# The directory Mix will write compiled artifacts to.
|
||||
/_build/
|
||||
|
||||
# If you run "mix test --cover", coverage assets end up here.
|
||||
/cover/
|
||||
|
||||
# The directory Mix downloads your dependencies sources to.
|
||||
/deps/
|
||||
|
||||
# Where third-party dependencies like ExDoc output generated docs.
|
||||
/doc/
|
||||
|
||||
# Ignore .fetch files in case you like to edit your project deps locally.
|
||||
/.fetch
|
||||
|
||||
# If the VM crashes, it generates a dump, let's ignore it too.
|
||||
erl_crash.dump
|
||||
|
||||
# Also ignore archive artifacts (built via "mix archive.build").
|
||||
*.ez
|
||||
|
||||
# Ignore package tarball (built via "mix hex.build").
|
||||
lol_api-*.tar
|
||||
|
||||
# Temporary files, for example, from tests.
|
||||
/tmp/
|
||||
@@ -0,0 +1,21 @@
|
||||
# LoLAPI
|
||||
|
||||
**TODO: Add description**
|
||||
|
||||
## Installation
|
||||
|
||||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
|
||||
by adding `lol_api` to your list of dependencies in `mix.exs`:
|
||||
|
||||
```elixir
|
||||
def deps do
|
||||
[
|
||||
{:lol_api, "~> 0.1.0"}
|
||||
]
|
||||
end
|
||||
```
|
||||
|
||||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
|
||||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
|
||||
be found at <https://hexdocs.pm/lol_api>.
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import Config
|
||||
|
||||
config :lol_api,
|
||||
riot_api_key: System.get_env("RIOT_API_KEY")
|
||||
@@ -0,0 +1,26 @@
|
||||
defmodule LoLAPI.AccountApi do
|
||||
require Logger
|
||||
|
||||
@get_puuid_endpoint "https://europe.api.riotgames.com/riot/account/v1/accounts/by-riot-id/%{gameName}/%{tagLine}"
|
||||
|
||||
@spec get_puuid(String.t(), String.t()) :: {:ok, String.t()} | {:error, String.t()}
|
||||
def get_puuid(name, tag) do
|
||||
url =
|
||||
@get_puuid_endpoint
|
||||
|> String.replace("%{gameName}", name)
|
||||
|> String.replace("%{tagLine}", tag)
|
||||
|
||||
api_key = System.get_env("RIOT_API_KEY")
|
||||
headers = [{"X-Riot-Token", api_key}]
|
||||
response = HTTPoison.get!(url, headers, timeout: 5000)
|
||||
|
||||
case response.status_code do
|
||||
200 ->
|
||||
{:ok, Poison.decode(response.body)}
|
||||
|
||||
code ->
|
||||
Logger.error("Error getting puuid from player #{name} \##{tag}")
|
||||
{:err, response.status_code}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,51 @@
|
||||
defmodule LoLAPI.MatchApi do
|
||||
require Logger
|
||||
@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> LoLAPI.MatchApi.get_match_by_id("EUW1_6921743825")
|
||||
"""
|
||||
@spec get_match_by_id(String.t()) :: %LoLAPI.Model.MatchResponse{}
|
||||
def get_match_by_id(match_id) do
|
||||
url = String.replace(@match_base_endpoint, "%{matchid}", match_id)
|
||||
Logger.info("Making request to #{url}")
|
||||
api_key = System.get_env("RIOT_API_KEY")
|
||||
headers = [{"X-Riot-Token", api_key}]
|
||||
response = HTTPoison.get!(url, headers, timeout: 5000)
|
||||
|
||||
case response.status_code do
|
||||
200 ->
|
||||
{:ok, response.body}
|
||||
|
||||
_ ->
|
||||
Logger.error("Error getting match by id: #{match_id} #{inspect(response)}")
|
||||
{:err, response.status_code}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get matches from player
|
||||
|
||||
iex> LoLAPI.MatchApi.get_matches_from_player "JB6TdEWlKjZwnbgdSzOogYepNfjLPdUh68S8b4kUu4EEZy4R4MMAgv92QMj1XgVjtzHmZVLaOW7mzg"
|
||||
"""
|
||||
@spec get_matches_from_player(String.t()) :: list(String.t()) | integer()
|
||||
def get_matches_from_player(puuid) do
|
||||
url = String.replace(@puuid_matches_base_endpoint, "%{puuid}", URI.encode(puuid))
|
||||
Logger.info("Making request to #{url}")
|
||||
api_key = System.get_env("RIOT_API_KEY")
|
||||
headers = [{"X-Riot-Token", api_key}]
|
||||
response = HTTPoison.get!(url, headers, timeout: 5000)
|
||||
|
||||
case response.status_code do
|
||||
200 ->
|
||||
{:ok, Poison.decode!(response.body)}
|
||||
|
||||
code ->
|
||||
Logger.error("Error getting matches from player #{puuid} #{code}")
|
||||
{:err, response.status_code}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,20 @@
|
||||
defmodule LoLAPI.Model.Info do
|
||||
alias LoLAPI.Model.Participant
|
||||
|
||||
defstruct endOfGameResult: "",
|
||||
gameCreation: "",
|
||||
gameDuration: "",
|
||||
gameEndTimestamp: "",
|
||||
gameId: "",
|
||||
gameMode: "",
|
||||
gameName: "",
|
||||
gameStartTimestamp: "",
|
||||
gameType: "",
|
||||
gameVersion: "",
|
||||
mapId: "",
|
||||
participants: [%Participant{}],
|
||||
platformId: "",
|
||||
queueId: "",
|
||||
teams: "",
|
||||
tournamentCode: ""
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
defmodule LoLAPI.Model.MatchResponse do
|
||||
alias LoLAPI.Model.{Info, Metadata}
|
||||
|
||||
defstruct metadata: %Metadata{},
|
||||
info: %Info{}
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
defmodule LoLAPI.Model.Metadata do
|
||||
defstruct [:dataVersion, :matchId, :participants]
|
||||
end
|
||||
@@ -0,0 +1,135 @@
|
||||
defmodule LoLAPI.Model.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
|
||||
@@ -0,0 +1,18 @@
|
||||
defmodule LoLAPI do
|
||||
@moduledoc """
|
||||
Documentation for `LoLAPI`.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Hello world.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> LoLAPI.hello()
|
||||
:world
|
||||
|
||||
"""
|
||||
def hello do
|
||||
:world
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,35 @@
|
||||
defmodule LoLAPI.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[
|
||||
app: :lol_api,
|
||||
version: "0.1.0",
|
||||
build_path: "../../_build",
|
||||
config_path: "../../config/config.exs",
|
||||
deps_path: "../../deps",
|
||||
lockfile: "../../mix.lock",
|
||||
elixir: "~> 1.16",
|
||||
start_permanent: Mix.env() == :prod,
|
||||
deps: deps()
|
||||
]
|
||||
end
|
||||
|
||||
# Run "mix help compile.app" to learn about applications.
|
||||
def application do
|
||||
[
|
||||
extra_applications: [:logger]
|
||||
]
|
||||
end
|
||||
|
||||
# Run "mix help deps" to learn about dependencies.
|
||||
defp deps do
|
||||
[
|
||||
{: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}
|
||||
]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
defmodule LoLAPITest do
|
||||
use ExUnit.Case
|
||||
doctest LoLAPI
|
||||
|
||||
test "greets the world" do
|
||||
assert LoLAPI.hello() == :world
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1 @@
|
||||
ExUnit.start()
|
||||
Reference in New Issue
Block a user