JSFiddle - React, Tailwind, and code Playground
JavaScript
var Blizzard = {};
Blizzard.Api = Blizzard.Api || {};
Blizzard.Api.Diablo3 = function(initializer) {
var me = this;
var config = $.extend({
region: 'eu',
urlFormat: 'http://{region}.battle.net/api/d3/profile/{battleTag}/hero/{heroId}'
}, initializer);
this.getHero = function(battleTag, heroId) {
$.ajax({
url: getHeroUrl(battleTag, heroId), dataType: 'jsonp', type: 'post'
}).done(function(data) {
console.log(data);
}).fail(function() { console.log('Could not request the hero data.'); });
}
function getHeroUrl(battleTag, heroId) {
return config.urlFormat
.replace('{region}', config.region)
.replace('{battleTag}', battleTag)
.replace('{heroId}', heroId);
}
}
var d3api = new Blizzard.Api.Diablo3();
d3api.getHero('Sideshow-2189', 1922871);