Halo Reach C# JSON Service API Wrappers

This is a library of C# wrappers around the Bungie.,net Halo Reach Stats API.

The aim is to provide a set of asynchronous service wrappers for retrieving Halo Reach Player, Media and File information.

NOTE: You must sign up for a Halo Reach API Key to use these services

This project is not endorsed by, nor affiliated with, Bungie, Microsoft or anyone else for that matter

Examples

haloReachAPITest1.png

Game Metadata (Map, Medal and Weapon information)

private static void GameMetadataExample()
{
    // Create the metadata service, passing in our api key.
    // NOTE: Alternatively, the default Constructor will look for a "HaloReachAPIKey" App Setting.
    var metadataService = new GameMetadataService("[YOURAPIKEY]");

    bool completed = false;
    metadataService.GotError += (s, e) =>
        {
            // Handle an error... show a message.
            Console.WriteLine("Metadata Service Error: {0}", e.Argument.Message);
            completed = true;
        };
    metadataService.GotResult += (s, e) =>
        {
            // Handle our response... Show some details.
            var response = e.Argument;
            Console.WriteLine("Metadata Service Response: {0}", response.reason);
            Console.WriteLine("\tCommendation Count: {0}", response.Data.AllCommendationsById.Count);
            Console.WriteLine("\tEnemy Count: {0}", response.Data.AllEnemiesById.Count);
            Console.WriteLine("\tMedal Count: {0}", response.Data.AllMedalsById.Count);
            Console.WriteLine("\tMaps Count: {0}", response.Data.AllMapsById.Count);
            Console.WriteLine("\tWeapons Count: {0}", response.Data.AllWeaponsById.Count);

            completed = true;
        };

    metadataService.GetGameDataAsync();

    // Waiting around for the service to return...
    var start = DateTime.Now;
    while (DateTime.Now.Subtract(start).TotalSeconds < 5)
    {
        if (completed)
            break;

        Console.WriteLine("Sleeping...");
        Thread.Sleep(1000);
    }

}


Player Details and Statistics (Player Model images and statistics by game)

/// <summary>
/// An example method for getting a players statistics and details.
/// </summary>
private static void PlayerDetailsExample()
{
    // Using the default constructor will load your API Key from the "HaloReachAPIKey" App Setting.
    var playerDetailsService = new PlayerDetailsService("[YOURAPIKEY]");

    bool completed = false;
    playerDetailsService.GotError += (s, e) =>
    {
        Console.WriteLine("Player Details Service Error: {0}", e.Argument.Message);
        completed = true;
    };
    playerDetailsService.GotResult += (s, e) =>
    {
        var response = e.Argument;

        if (response.Player == null)
        {
            Console.WriteLine("Player not found...");
            completed = true;
            return;
        }

        Console.WriteLine("Player Details: {0} ({1})", response.Player.gamertag, response.Player.service_tag);
                
        // Player model image (standard and Hi Res)
        Console.WriteLine("Player Model Url: http://bungie.net" + response.PlayerModelUrl);
        Console.WriteLine("Player Model Url (Hi-Res): http://bungie.net" + response.PlayerModelUrlHiRes);

        // Challenges information
        Console.WriteLine("Daily Challenges Completed: {0}", response.Player.daily_challenges_completed);
        Console.WriteLine("Weekly Challenges Completed: {0}", response.Player.weekly_challenges_completed);

        // Last game type played
        Console.WriteLine("Last Game Type Played: {0}", response.Player.LastGameVariantClassPlayed);

        foreach (var mapStat in e.Argument.StatisticsByMap)
        {
            // Statistics for last played maps.
            Console.WriteLine("Map Id: {0}", mapStat.MapId);
            Console.WriteLine("\tTotal Kills: {0}", mapStat.total_kills);
            Console.WriteLine("\tTotal Deaths: {0}", mapStat.total_deaths);
            Console.WriteLine("\tTotal Score: {0}", mapStat.total_score);
            Console.WriteLine("\tTotal Medals: {0}", mapStat.TotalMedals);
        }

        completed = true;
    };

    // Ask for a gamertag to look up.
    Console.WriteLine("Enter a Gamertag: ");
    var gamerTag = Console.ReadLine();

    playerDetailsService.GetPlayerDetailsWithStatsByMapAsync(gamerTag);

    // Waiting around for the service to return... Takes about 10 seconds for player details calls
    var start = DateTime.Now;
    while (DateTime.Now.Subtract(start).TotalSeconds < 20)
    {
        if (completed)
            break;

        Console.WriteLine("Sleeping...");
        Thread.Sleep(1000);
    }
}


This project was started by Jacob Gable.

Last edited Oct 3, 2010 at 2:08 AM by jgable, version 8