Skip to content

Commit

Permalink
Updated documentation (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-j-green authored Oct 1, 2024
1 parent 3294c4e commit 90d7caf
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 45 deletions.
54 changes: 54 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -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 = "<Your API key here>";
```
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<DataObjectItem> platforms = hasheous.GetPlatforms();
```

### Accessing the Metadata Proxy
#### Using an ID (long)
```c#
HasheousClient.Models.Metadata.IGDB.Game metadataProxy = hasheous.GetMetadataProxy<HasheousClient.Models.Metadata.IGDB.Game>(HasheousClient.Hasheous.MetadataProvider.IGDB, 3192);
```

#### Using a slug (string)
```c#
HasheousClient.Models.Metadata.IGDB.Game metadataProxy = hasheous.GetMetadataProxy<HasheousClient.Models.Metadata.IGDB.Game>(HasheousClient.Hasheous.MetadataProvider.IGDB, "sonic-the-hedgehog");
```
47 changes: 2 additions & 45 deletions TestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using HasheousClient.Models;

HasheousClient.WebApp.HttpHelper.BaseUri = "https://hasheous.org/";
HasheousClient.WebApp.HttpHelper.APIKey = "";

HasheousClient.Hasheous hasheous = new HasheousClient.Hasheous();

Expand All @@ -28,7 +29,7 @@
Console.WriteLine(i + ": " + platforms[i].Name);
}

HasheousClient.Models.Metadata.IGDB.Override.Game metadataProxy = hasheous.GetMetadataProxy<HasheousClient.Models.Metadata.IGDB.Override.Game>(HasheousClient.Hasheous.MetadataProvider.IGDB, 3192);
HasheousClient.Models.Metadata.IGDB.Game metadataProxy = hasheous.GetMetadataProxy<HasheousClient.Models.Metadata.IGDB.Game>(HasheousClient.Hasheous.MetadataProvider.IGDB, 3192);
if (metadataProxy != null)
{
Newtonsoft.Json.JsonSerializerSettings jsonSerializerSettings = new Newtonsoft.Json.JsonSerializerSettings
Expand All @@ -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<IGDB.Models.Platform[]>(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<IGDB.Models.Game[]>(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);
}
16 changes: 16 additions & 0 deletions hasheous-client/HasheousClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ private async Task<T> _GetMetadataProxy<T>(MetadataProvider metadataProvider, in
return result;
}

public T GetMetadataProxy<T>(MetadataProvider metadataProvider, string slug)
{
Task<T> result = _GetMetadataProxy<T>(metadataProvider, slug);

return result.Result;
}

private async Task<T> _GetMetadataProxy<T>(MetadataProvider metadataProvider, string slug)
{
string TypeName = typeof(T).Name;

var result = await HasheousClient.WebApp.HttpHelper.Get<T>($"/api/v1/MetadataProxy/{metadataProvider}/{TypeName}?slug={slug}");

return result;
}

public T? GetMetadataProxy_SearchPlatform<T>(MetadataProvider metadataProvider, string search)
{
string TypeName = typeof(T).Name.Replace("[]", "");
Expand Down
12 changes: 12 additions & 0 deletions hasheous-client/WebClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> Post<T>(string url, object contentValue)
Expand Down

0 comments on commit 90d7caf

Please sign in to comment.