From 7406b115048b8b57b138d4028f9846a2301ee258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro?= Date: Wed, 1 May 2024 10:36:05 +0200 Subject: [PATCH] scrapper: create match_api.ex --- apps/scrapper/lib/scrapper/data/match_api.ex | 40 ++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 apps/scrapper/lib/scrapper/data/match_api.ex diff --git a/apps/scrapper/lib/scrapper/data/match_api.ex b/apps/scrapper/lib/scrapper/data/match_api.ex new file mode 100644 index 0000000..4db3379 --- /dev/null +++ b/apps/scrapper/lib/scrapper/data/match_api.ex @@ -0,0 +1,40 @@ +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" + + @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) + 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 -> + # process the response here + IO.inspect(response.body) + + _ -> + # handle error responses + IO.inspect(response.status_code) + end + end + + @spec get_matches_from_player(String.t()) :: any() + def get_matches_from_player(puuid) do + url = String.replace(@puuid_matches_base_endpoint, "%{puuid}", puuid) + 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 -> + # process the response here + IO.inspect(response.body) + + _ -> + # handle error responses + IO.inspect(response.status_code) + end + end +end