Simple RESTful Interface for battle.net/api menu

Shout-Out

User Tag List

Results 1 to 5 of 5
  1. #1
    fvicaria's Avatar Active Member
    Reputation
    29
    Join Date
    Jan 2009
    Posts
    55
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple RESTful Interface for battle.net/api

    Here is a very simple interface for the battle.net RESTfull service.

    Basically it will request asynchronously for any item details and current database status by providing either its id or name.
    It's also very useful for loading general static data directly from the servers i.e races, classes, characters achievements, pvp status, etc.

    Regions.cs
    Code:
    
    // ReSharper disable InconsistentNaming
    namespace WoWHack.Common.REST 
    {
        /* 
         * Example of how to use it: 
         * http://eu.battle.net/api/wow/data/character/races?locale=fr_FR
         */
    
        public enum Regions
            {
                US,
                Europe,
                Korea,
                Taiwan,
                China,
                NONE
            }
            public enum Locales
            {
                en_US,
                es_MX,
                pt_BR,
                en_GB,
                es_ES,
                fr_FR,
                ru_RU,
                de_DE,
                pt_PT,
                it_IT,
                ko_KR,
                zh_TW,
                zh_CN,
                NONE
            }
    }
    WoWItemInfo.cs
    Code:
    using Newtonsoft.Json.Linq;
    
    namespace WoWHack.Common.REST
    {
        public class WoWItemInfo
        {
            #region Fields
            private readonly JObject _jsonObject;
            #endregion
    
            #region Constructors
            public WoWItemInfo(int id, string name, string description = null)
            {
                Name = name;
                Id = id;
                Description = description;
            }
            public WoWItemInfo(string jsonString)
            {
                _jsonObject = JObject.Parse(jsonString);
                Id = _jsonObject.SelectToken("id").Value<int>();
                Name = _jsonObject.SelectToken("name").Value<string>();
                Description = _jsonObject.SelectToken("description").Value<string>();
            }
            #endregion
    
            #region Properties
            public int Id { get; private set; }
            public string Name { get; private set; }
            public string Description { get; private set; }
            #endregion
    
            #region Public Methods
            public T GetProperty<T>(string proName)
            {
                if (_jsonObject == null)
                    return default(T);
    
                var token = _jsonObject.SelectToken(proName);
                return token != null ? token.Value<T>() : default(T);
            }
            #endregion
        }
    }
    BattleNetREST.cs
    Code:
    /*
     * Simple Interface for the WOW API RESTful Service
     * By: F Vicaria
     * Updated: 02/11/2014
     * Documentation:
     * http://blizzard.github.io/api-wow-docs/
     * 
    */
    
    using System;
    using System.Diagnostics;
    using System.Net.Http;
    using System.Net.Http.Headers;
    
    namespace WoWHack.Common.REST
    {
        public delegate void ItemResponseHandler(WoWItemInfo item);
    
        public static class BattleNetRest
        {
            private static Regions _region;
            private static Locales _locale;
    
            static BattleNetRest() 
            {
                BaseUrl = @"http://eu.battle.net/api/wow/";
                _region = Regions.Europe;
                _locale = Locales.en_GB;
            }
    
            public static Regions Region
            {
                get { return _region; }
                set
                {
                    if (value == _region)
                        return;
    
                    _region = value;
                    _locale = Locales.NONE;
                    switch (value)
                    {
                        case Regions.US:
                            BaseUrl = @"http://us.battle.net/api/wow/";
                            break;
                        case Regions.Europe:
                            BaseUrl = @"http://eu.battle.net/api/wow/";
                            break;
                        case Regions.Korea:
                            BaseUrl = @"http://kr.battle.net/api/wow/";
                            break;
                        case Regions.Taiwan:
                            BaseUrl = @"http://tw.battle.net/api/wow/";
                            break;
                        case Regions.China:
                            BaseUrl = @"http://www.battlenet.com.cn/api/wow/";
                            break;
                        default:
                            BaseUrl = @"http://eu.battle.net/api/wow/";
                            break;
                    }
    
                }
            }
            public static Locales Locale
            {
                get { return _locale; }
                set
                {
                    if (value == _locale)
                        return;
    
                    _locale = value;
                    switch (value)
                    {
                        case Locales.en_US:
                        case Locales.es_MX:
                        case Locales.pt_BR:
                            _region = Regions.US;
                            BaseUrl = @"http://us.battle.net/api/wow/";
                            break;
                        case Locales.en_GB:
                        case Locales.es_ES:
                        case Locales.fr_FR:
                        case Locales.ru_RU:
                        case Locales.de_DE:
                        case Locales.pt_PT:
                        case Locales.it_IT:
                            _region = Regions.Europe;
                            BaseUrl = @"http://eu.battle.net/api/wow/";
                            break;
                        case Locales.ko_KR:
                            _region = Regions.Korea;
                            BaseUrl = @"http://kr.battle.net/api/wow/";
                            break;
                        case Locales.zh_TW:
                            _region = Regions.Taiwan;
                            BaseUrl = @"http://tw.battle.net/api/wow/";
                            break;
                        case Locales.zh_CN:
                            _region = Regions.China;
                            BaseUrl = @"http://www.battlenet.com.cn/api/wow/";
                            break;
                        default:
                            _region = Regions.Europe;
                            BaseUrl = @"http://eu.battle.net/api/wow/";
                            break;
                    }
                }
            }
            public static string BaseUrl { get; private set; }
    
            public static async void GetItemInfoFromId(int displayId, ItemResponseHandler handler)
            {
                if (handler == null)
                    return;
    
                try
                {
                    using (var client = new HttpClient())
                    {
                        client.BaseAddress = new Uri(BaseUrl);
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    
                        var response = await client.GetAsync("item/" + displayId);
    
                        if (!response.IsSuccessStatusCode)
                        {
                            handler(null);
                            return;
                        }
    
                        var jsonString = await response.Content.ReadAsStringAsync();
                        var info = new WoWItemInfo(jsonString);
    
                        handler(info);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
        }
    }
    You need to get Json.NET from here https://www.nuget.org/packages/Newtonsoft.Json/

    Here is a simple example on how to use it:
    Code:
            public WoWItem(IntPtr baseAddress)
                : base(baseAddress)
            {
                BattleNetRest.GetItemInfoFromId(EntryId, item =>
                {
                    _info = item;
                });
            }
    Let me know if I missed anything (cut and paste laziness) or if you add anything into it.

    Simple RESTful Interface for battle.net/api
  2. #2
    Jadd's Avatar 🐸 Premium Seller
    Reputation
    1515
    Join Date
    May 2008
    Posts
    2,433
    Thanks G/R
    81/336
    Trade Feedback
    1 (100%)
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can't give you rep right now, but this is quite cool. Nice to see something new

  3. #3
    RobertoSageto's Avatar Member
    Reputation
    7
    Join Date
    May 2014
    Posts
    14
    Thanks G/R
    1/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wish I had ANY rep to give. Thanks for sharing this man - looks pretty well put-together. Would be fun to use maybe for a mini-battle-pet bot - looks like quite a bit of that data is available via the API.

  4. #4
    fvicaria's Avatar Active Member
    Reputation
    29
    Join Date
    Jan 2009
    Posts
    55
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Reputation is always welcome but even better is to see any improvements and/or modifications done by anyone posted here.
    I will try to take the lead on this one but my time is limited mostly to weekends only.

  5. #5
    -Ryuk-'s Avatar Elite User CoreCoins Purchaser Authenticator enabled
    Reputation
    529
    Join Date
    Nov 2009
    Posts
    1,028
    Thanks G/R
    38/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good Job +Rep

    I have been using the API for quite some time now.

    Documentation can he found here http://blizzard.github.io/api-wow-docs/
    |Leacher:11/2009|Donor:02/2010|Established Member:09/2010|Contributor:09/2010|Elite:08/2013|

Similar Threads

  1. [Trading] Titanfall Beta Keys (PC, Xbox One) for Battle.net Balance
    By Dark_Mage- in forum General Trading Buy Sell Trade
    Replies: 0
    Last Post: 02-14-2014, 07:33 PM
  2. [Selling] Country Change for Battle.net Account * Europe* Get RaF and Awesome Rewards
    By Thele in forum World of Warcraft Buy Sell Trade
    Replies: 9
    Last Post: 01-08-2014, 09:17 PM
  3. [Trading] Trading origin & ubisoft for battle.net
    By pilkas in forum Diablo 3 Buy Sell Trade
    Replies: 0
    Last Post: 11-24-2013, 07:24 AM
  4. [Trading] Beta Key for Battle.net account with WoW, SC2
    By Xeffious in forum Hearthstone Buy Sell Trade
    Replies: 0
    Last Post: 11-08-2013, 04:27 PM
  5. [Buying] Fake ID for Battle.net account
    By Authenticspectre in forum World of Warcraft Buy Sell Trade
    Replies: 4
    Last Post: 02-27-2013, 10:05 AM
All times are GMT -5. The time now is 04:16 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search