Close
Showing results 1 to 2 of 2
  1. #1

    Default [Development] Using cURL and PHP to talk to the WoWArmory

    class armory {

    const BROWSER="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070319 Firefox/2.0.0.3";

    public $query;
    public $server;
    public $guild;
    public $guildie;
    public $page;
    public $armoryRegion;


    public function __construct ( $query, $server, $guild, $guildie, $page, $funcRegion ) {
    $this->query = $query;
    $this->server = $server;
    $this->guild = $guild;
    $this->guildie = $guildie;
    $this->page = $page;
    $this->region = $funcRegion;
    } // end of __construct()

    public function pull_xml() {
    global $USaurl;
    global $EUaurl;
    global $currentArmoryRegion;
    // change the first part of the $url to the armory link that you need
    if( $this->query === 'roster' ){
    if ($armoryRegion == 'US'){
    $url = 'http://www.wowarmory.com/guild-info.xml?r=' . urlencode($this->server) . '&n=' . urlencode($this->guild) . '&p=' . $this->page;
    } else {
    $url = 'http://eu.wowarmory.com/guild-info.xml?r=' . urlencode($this->server) . '&n=' . urlencode($this->guild) . '&p=' . $this->page;
    }
    }elseif( $this->query === 'character' ){
    if ($armoryRegion == 'US'){
    $url = 'http://www.wowarmory.com/character-sheet.xml?r=' . urlencode($this->server) . '&cn=' . $this->guildie;
    } else {
    $url = 'http://eu.wowarmory.com/character-sheet.xml?r=' . urlencode($this->server) . '&cn=' . $this->guildie;
    }
    }elseif( $this->query === 'arena' ){
    $currentArmoryRegion = $armoryRegion;
    if ($this->region === 'US'){
    $url = 'http://www.wowarmory.com/character-arenateams.xml?r=' . urlencode($this->server) . '&cn=' . $this->guildie;
    $USaurl = 'http://www.wowarmory.com/character-arenateams.xml?r=' . urlencode($this->server) . '&cn=' . $this->guildie;
    } else {
    $url = 'http://eu.wowarmory.com/character-arenateams.xml?r=' . urlencode($this->server) . '&cn=' . $this->guildie;
    $EUaurl = 'http://eu.wowarmory.com/character-arenateams.xml?r=' . urlencode($this->server) . '&cn=' . $this->guildie;
    }
    }

    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15);
    curl_setopt ($ch, CURLOPT_USERAGENT, self::BROWSER);

    $url_string = curl_exec($ch);
    curl_close($ch);
    return simplexml_load_string($url_string);


    } // end of pull_xml()

    } // end class
    Usage:

    $armory = new armory( arena , $toonRealm , NULL , $toonName , NULL, $armoryRegion);
    $xml = $armory->pull_xml();

  2. #2

    Default

    i would suggest adding
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
    $http_code = curl_getingo($ch, CURLINFO_HTTP_CODE);

    I had to do so for my own sig tool (as seen below) as the armory sometimes redirect, and when the maintenance is on you might get a error 500 and no data instead of the 'maintenance" xml page.

    In any case, check for the "errorhtml" tag in the response xml for armory errors, and check "belowMinLevel" for toons not yet of age.

    [edit]
    Also, make sure you pass a rawurlencoded $server, $guild and $guildie to take care of accentuated names and realms with quotes.
    Last edited by Zub : 02-02-2010 at 07:30 PM Reason: added encoding info
    .[I



Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •