Cupara
Well-known member
I swear this worked in 2.0 but in 2.1 it doesn't seem to insert the data. I have tried to get a data dump so I could see the results but nothing appears since I'm running this through a cron. I did get it to work prior when I had errors and it was grabbing data fine. Anyway, here is the code, hopefully someone will see my mistake.
Thanks
PHP:
public function insertRealms()
{
$options = \XF::options();
$db = \XF::db();
$app = \XF::app();
try
{
$results = $app->http()->client()->get('https://us.api.blizzard.com/data/wow/realm/index?namespace=dynamic-us&locale=en_US&access_token=UShw2Mej5wyRMeaWgtP0qMKTbWyocEyIty');
}
catch(\GuzzleHttp\Exception\RequestException $e)
{
if (null !== $e->getResponse())
{
$error = 'Error' . $e->getResponse()->getStatusCode() . ' - ' . $e->getResponse()->getReasonPhrase();
} else {
$error = $e->getMessage();
}
return $error;
}
$results = \GuzzleHttp\json_decode($results->getBody(), true);
$realms = $results['realms'];
foreach($realms AS $n)
{
$this->db()->insert('xwow_realms', [
'realm_id' => $n['id'],
'realm_name' => $n['name'],
'realm_slug' => $n['slug'],
'realm_locale' => $options['xenwow_locale']
]);
}
return true;
}
Thanks