示例#1
0
        /// <summary>
        ///   Sets the request authentication header
        /// </summary>
        /// <param name="request"> request </param>
        /// <param name="apiKey"> api key pair </param>
        internal static void SetAuthenticationHeader(HttpWebRequest request, ApiKeyPair apiKey)
        {
            if (apiKey != null)
            {
                DateTime date       = DateTime.Now.ToUniversalTime();
                string   dateString = date.ToString("r", CultureInfo.InvariantCulture);
                request.Date = date;

                string stringToSign = request.Method + "\n" + dateString
                                      + "\n" + request.RequestUri.AbsolutePath + "\n";
                using (var hashAlgorithm = new HMACSHA1(apiKey.GetPrivateKeyBytes()))
                {
                    string signature = Convert.ToBase64String(
                        hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(stringToSign)));
                    request.Headers[HttpRequestHeader.Authorization] = "BNET " + apiKey.PublicKey + ":" + signature;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Test accessing diablo asynchronously
        /// </summary>
        /// <returns>Task</returns>
        private async static Task TestDiabloClientAsync()
        {
            string privateKey = ConfigurationManager.AppSettings["PrivateKey"];
            string publicKey  = ConfigurationManager.AppSettings["PublicKey"];
            var    pair       = new ApiKeyPair(publicKey, privateKey);

            // Init client
            var client = new DiabloClient(Region.EU, pair, "en-gb", null);

            // Get profile
            var profile = await client.GetProfileAsync("Grendizer#2508");

            // Get Hero
            var hero = await client.GetHeroAsync(profile.BattleTag, profile.Heroes[0].Id);

            /// Get item
            var item = await client.GetItemAsync(hero.Items.Head.TooltipParameters);

            // Get blacksmith info
            var blackSmith = await client.GetArtisanInfoAsync(ArtisanType.Blacksmith);

            // Get scoundrel info
            var scoundrel = await client.GetFollowerInfoAsync(FollowerType.Scoundrel);
        }
示例#3
0
 /// <summary>
 ///   Constructor. Initializes a new instance of the ApiClient class
 /// </summary>
 /// <param name="region"> Regional battle.net Community website to which the ApiClient should connect to perform request. </param>
 /// <param name="apiKey"> Application key used to authenticate requests sent by the ApiClient </param>
 /// <param name="locale"> The locale to use to perform request (item names, class names, etc are retrieved in the locale specified) </param>
 /// <remarks>
 ///   Only Locales supported by the regional website that the ApiClient is connecting to are supported. If a wrong local is passed, default language is used.
 /// </remarks>
 public WowClient(string region, ApiKeyPair apiKey, string locale)
     : this(Region.GetRegion(region), apiKey, locale, null)
 {
 }
示例#4
0
 /// <summary>
 ///   Constructor. Initializes a new instance of the ApiClient class
 /// </summary>
 /// <param name="apiKey"> Application key used to authenticate requests sent by the ApiClient </param>
 public WowClient(ApiKeyPair apiKey)
     : this((Region)null, apiKey, null, null)
 {
 }
示例#5
0
 /// <summary>
 ///   Constructor. Initializes a new instance of the ApiClient class
 /// </summary>
 /// <param name="region"> Regional battle.net Community website to which the ApiClient should connect to perform request. </param>
 /// <param name="apiKey"> Application key used to authenticate requests sent by the ApiClient </param>
 /// <param name="locale"> The locale to use to perform request (item names, class names, etc are retrieved in the locale specified) </param>
 /// <param name="cacheManager"> Cache manager to cache data </param>
 /// <remarks>
 ///   Only Locales supported by the regional website that the ApiClient is connecting to are supported. If a wrong local is passed, default language is used.
 /// </remarks>
 public WowClient(Region region, ApiKeyPair apiKey, string locale, ICacheManager cacheManager)
     : base(region, apiKey, locale, cacheManager)
 {
 }
示例#6
0
 /// <summary>
 ///   Constructor. Initializes a new instance of the ApiClient class
 /// </summary>
 /// <param name="region"> Regional battle.net Community website to which the ApiClient should connect to perform request. </param>
 /// <param name="apiKey"> Application key used to authenticate requests sent by the ApiClient </param>
 /// <param name="locale"> The locale to use to perform request (item names, class names, etc are retrieved in the locale specified) </param>
 /// <param name="cacheManager"> Cache manager to cache data </param>
 /// <remarks>
 ///   Only Locales supported by the regional website that the ApiClient is connecting to are supported. If a wrong local is passed, default language is used.
 /// </remarks>
 public WowClient(string region, ApiKeyPair apiKey, string locale, ICacheManager cacheManager)
     : this(Region.GetRegion(region), apiKey, locale, cacheManager)
 {
 }
示例#7
0
 /// <summary>
 ///   Constructor. Initializes a new instance of the ApiClient class
 /// </summary>
 /// <param name="apiKey"> Application key used to authenticate requests sent by the ApiClient </param>
 public DiabloClient(ApiKeyPair apiKey)
     : this((Region)null, apiKey, null, null)
 {
 }
示例#8
0
        /// <summary>
        /// Gets accessing WOW API Asynchronously
        /// </summary>
        /// <returns></returns>
        private async static Task TestWowClientAsync()
        {
            string privateKey = ConfigurationManager.AppSettings["PrivateKey"];
            string publicKey  = ConfigurationManager.AppSettings["PublicKey"];
            var    pair       = new ApiKeyPair(publicKey, privateKey);

            // Init client
            var client = new WowClient(Region.EU, pair, "en-gb", null);

            // Character
            var character = await client.GetCharacterAsync("kazzak", "Grendiser", CharacterFields.All);

            // Refresh character info
            await character.RefreshAsync(client);

            // Gee pet types
            var petTypes = await client.GetBattlePetTypesAsync();

            // Get challenge leaders
            var kazzakChallengeLeaders = await client.GetChallengeLeadersAsync("kazzak");

            var euChallengeLeaders = await client.GetChallengeLeadersAsync(null);

            // Get battle groups
            var bgs = await client.GetBattleGroupsAsync();

            // Get rewards
            var rewards = await client.GetGuildRewardsAsync();

            // Get perks
            var perks = await client.GetGuildPerksAsync();

            // Get realms
            var realms = await client.GetRealmStatusAsync();

            // Get classes
            var classes = await client.GetClassesAsync();

            // Get item categories
            var itemCategories = await client.GetItemCategoryNamesAsync();

            // Get races
            var races = await client.GetRacesAsync();

            // Get character achievements
            var characterAchievements = await client.GetCharacterAchievementsAsync();

            // Get guild achievements
            var guildAchievements = await client.GetGuildAchievementsAsync();

            // Get quest
            var quest = await client.GetQuestAsync(23);

            // Get talents
            var talents = await client.GetTalentsAsync();

            // Get PVP information
            var topArenaPlayers = await client.GetPvpLeaderboardAsync(PvpBracket.Arena5v5);

            var topBgPlayers = await client.GetPvpLeaderboardAsync(PvpBracket.RatedBattleground);

            // Get item set
            var itemSet = await client.GetItemSetAsync(1058);

            // Get ability
            var ability = await client.GetBattlePetAbilityAsync(640);

            var petSpecies = await client.GetBattlePetSpeciesAsync(258);

            // Get guild
            var guild = await client.GetGuildAsync(character.Realm, character.Guild.Name, GuildFields.All);

            // Get items
            var itemsTasks = character.Items.AllItems.Select(
                equippedItem => client.GetItemAsync(equippedItem.ItemId)).ToArray();
            var allItemsTask = new Task <WOWSharp.Community.Wow.Item[]>(() =>
            {
                Task.WaitAll(itemsTasks);
                return(itemsTasks.Select(t => t.Result).ToArray());
            });

            allItemsTask.Start();
            var items = await allItemsTask;

            var gems = character.Items.AllItems.Where(ei => ei.Parameters != null)
                       .SelectMany(ei => new[] { ei.Parameters.Gem0, ei.Parameters.Gem1, ei.Parameters.Gem2, ei.Parameters.Gem3 })
                       .Where(gemid => gemid != null)
                       .Distinct();

            // Get AH dump
            var auctions = await client.GetAuctionDumpAsync(character.Realm);
        }