/** * Удаление фотографии. * * <h1>Примеры</h1> * * <h2>Удаление альбома</h2> * <code> * <?php * $api->deletePhoto(12345678); * ?> * </code> * * @param int $photoId Id фотографии, которую нужно удалить * * @return $this * @throws \Yandex\Fotki\Exception\Api\Photo */ public function deletePhoto($photoId) { $apiUrl = sprintf("http://api-fotki.yandex.ru/api/users/%s/photo/%s/", $this->_login, intval($photoId)); $oAuthToken = $this->_transport->getOAuthToken(); $fimpToken = $this->_transport->getFimpToken(); $response = Request::delete($apiUrl, array('Authorization' => $oAuthToken ? "OAuth {$oAuthToken}" : "FimpToken realm=\"fotki.yandex.ru\", token=\"{$fimpToken}\"")); if ($response->code === 204) { return $this; } else { throw new \Yandex\Fotki\Exception\Api\Photo($response->body, $response->code); } }
protected function _loadToken(\Yandex\Fotki\Transport $transport, $apiUrl, array $data) { $error = true; $result = null; $tmp = $transport->post($apiUrl, $data); 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 token! %s", $msg), $tmp['code']); } else { throw new \Yandex\Fotki\Exception\Api\Auth(sprintf("Error get token! %s", $msg), $tmp['code']); } } $response = new \SimpleXMLElement($result); $this->_token = (string) $response->token; return $this; }
/** * Загрузка фото * @param Transport $transport * @param $apiUrl * @param array $data * * @return mixed|null * @throws Exception\Api */ protected function _postData(\Yandex\Fotki\Transport $transport, $apiUrl, array $data) { $error = true; $result = null; $tmp = $transport->post($apiUrl, $data); if ($tmp['code'] == 200 || $tmp['code'] == 201) { $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; }