Skip to content

Commit

Permalink
Added Taddy API helper
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshiask committed Dec 22, 2022
1 parent 57fff58 commit 8d432cc
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Zune.Net.Shared/Helpers/Taddy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Flurl.Http;
using Newtonsoft.Json.Linq;
using System;
using System.Threading.Tasks;

namespace Zune.Net.Helpers
{
public static class Taddy
{
public const string API_BASE = "https://api.taddy.org";

public static IFlurlRequest GetBase()
{
return API_BASE
.WithHeader("Content-Type", "application/json")
.WithHeader("X-USER-ID", Constants.TD_USER_ID)
.WithHeader("X-API-KEY", Constants.TD_API_KEY);
}

public static async Task<TaddyPodcastSeries> GetMinimalPodcastInfo(string name)
{
RequestData request = new($"{{ getPodcastSeries(name: \"{name}\") {{ uuid rssUrl description(shouldStripHtmlTags: true) }} }}");

var response = await GetBase().PostJsonAsync(request);
var responseObj = await response.GetJsonAsync<JToken>();

var data = responseObj["data"]["getPodcastSeries"];
return new(
Guid.Parse(data.Value<string>("uuid")),
data.Value<string>("rssUrl"),
data.Value<string>("description")
);
}

private record RequestData(string query);

public record TaddyPodcastSeries(Guid Id, string RssUrl, string Description);
}
}

0 comments on commit 8d432cc

Please sign in to comment.