From 90d7cafd16aec6878f955079217e8729c5dac59a Mon Sep 17 00:00:00 2001 From: Michael Green <84688932+michael-j-green@users.noreply.github.com> Date: Wed, 2 Oct 2024 00:04:40 +1000 Subject: [PATCH] Updated documentation (#12) --- README.MD | 54 +++++++++++++++++++++++++++++++ TestApp/Program.cs | 47 ++------------------------- hasheous-client/HasheousClient.cs | 16 +++++++++ hasheous-client/WebClient.cs | 12 +++++++ 4 files changed, 84 insertions(+), 45 deletions(-) create mode 100644 README.MD diff --git a/README.MD b/README.MD new file mode 100644 index 0000000..af80e3f --- /dev/null +++ b/README.MD @@ -0,0 +1,54 @@ +# Hasheous Client + +This repo contains a basic Hasheous Client .NET based applications. + +## Setting up this client +1. Add the repo to your project: `dotnet add package hasheous-client` +2. Set the base URI: +```c# +HasheousClient.WebApp.HttpHelper.BaseUri = "https://hasheous.org/"; +``` +3. Set the Hasheous API key: +> **Note:** Only the metadata proxy and fix match endpoints require an API key. +> +> If you don't plan on using these endpoints, the API key can be safely ommitted. +```c# +HasheousClient.WebApp.HttpHelper.APIKey = ""; +``` +4. Create a new Hasheous Client object: +```c# +HasheousClient.Hasheous hasheous = new HasheousClient.Hasheous(); +``` + +## Methods +### MD5 Hash lookup +```c# +LookupItemModel? HasheousResult = hasheous.RetrieveFromHasheous(new HashLookupModel +{ + MD5 = "7a61d6a9bd7ac1a3249ef167ae136af7" +}); +``` + +### SHA1 Hash lookup +```c# +LookupItemModel? HasheousResult = hasheous.RetrieveFromHasheous(new HashLookupModel +{ + SHA1 = "dc56fdcb9181b5ea04b95049997ceea2654aab78" +}); +``` + +### Get Platforms +```c# +List platforms = hasheous.GetPlatforms(); +``` + +### Accessing the Metadata Proxy +#### Using an ID (long) +```c# +HasheousClient.Models.Metadata.IGDB.Game metadataProxy = hasheous.GetMetadataProxy(HasheousClient.Hasheous.MetadataProvider.IGDB, 3192); +``` + +#### Using a slug (string) +```c# +HasheousClient.Models.Metadata.IGDB.Game metadataProxy = hasheous.GetMetadataProxy(HasheousClient.Hasheous.MetadataProvider.IGDB, "sonic-the-hedgehog"); +``` \ No newline at end of file diff --git a/TestApp/Program.cs b/TestApp/Program.cs index eaba8c7..a857efd 100644 --- a/TestApp/Program.cs +++ b/TestApp/Program.cs @@ -2,6 +2,7 @@ using HasheousClient.Models; HasheousClient.WebApp.HttpHelper.BaseUri = "https://hasheous.org/"; +HasheousClient.WebApp.HttpHelper.APIKey = ""; HasheousClient.Hasheous hasheous = new HasheousClient.Hasheous(); @@ -28,7 +29,7 @@ Console.WriteLine(i + ": " + platforms[i].Name); } -HasheousClient.Models.Metadata.IGDB.Override.Game metadataProxy = hasheous.GetMetadataProxy(HasheousClient.Hasheous.MetadataProvider.IGDB, 3192); +HasheousClient.Models.Metadata.IGDB.Game metadataProxy = hasheous.GetMetadataProxy(HasheousClient.Hasheous.MetadataProvider.IGDB, 3192); if (metadataProxy != null) { Newtonsoft.Json.JsonSerializerSettings jsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings @@ -40,48 +41,4 @@ jsonSerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); string outString = Newtonsoft.Json.JsonConvert.SerializeObject(metadataProxy, jsonSerializerSettings); Console.WriteLine(outString); -} - -// IGDB.Models.Platform[] platformSearch = hasheous.GetMetadataProxy_SearchPlatform(HasheousClient.Hasheous.MetadataProvider.IGDB, "Nintendo"); -// if (platformSearch != null) -// { -// Newtonsoft.Json.JsonSerializerSettings jsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings -// { -// Formatting = Newtonsoft.Json.Formatting.Indented, -// NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore -// }; -// jsonSerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); -// string outString = Newtonsoft.Json.JsonConvert.SerializeObject(platformSearch, jsonSerializerSettings); -// Console.WriteLine(outString); -// } - -// IGDB.Models.Game[] gameSearch = hasheous.GetMetadataProxy_SearchGame(HasheousClient.Hasheous.MetadataProvider.IGDB, platformSearch[0].Id.ToString(), "Super Mario Bros."); -// if (gameSearch != null) -// { -// Newtonsoft.Json.JsonSerializerSettings jsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings -// { -// Formatting = Newtonsoft.Json.Formatting.Indented, -// NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore -// }; -// jsonSerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); -// string outString = Newtonsoft.Json.JsonConvert.SerializeObject(gameSearch, jsonSerializerSettings); -// Console.WriteLine(outString); -// } - -// convert gameSearch to a HasheousClient.Models.Metadata.IGDB.Game object -Console.ForegroundColor = ConsoleColor.Magenta; -Console.WriteLine("Converting gameSearch to HasheousClient.Models.Metadata.IGDB.Game object"); -Console.ResetColor(); -HasheousClient.Models.Metadata.IGDB.Game gameSearchConverted = HasheousClient.Models.Metadata.IGDB.Game.ConvertFromIGDB(metadataProxy, new HasheousClient.Models.Metadata.IGDB.Game()); -if (gameSearchConverted != null) -{ - Newtonsoft.Json.JsonSerializerSettings jsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings - { - Formatting = Newtonsoft.Json.Formatting.Indented, - NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, - MaxDepth = 8 - }; - jsonSerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter()); - string outString = Newtonsoft.Json.JsonConvert.SerializeObject(gameSearchConverted, jsonSerializerSettings); - Console.WriteLine(outString); } \ No newline at end of file diff --git a/hasheous-client/HasheousClient.cs b/hasheous-client/HasheousClient.cs index 9411e01..9b892ee 100644 --- a/hasheous-client/HasheousClient.cs +++ b/hasheous-client/HasheousClient.cs @@ -82,6 +82,22 @@ private async Task _GetMetadataProxy(MetadataProvider metadataProvider, in return result; } + public T GetMetadataProxy(MetadataProvider metadataProvider, string slug) + { + Task result = _GetMetadataProxy(metadataProvider, slug); + + return result.Result; + } + + private async Task _GetMetadataProxy(MetadataProvider metadataProvider, string slug) + { + string TypeName = typeof(T).Name; + + var result = await HasheousClient.WebApp.HttpHelper.Get($"/api/v1/MetadataProxy/{metadataProvider}/{TypeName}?slug={slug}"); + + return result; + } + public T? GetMetadataProxy_SearchPlatform(MetadataProvider metadataProvider, string search) { string TypeName = typeof(T).Name.Replace("[]", ""); diff --git a/hasheous-client/WebClient.cs b/hasheous-client/WebClient.cs index f60c1ad..7e34cc4 100644 --- a/hasheous-client/WebClient.cs +++ b/hasheous-client/WebClient.cs @@ -33,6 +33,18 @@ public static void AddHeader(string name, string value) client.DefaultRequestHeaders.Add(name, value); } + public static string APIKey + { + get + { + return client.DefaultRequestHeaders.GetValues("APIKey").FirstOrDefault(); + } + set + { + AddHeader("APIKey", value); + } + } + private static HttpClient client = new HttpClient(); public static async Task Post(string url, object contentValue)