Refactored the youtube api module

This commit is contained in:
Kieran Eglin 2024-06-05 08:40:54 -07:00
parent c21f2c6b93
commit 41b682668b
No known key found for this signature in database
GPG key ID: 193984967FCF432D

View file

@ -48,10 +48,10 @@ defmodule Pinchflat.FastIndexing.YoutubeApi do
defp do_api_request(playlist_id) do defp do_api_request(playlist_id) do
Logger.debug("Fetching recent media IDs from YouTube API for playlist: #{playlist_id}") Logger.debug("Fetching recent media IDs from YouTube API for playlist: #{playlist_id}")
api_base = "https://youtube.googleapis.com/youtube/v3/playlistItems" playlist_id
request_url = "#{api_base}?part=contentDetails&maxResults=50&playlistId=#{playlist_id}&key=#{api_key()}" |> construct_api_endpoint()
|> http_client().get(accept: "application/json")
case http_client().get(request_url, accept: "application/json") do |> case do
{:ok, response} -> {:ok, response} ->
Phoenix.json_library().decode(response) Phoenix.json_library().decode(response)
@ -78,6 +78,14 @@ defmodule Pinchflat.FastIndexing.YoutubeApi do
Settings.get!(:youtube_api_key) Settings.get!(:youtube_api_key)
end end
defp api_base do
"https://youtube.googleapis.com/youtube/v3/playlistItems"
end
defp construct_api_endpoint(playlist_id) do
"#{api_base()}?part=contentDetails&maxResults=50&playlistId=#{playlist_id}&key=#{api_key()}"
end
defp http_client do defp http_client do
Application.get_env(:pinchflat, :http_client, Pinchflat.HTTP.HTTPClient) Application.get_env(:pinchflat, :http_client, Pinchflat.HTTP.HTTPClient)
end end