Created
December 4, 2012 20:17
-
-
Save rubensayshi/4208247 to your computer and use it in GitHub Desktop.
GW2Spidy example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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