Esempio n. 1
0
 /**
  * Retrieve a cache key given a method and its arguments
  *
  * @param DLCompare\LoLApiBundle\Api\Method $method
  * @param array $arguments
  * @return string
  */
 public function getKey(Method $method, array $arguments)
 {
     $key = 'lolapi_';
     $key .= $method->getService()->getPrefix();
     $key .= $method->getSuffix();
     foreach ($arguments as $k => $v) {
         $key .= "." . $k . "-" . $v;
     }
     $key = str_replace(['/', '{', '}'], ['_', '', ''], $key);
     return $key;
 }
Esempio n. 2
0
 /**
  * Builds the url for the given webservice call
  *
  * @param DLCompare\LoLApiBundle\Api\Service\ServiceInterface $service
  * @param array $arguments
  * @param array $querystring
  * @return string
  *
  * @throws \LogicException
  */
 protected function buildUrl(ServiceInterface $service, Method $method, array $arguments = array(), array $querystring = array())
 {
     $url = "https://{region}.api.pvp.net/" . $service->getPrefix() . '/' . $method->getSuffix() . '?api_key=' . self::$api_key;
     $url = str_replace('{region}', $this->region, $url);
     $url = str_replace('{version}', $service->getVersion(), $url);
     foreach ($arguments as $key => $value) {
         $url = str_replace('{' . $key . '}', $value, $url);
     }
     $nok = preg_match_all("|{([\\w]+)}|U", $url, $missing, PREG_SET_ORDER);
     if ($nok > 0) {
         $params = [];
         foreach ($missing as $param) {
             $params[] = $param[0];
         }
         throw new \LogicException('Missing parameters for this webservice : ' . implode(',', $params));
     }
     foreach ($querystring as $key => $value) {
         $url .= '&' . $key . '=' . $value;
     }
     return $url;
 }