Closed pad92 closed 9 years ago
I was waiting for Blizzard to finalize their API so I don't have to keep making changes. I already started working on it and I have a rough version of the class already working. I wanted to polish it out before publishing it.
Ok.
git diff of my hotfix it, i'm waiting for your commit :
--- a/diablo3.api.class.php
+++ b/diablo3.api.class.php
@@ -15,7 +15,7 @@
class Diablo3 {
private $battlenet_tag;
- private $host = '.battle.net';
+ private $host = '.api.battle.net';
private $media_host = '.media.blizzard.com';
private $battlenet_servers = array('us', 'eu', 'tw', 'kr', 'cn');
private $locales = array('en_US', 'en_GB', 'es_MX', 'es_ES', 'it_IT', 'pt_PT', 'pt_BR', 'fr_FR', 'ru_RU', 'pl_PL', 'de_DE', 'ko_KR', 'zh_TW', 'zh_CN');
@@ -33,18 +33,17 @@ class Diablo3 {
private $item_img_sizes = array('small', 'large');
private $skill_img_url;
private $skill_img_sizes = array('21', '42', '64');
- private $item_save_loc = '/Diablo-3-API-PHP/img/items/'; // Relative to DOCUMENT_ROOT
- private $skills_save_loc = '/Diablo-3-API-PHP/img/skills/'; // Relative to DOCUMENT_ROOT
- private $paperdolls_save_loc = '/Diablo-3-API-PHP/img/paperdolls/'; // Relative to DOCUMENT_ROOT
- private $cache_loc = '/Diablo-3-API-PHP/cache/'; // Relative to DOCUMENT_ROOT
- private $use_cache = true; // Set to true to use 'If-Modified-Since' header
+ private $item_save_loc = '/img/items/'; // Relative to DOCUMENT_ROOT
+ private $skills_save_loc = '/img/skills/'; // Relative to DOCUMENT_ROOT
+ private $paperdolls_save_loc = '/img/paperdolls/'; // Relative to DOCUMENT_ROOT
+ private $cache_loc = '/cache/'; // Relative to DOCUMENT_ROOT
+ private $use_cache = false; // Set to true to use 'If-Modified-Since' header
private $skill_url;
private $paperdoll_url;
private $genders = array('male', 'female');
private $classes = array('barbarian', 'crusader', 'witch-doctor', 'demon-hunter', 'monk', 'wizard');
- private $authenticate = false; // Set to true for authenticated calls
- private $API_private_key = 'BLIZZARD_PRIVATE_KEY'; // API Private Key
- private $API_public_key = 'BLIZZARD_PUBLIC_KEY'; // API Public Key
+ private $authenticate = true; // Set to true for authenticated calls
+ private $API_key = 'MyAPIKey'; // API Private Key
private $no_battleTag = false;
private $fromCache = false;
@@ -79,15 +78,15 @@ class Diablo3 {
}
$this->battlenet_tag = urlencode($battlenet_tag);
- $this->career_url = 'http://'.$server.$this->host.'/api/d3/profile/'.$this->battlenet_tag.'/index';
- $this->hero_url = 'http://'.$server.$this->host.'/api/d3/profile/'.$this->battlenet_tag.'/hero/';
+ $this->career_url = 'http://'.$server.$this->host.'/d3/profile/'.$this->battlenet_tag.'/index';
+ $this->hero_url = 'http://'.$server.$this->host.'/d3/profile/'.$this->battlenet_tag.'/hero/';
} else {
$this->no_battleTag = true;
}
- $this->item_url = 'http://'.$server.$this->host.'/api/d3/data/';
- $this->follower_url = 'http://'.$server.$this->host.'/api/d3/data/follower/';
- $this->artisan_url = 'http://'.$server.$this->host.'/api/d3/data/artisan/';
+ $this->item_url = 'http://'.$server.$this->host.'/d3/data/';
+ $this->follower_url = 'http://'.$server.$this->host.'/d3/data/follower/';
+ $this->artisan_url = 'http://'.$server.$this->host.'/d3/data/artisan/';
$this->item_img_url = 'http://'.$server.$this->media_host.'/d3/icons/items/';
$this->skill_img_url = 'http://'.$server.$this->media_host.'/d3/icons/skills/';
$this->skill_url = 'http://'.$server.$this->host.'/d3/'.substr($locale, 0, -3).'/tooltip/';
@@ -176,7 +175,6 @@ class Diablo3 {
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_FILE, $fp);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
@@ -184,7 +182,6 @@ class Diablo3 {
curl_setopt($curl, CURLOPT_MAXREDIRS, 5);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
- curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
curl_exec($curl);
$error = curl_errno($curl);
@@ -237,32 +234,23 @@ class Diablo3 {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($curl, CURLOPT_TIMEOUT, 25);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_MAXREDIRS, 5);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);
- curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
curl_setopt($curl, CURLOPT_FILETIME, true);
// Authenticate with Battle.net
//
$header = array();
if($this->authenticate) {
- date_default_timezone_set('GMT');
- $request_url = str_replace('http://'.$this->current_server.$this->host, '', $url);
- $date = date('D, d M Y G:i:s T', time());
- $signature = base64_encode(hash_hmac('sha1', "GET\n".$date."\n".$request_url."\n", $this->API_private_key, true));
-
- $header = array("Host: ".$this->current_server.$this->host,
- "Date: ". $date,
- "\nAuthorization: BNET ".$this->API_public_key.":".$signature."\n");
-
- curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
+ $url .= '&apikey='.$this->API_key;
+ $url = preg_replace("/^http:/i", "https:", $url);
+ curl_setopt($curl, CURLOPT_URL, $url);
}
$file_time = 0;
@@ -275,7 +263,7 @@ class Diablo3 {
$file_time = $json_decode['Last-Modified'];
$file_data = $json_decode['Data'];
} else {
- error_log('Cache File Does Not Exist Or Is Not Readable');
+ error_log('Cache File "'.$cache_file.'" Does Not Exist Or Is Not Readable');
}
if($file_time > 0) {
Commit has been made. I will make some more improvements in the upcoming days.
Hi,
Bnet's API change : https://dev.battle.net/docs/community_apis/migration
Is it possible to update this class ?
Thank you :)