Elitist Jerks
Register
Blogs
Forums


Go Back   Elitist Jerks » Public Discussion » Public Discussion

Reply
 
LinkBack Thread Tools
Old 04/15/11, 2:06 PM   #121
Furizaa
Somewhat usefull
 
Furizaa's Avatar
 
Worgen Hunter
 
Gul'dan (EU)
Seems like they have some sort of Cross Site Policy set. Surprisingly this works:

Simple Realm Status with JQuery & JSONP - Forums - World of Warcraft

Can someone with access to the US forums ask what we can expect for the future? If they plan to allow X-Site-Ajax requests to fetch data from the API, i ditch my current PHP scripts and write this stuff from scratch in JavaScript.

Germany Offline
Reply With Quote
Old 04/15/11, 7:05 PM   #122
BinaryMuse
Glass Joe
 
BinaryMuse's Avatar
 
Tauren Druid
 
Nazjatar
Originally Posted by Furizaa View Post
Seems like they have some sort of Cross Site Policy set. Surprisingly this works:

Simple Realm Status with JQuery & JSONP - Forums - World of Warcraft

Can someone with access to the US forums ask what we can expect for the future? If they plan to allow X-Site-Ajax requests to fetch data from the API, i ditch my current PHP scripts and write this stuff from scratch in JavaScript.
This is specifically what JSONP was designed to do: allow loading JSON data from other domains. See JSONP - Wikipedia, the free encyclopedia.

Offline
Reply With Quote
Old 04/29/11, 9:48 AM   #123
zork
Don Flamenco
 
zork's Avatar
 
Dwarf Warrior
 
Aegwynn (EU)
I set up a small testfile in PHP that gets data from the new WoW Armory API via CURL.

The result is delivered in JSON and then converted into a PHP array.

<?php

  //function and variables

  function json_code($json) {
    return json_decode($json, true);
  }

  //html output
  function p($output) {
    $eol = "\n";
    echo $output.$eol;
  }

  //html header stuff
  header('Content-Type: text/html; charset=utf-8');

  //html output
  p('<html>');
  p('<head>');
  p('  <title>WoW Armory API: Realm Status Test</title>');
  p('</head>');
  p('<body>');
  p('  <h1><a href="test1.php">WoW Armory API: Realm Status Test</a></h1>');

  //url to ask for
  $url = 'http://us.battle.net/api/wow/realm/status?realm=Medivh&realm=Blackrock';

  //curl init
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_VERBOSE, 1);
  curl_setopt($ch, CURLOPT_POST, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  $json = curl_exec($ch);
  curl_close ($ch);


  $json_orig = $json; //temp
  //$json = utf8_encode($json); //in case utf8 encoding is needed
  $arrayed_json = json_code($json); //generate php array from json response

  //Output
  p('  <h3>Output</h3>');
  //print the json code
  print_r($json_orig);

  p('');

  p('  <hr>');

  //print the php array
  print_r($arrayed_json);

  p('');
  p('  <hr>');

  //print result in loop
  $realms = $arrayed_json['realms'];

  for ($i=0;$i<count($realms);$i++) {
    p('  <h3>Realm: '.$realms[$i]['name'].'</h3>');
    p('  <p>Type: '.$realms[$i]['type'].'</p>');
    p('  <p>Status: '.$realms[$i]['status'].'</p>');
    p('  <hr>');
  }

  p('</body>');
  p('</html>');

?>
Once the data is retrieved and converted into an PHP array it can be extracted easily.

Result of the code above:
<html>
<head>
  <title>WoW Armory API: Realm Status Test</title>
</head>
<body>
  <h1><a href="test1.php">WoW Armory API: Realm Status Test</a></h1>
  <h3>Output</h3>
{
  "realms":[
    {
      "type":"pvp",
      "population":"high",
      "queue":false,
      "status":true,
      "name":"Blackrock",
      "slug":"blackrock"
    },
    {
      "type":"pve",
      "population":"medium",
      "queue":false,
      "status":true,
      "name":"Medivh",
      "slug":"medivh"
    }
  ]
}
  <hr>
Array
(
    [realms] => Array
        (
            [0] => Array
                (
                    [type] => pvp
                    [population] => high
                    [queue] => 
                    [status] => 1
                    [name] => Blackrock
                    [slug] => blackrock
                )

            [1] => Array
                (
                    [type] => pve
                    [population] => medium
                    [queue] => 
                    [status] => 1
                    [name] => Medivh
                    [slug] => medivh
                )

        )

)

  <hr>

  <h3>Realm: Blackrock</h3>
  <p>Type: pvp</p>
  <p>Status: 1</p>
  <hr>
  <h3>Realm: Medivh</h3>
  <p>Type: pve</p>

  <p>Status: 1</p>
  <hr>
</body>
</html>

Last edited by zork : 04/29/11 at 10:05 AM.

| Simple is beautiful.
| Blog | Roth UI | Roth UI FAQ | GoogleCode | Zork | Guild | zorker.de

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Offline
Reply With Quote
Reply

Go Back   Elitist Jerks » Public Discussion » Public Discussion

Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
The Warcraft Armory Nite_Moogle Public Discussion 336 06/29/07 4:46 PM
Unpopular talents, or the Armory in action Navaash Public Discussion 303 05/16/07 1:24 AM
In Game Armory Mod Maligne User Interface and AddOns 29 05/07/07 11:37 AM
[All Classes] Armory data used to see 31 and 41 pt talent use. Nomad_Wanderer Class Mechanics 2 05/03/07 11:23 AM