Example #1
0
 /**
  * @param Query $query
  * @return string
  */
 public function query(Query $query)
 {
     if (!$query->getPackage() && $this->package) {
         $query->setPackage($this->getPackage());
     }
     if (!$query->getToken() && $this->token) {
         $query->setToken($this->getToken());
     }
     $body = file_get_contents($this->getEndpointUrl() . $query->toQueryString());
     $decoded = json_decode($body, JSON_OBJECT_AS_ARRAY);
     if (NULL === $decoded) {
         throw new NumerologException($body);
     }
     if (!empty($decoded['error'])) {
         $exceptionClass = isset($decoded['type']) ? $decoded['type'] : 'NamelessCoder\\Numerolog\\NumerologException';
         throw new $exceptionClass($decoded['error'], $decoded['code']);
     }
     return $decoded;
 }