Skip to content

Latest commit

 

History

History
64 lines (47 loc) · 1.57 KB

Examples.md

File metadata and controls

64 lines (47 loc) · 1.57 KB

Simple request

  • Get the API clientID and secret from Blizzard developer portal

  • Configure the API in ConfigureServices

services.Configure<ApiConfiguration>(Options => 
        Options.SetClientId(clientId)
        .SetClientSecret(secret)
        .SetRegion(region)
        .SetLocale(locale));

  • Register the API for Dependency Injection
//For Diablo API
services.AddBlizzardApiReaderDiablo();


//For World of Warcraft API
services.AddBlizzardApiReaderWorldOfWarcraft();

  • Use the game API adding the dependency on the controller constructor
//Using Diablo API
//Get first Act information
StoryAct act1 = await d3Api.GetActAsync(1);
Console.WriteLine($"act 1 name: {act1.Name}");

//Using World of Warcraft API
List<Boss> bosses = await wowApi.GetBossesAsync();
foreach (Boss boss in bosses)
{
	Console.WriteLine($"Encounter: {boss.Name} Description: {boss.Description}");
}

  • For command line utilization, you need to create your service collection and the provider
static void Main(string[] args)
    {
        var services = new ServiceCollection();

        services.Configure<ApiConfiguration>(Options => 
          Options.SetClientId(clientId)
            .SetClientSecret(secret)
            .SetRegion(region)
            .SetLocale(locale));
     
        services.AddBlizzardApiReaderDiablo();
        
        var provider = services.BuildServiceProvider();
          
        var api = provider.GetService<DiabloApi>();
        
        StoryAct act1 = api.GetActAsync(1).Result;
        Console.WriteLine($"act 1 name: {act1.Name}");
    }