Advertisement
Belazor

Untitled

Jan 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1. <?php
  2. #########################################################
  3. # @Filename        : WoWToken.php
  4. # @Version        : 1.0.0
  5. # @Author        : Mythotical
  6. # @Update        : 12/25/2017
  7. # @Website        : https://goblintimes.com
  8. # @Copyright    : 2017-2018 © Goblin Times
  9. #                  All Rights Reserved
  10. # @Add-On        : [GT] xenPortal
  11. #########################################################
  12.  
  13. namespace GoblinTimes\xenPortal\Repository;
  14.  
  15. use XF\Mvc\Entity\Repository;
  16.  
  17. /**
  18.  * Class WoWToken
  19.  *
  20.  * @package GoblinTimes\xenPortal\Repository
  21.  */
  22. class WoWToken extends Repository
  23. {
  24.     /**
  25.      * @var string
  26.      */
  27.     protected $apiUrl = '%s/data/wow/token/?namespace=%s&locale=%s&access_token=%s';
  28.    
  29.     /**
  30.      * @var array
  31.      */
  32.     protected $regions = [
  33.         'gb' => [
  34.             'url' => 'https://eu.api.battle.net',
  35.             'locale' => 'en_GB',
  36.             'dynamic' => 'dynamic-eu',
  37.         ],
  38.    
  39.     ];
  40.    
  41.     /**
  42.      * @return array
  43.      */
  44.     public function getTokenPrice($region)
  45.     {
  46.         $options = \XF::options();
  47.        
  48.         if (!$options->offsetExists('gt_xenportal_wow_access_' . $region))
  49.         {
  50.             throw new \LogicException("Region '$region' doesn't exist.");
  51.         }
  52.        
  53.         $url = sprintf($this->apiUrl,
  54.             $this->regions[$region]['url'],
  55.             $this->regions[$region]['dynamic'],
  56.             $this->regions[$region]['locale'],
  57.             $options->offsetGet('gt_xenportal_wow_access_' . $region)
  58.         );
  59.        
  60.         try
  61.         {
  62.             $response = $this->app()->http()->client()->get($url);
  63.         }
  64.         catch(\GuzzleHttp\Exception\RequestException $e)
  65.         {
  66.             \XF::logException($e, false, "Error fetching WoW status from $url: ");
  67.         }
  68.        
  69.         return $response->json();
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement