For Blizzard Licensing we need to publish the code that interacts with the Armory API. As simple as it is, here it is:
<?php
/**
* This is the Primary Functionality for a WoW read from the Armory
*
* @author Stephen Johnston
*
*/
/**
* This is the base class
*/
class GL_Game_Import_Worldofwarcraft_Core
{
function gl_read_armory_api_url($url,$last_update)
{
$sign_request = true;
$set_last_modified = true;
$headers = array();
$html_data = "";
// Try cURL first. If that isn't available, check if we're allowed to
// use fopen on URLs. If that doesn't work, just die.
if (function_exists('curl_init'))
{
$ch = curl_init();
$connect_timeout = $connect_timeout; // set to zero for no timeout
$total_timeout = $total_timeout; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($ch, CURLOPT_TIMEOUT, 10);
//curl_setopt ($ch, CURLOPT_HEADER, true);
array_push($headers,'Expect: ');
array_push($headers,'Accept-Charset: UTF-8');
array_push($headers,'Accept: application/json');
array_push($headers,'Content-Type: application/json');
array_push($headers,'User-Agent: GuildLaunch.com WoWAPI Client');
date_default_timezone_set('GMT');
// set the last UPDATE info
if ($last_update > 0 && $set_last_modified == true) {
curl_setopt($ch, CURLOPT_TIMEVALUE, $last_update);
curl_setopt($ch, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
}
if ($sign_request)
{
$public_key = 'REDACTED';
$private_key = 'REDACTED';
$path = parse_url($url,PHP_URL_PATH);
if ($public_key !== null && $private_key !== null) {
$date = str_replace('+0000','GMT',gmdate(DATE_RFC1123));
$stringToSign = "GET\n" . $date . "\n$path\n";
$signature = base64_encode(hash_hmac('sha1',$stringToSign, $private_key, true));
array_push($headers,'Authorization: BNET' . ' ' . $public_key . ':' . $signature);
array_push($headers,'Date: ' . $date);
}
}
curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt ($ch, CURLINFO_HEADER_OUT, true);
$html_data = curl_exec($ch);
curl_close($ch);
}
return $html_data;
}
}
?>