コード例 #1
0
 /**
  * Загрузка данных из api
  * @param Transport $transport
  * @param string $apiUrl
  * @return mixed|null
  * @throws Exception\Api
  */
 protected function _getData(\Yandex\Fotki\Transport $transport, $apiUrl)
 {
     $error = true;
     $result = null;
     $tmp = $transport->get($apiUrl);
     if ($tmp['code'] == 200) {
         $result = json_decode($tmp['data'], true);
         if (!is_null($result)) {
             $error = false;
         }
     }
     if ($error) {
         $text = strip_tags($tmp['data']);
         $msg = sprintf("Command %s error (%s). %s", get_called_class(), $apiUrl, trim($text));
         throw new \Yandex\Fotki\Exception\Api($msg, $tmp['code']);
     }
     return $result;
 }
コード例 #2
0
 protected function _loadRsaKey(\Yandex\Fotki\Transport $transport, $apiUrl)
 {
     $error = true;
     $result = null;
     $tmp = $transport->get($apiUrl);
     if ($tmp['code'] == 200) {
         $result = $tmp['data'];
         $error = false;
     }
     if ($error) {
         $text = strip_tags($tmp['data']);
         $msg = sprintf("Command %s error (%s). %s", get_called_class(), $apiUrl, trim($text));
         if ($tmp['code'] == 502) {
             throw new \Yandex\Fotki\Exception\ServerError(sprintf("Error get RSA key! %s", $msg), $tmp['code']);
         } else {
             throw new \Yandex\Fotki\Exception\Api\Auth(sprintf("Error get RSA key! %s", $msg), $tmp['code']);
         }
     }
     $response = new \SimpleXMLElement($result);
     $this->_requestId = (string) $response->request_id;
     $this->_rsaKey = (string) $response->key;
     return $this;
 }