Skip to content

Instantly share code, notes, and snippets.

@rubensayshi
Created December 4, 2012 20:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rubensayshi/4208247 to your computer and use it in GitHub Desktop.
Save rubensayshi/4208247 to your computer and use it in GitHub Desktop.
GW2Spidy example
<?php
ini_set('max_execution_time', 0);
class GW2SpidyDataset {
protected $data;
public function getItemById($id) {
if (!$this->data) {
$this->getData();
}
return isset($this->data['results'][$id]) ? $this->data['results'][$id] : null;
}
public function getItemByName($name) {
if (!$this->data) {
$this->getData();
}
foreach ($this->data['results'] as $id => $item) {
if ($item['name'] == $name) {
return $item;
}
}
return null;
}
protected function getData() {
$this->data = json_decode(file_get_contents("http://www.gw2spidy.com/api/v0.9/json/all-items/all"), true);
}
}
$con = mysql_connect('localhost', 'root', 'pass');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$gw2spidy = new GW2SpidyDataset();
function updateitem($itemname) {
$gw2spidy = $GLOBALS['gw2spidy'];
$item = $gw2spidy->getItemByName($itemname);
if ($item) {
// your code here, for example;
echo "{$item['name']} costs {$item['min_sale_unit_price']}. \n";
} else {
echo "failed to find item! \n";
}
}
updateitem('Tooth of Frostfang');
updateitem('Vial of Powerful Blood');
updateitem('Vicious Fang');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment