/ArgentPonyWarcraftClient

The Argent Squire .NET client for the Blizzard World of Warcraft Community Web APIs

Primary LanguageC#MIT LicenseMIT

Argent Pony Warcraft Client

The Argent Pony Warcraft Client is a .NET client for the Blizzard World of Warcraft Community APIs. It lets .NET applications easily access information about World of Warcraft characters, guilds, items, spells, and more. It is a .NET Standard 1.1 library, which means it supports a broad range of platforms, including .NET Core 1.0+ and .NET Framework 4.5+.

NuGet version Build status

Prerequisites

All users of the Blizzard World of Warcraft Community Web APIs must have a Battle.net account and a client ID. Follow Blizzard's Getting Started instructions.

Installing via NuGet

You can install the ArgentPonyWarcraftClient package from the NuGet Package Manager in Visual Studio or by running the following command from the Package Manager Console:

Install-Package ArgentPonyWarcraftClient

Using the Argent Pony Warcraft Client

Assuming you're working in C#, add the appropriate using statement to reference the library:

using ArgentPonyWarcraftClient;

Instantiate a WarcraftClient with the the client ID and client secret that you registered for in the Prerequisites step. For simplicity, these values are stored in the source code in the example below. You should instead use the configuration API for your .NET platform to store the key securely. For example, ASP.NET Core developers should read Configuration in ASP.NET Core.

string clientId = "MY-CLIENT-ID-GOES-HERE";
string clientSecret = "MY-CLIENT-SECRET-GOES-HERE";
var warcraftClient = new WarcraftClient(clientId, clientSecret);

You can optionally specify the region and locale to use when calling the WarcraftClient constructor. If you omit these parameters, it will default to Region.US and "Locale.en_US". Each method on WarcraftClient also has an overload that allows you to override these default values for the current call.

var warcraftClient = new WarcraftClient(clientId, clientSecret, Region.US, "Locale.en_US");

Once you have your WarcraftClient instance, you can start asking for data. All methods are asynchronous. Here's an example for retrieving a character:

RequestResult<Character> result = await warcraftClient.GetCharacterAsync("Norgannon", "Drinian", CharacterFields.All);

This will retrieve a character named Drinian from the realm Norgannon. The CharacterFields enumeration allows you to specify which portions of character-related data the Blizzard API should return. If you only want to retrieve information about the character's talents and mounts, for instance, you can ask for only those portions of the Character object to be populated.

CharacterFields fields = CharacterFields.Talents | CharacterFields.Mounts;
RequestResult<Character> result = await warcraftClient.GetCharacterAsync("Norgannon", "Drinian", fields);

Each request is wrapped in the RequestResult<T> class. Which has the following properties.

  • Value (The generic type argument)
  • Error (RequestError class)
    • Code (The HTTP status code)
    • Type (The HTTP status code description)
    • Detail (The details of why the request failed)
  • Success (bool)

A proper method call could look like this.

RequestResult<Character> result = await warcraftClient.GetCharacterAsync("Norgannon", "Drinian", CharacterFields.All);

if (result.Success)
{
    Console.WriteLine("Character Name: " + result.Value.Name);
    Console.WriteLine("Character Level: " + result.Value.Level);
}
else
{
    Console.WriteLine("HTTP Status Code: " + result.Error.Code);
    Console.WriteLine("HTTP Status Description: " + result.Error.Type);
    Console.WriteLine("Details: " + result.Error.Detail);
}

Take a look at the WarcraftClientTests class and the Blizzard World of Warcraft Community APIs documentation to learn more about what else you can do.