Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- #########################################################
- # @Filename : WoWToken.php
- # @Version : 1.0.0
- # @Author : Mythotical
- # @Update : 12/25/2017
- # @Website : https://goblintimes.com
- # @Copyright : 2017-2018 © Goblin Times
- # All Rights Reserved
- # @Add-On : [GT] xenPortal
- #########################################################
- namespace GoblinTimes\xenPortal\Repository;
- use XF\Mvc\Entity\Repository;
- /**
- * Class WoWToken
- *
- * @package GoblinTimes\xenPortal\Repository
- */
- class WoWToken extends Repository
- {
- /**
- * @var string
- */
- protected $apiUrl = '%s/data/wow/token/?namespace=%s&locale=%s&access_token=%s';
- /**
- * @var array
- */
- protected $regions = [
- 'gb' => [
- 'url' => 'https://eu.api.battle.net',
- 'locale' => 'en_GB',
- 'dynamic' => 'dynamic-eu',
- ],
- ];
- /**
- * @return array
- */
- public function getTokenPrice($region)
- {
- $options = \XF::options();
- if (!$options->offsetExists('gt_xenportal_wow_access_' . $region))
- {
- throw new \LogicException("Region '$region' doesn't exist.");
- }
- $url = sprintf($this->apiUrl,
- $this->regions[$region]['url'],
- $this->regions[$region]['dynamic'],
- $this->regions[$region]['locale'],
- $options->offsetGet('gt_xenportal_wow_access_' . $region)
- );
- try
- {
- $response = $this->app()->http()->client()->get($url);
- }
- catch(\GuzzleHttp\Exception\RequestException $e)
- {
- \XF::logException($e, false, "Error fetching WoW status from $url: ");
- }
- return $response->json();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement