Yandex Disk C++ Client 1.0.0
Modern C++ client for Yandex.Disk REST API. Simple, lightweight, and static library for integrating Yandex.Disk cloud storage into C++ projects.
Loading...
Searching...
No Matches
YandexDiskClient Class Reference

C++ client for Yandex.Disk REST API. More...

#include <YandexDiskClient.h>

Public Member Functions

 YandexDiskClient (const std::string &oauth_token)
 Constructor. Initializes client with OAuth token.
nlohmann::json getQuotaInfo ()
 Get disk quota information (total, used, trash).
std::string formatQuotaInfo (const nlohmann::json &json)
 Format quota information as human-readable string.
nlohmann::json getResourceList (const std::string &disk_path="/")
 Get list of files and folders at given path.
std::string formatResourceList (const nlohmann::json &json)
 Format resource list as human-readable string.
std::string getResourceInfo (const std::string &disk_path)
 Get detailed information about a file or folder.
bool publish (const std::string &path)
 Publish a file or folder (make it public).
bool unpublish (const std::string &disk_path)
 Unpublish a file or folder (remove public access).
std::string getPublicDownloadLink (const std::string &disk_path)
 Get public download link for a published file or folder.
bool uploadFile (const std::string &disk_dir, const std::string &local_path)
 Upload a local file to Yandex.Disk.
bool downloadFile (const std::string &download_disk_path, const std::string &local_dir)
 Download a file from Yandex.Disk to local directory.
bool uploadDirectory (const std::string &disk_path, const std::string &local_path)
 Recursively upload a local directory to Yandex.Disk.
bool downloadDirectory (const std::string &disk_path, const std::string &local_path)
 Recursively download a directory from Yandex.Disk to local path.
bool deleteFileOrDir (const std::string &disk_path)
 Delete a file or directory from Yandex.Disk.
bool createDirectory (const std::string &disk_path)
 Create a directory on Yandex.Disk.
bool moveFileOrDir (const std::string &from_path, const std::string &to_path, bool overwrite=false)
 Move or copy a file or directory on Yandex.Disk.
bool renameFileOrDir (const std::string &disk_path, const std::string &new_name, bool overwrite=false)
 Rename a file or directory on Yandex.Disk.
bool exists (const std::string &disk_path)
 Check if a file or directory exists on Yandex.Disk.
nlohmann::json getTrashResourceList (const std::string &trash_path="trash:/")
 Get list of files and folders in Yandex.Disk trash.
std::string formatTrashResourceList (const nlohmann::json &json)
 Format trash resource list as human-readable string.
bool restoreFromTrash (const std::string &trash_path)
 Restore a file or directory from trash to its original location.
bool deleteFromTrash (const std::string &trash_path)
 Permanently delete a file or directory from trash.
bool emptyTrash ()
 Empty the entire Yandex.Disk trash.
std::vector< std::string > findTrashPathByName (const std::string &name)
 Find all resources in trash by name.
std::vector< std::string > findResourcePathByName (const std::string &name, const std::string &start_path="/")
 Find all resources on disk by name (recursive).

Detailed Description

C++ client for Yandex.Disk REST API.

Constructor & Destructor Documentation

◆ YandexDiskClient()

YandexDiskClient::YandexDiskClient ( const std::string & oauth_token)
explicit

Constructor. Initializes client with OAuth token.

Parameters
oauth_tokenYandex.Disk OAuth token.

Member Function Documentation

◆ createDirectory()

bool YandexDiskClient::createDirectory ( const std::string & disk_path)

Create a directory on Yandex.Disk.

Parameters
disk_pathPath to directory to create.
Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

◆ deleteFileOrDir()

bool YandexDiskClient::deleteFileOrDir ( const std::string & disk_path)

Delete a file or directory from Yandex.Disk.

Parameters
disk_pathPath to file or directory on Yandex.Disk.
Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

◆ deleteFromTrash()

bool YandexDiskClient::deleteFromTrash ( const std::string & trash_path)

Permanently delete a file or directory from trash.

Parameters
trash_pathPath to resource in trash (from "path" field).
Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

◆ downloadDirectory()

bool YandexDiskClient::downloadDirectory ( const std::string & disk_path,
const std::string & local_path )

Recursively download a directory from Yandex.Disk to local path.

Parameters
disk_pathPath to directory on Yandex.Disk.
local_pathLocal directory to save contents.
Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

◆ downloadFile()

bool YandexDiskClient::downloadFile ( const std::string & download_disk_path,
const std::string & local_dir )

Download a file from Yandex.Disk to local directory.

Parameters
download_disk_pathPath to file on Yandex.Disk.
local_dirLocal directory to save the file.
Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

◆ emptyTrash()

bool YandexDiskClient::emptyTrash ( )

Empty the entire Yandex.Disk trash.

Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

◆ exists()

bool YandexDiskClient::exists ( const std::string & disk_path)

Check if a file or directory exists on Yandex.Disk.

Parameters
disk_pathPath to file or directory.
Returns
true if exists, false otherwise.

◆ findResourcePathByName()

std::vector< std::string > YandexDiskClient::findResourcePathByName ( const std::string & name,
const std::string & start_path = "/" )

Find all resources on disk by name (recursive).

Parameters
nameName of file or folder.
start_pathDirectory to start search from (default: root).
Returns
Vector of full paths for all matches.

◆ findTrashPathByName()

std::vector< std::string > YandexDiskClient::findTrashPathByName ( const std::string & name)

Find all resources in trash by name.

Parameters
nameName of file or folder.
Returns
Vector of full paths in trash for all matches.

◆ formatQuotaInfo()

std::string YandexDiskClient::formatQuotaInfo ( const nlohmann::json & json)

Format quota information as human-readable string.

Parameters
jsonJSON object from getQuotaInfo().
Returns
Formatted string.

◆ formatResourceList()

std::string YandexDiskClient::formatResourceList ( const nlohmann::json & json)

Format resource list as human-readable string.

Parameters
jsonJSON object from getResourceList().
Returns
Formatted string.

◆ formatTrashResourceList()

std::string YandexDiskClient::formatTrashResourceList ( const nlohmann::json & json)

Format trash resource list as human-readable string.

Parameters
jsonJSON object from getTrashResourceList().
Returns
Formatted string.

◆ getPublicDownloadLink()

std::string YandexDiskClient::getPublicDownloadLink ( const std::string & disk_path)

Get public download link for a published file or folder.

Parameters
disk_pathPath to file or folder on Yandex.Disk.
Returns
Public URL as string.
Exceptions
std::runtime_errorif not published or on error.

◆ getQuotaInfo()

nlohmann::json YandexDiskClient::getQuotaInfo ( )

Get disk quota information (total, used, trash).

Returns
JSON object with quota info.
Exceptions
std::runtime_erroron API/network error.

◆ getResourceInfo()

std::string YandexDiskClient::getResourceInfo ( const std::string & disk_path)

Get detailed information about a file or folder.

Parameters
disk_pathPath to file or folder on Yandex.Disk.
Returns
Formatted string with resource info.
Exceptions
std::runtime_erroron API/network error.

◆ getResourceList()

nlohmann::json YandexDiskClient::getResourceList ( const std::string & disk_path = "/")

Get list of files and folders at given path.

Parameters
disk_pathPath on Yandex.Disk (default: root "/").
Returns
JSON object with resource list.
Exceptions
std::runtime_erroron API/network error.

◆ getTrashResourceList()

nlohmann::json YandexDiskClient::getTrashResourceList ( const std::string & trash_path = "trash:/")

Get list of files and folders in Yandex.Disk trash.

Parameters
trash_pathPath in trash (default: "trash:/").
Returns
JSON object with trash resource list.
Exceptions
std::runtime_erroron API/network error.

◆ moveFileOrDir()

bool YandexDiskClient::moveFileOrDir ( const std::string & from_path,
const std::string & to_path,
bool overwrite = false )

Move or copy a file or directory on Yandex.Disk.

Parameters
from_pathSource path.
to_pathDestination path.
overwriteOverwrite if destination exists.
Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

◆ publish()

bool YandexDiskClient::publish ( const std::string & path)

Publish a file or folder (make it public).

Parameters
pathPath to file or folder on Yandex.Disk.
Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

◆ renameFileOrDir()

bool YandexDiskClient::renameFileOrDir ( const std::string & disk_path,
const std::string & new_name,
bool overwrite = false )

Rename a file or directory on Yandex.Disk.

Parameters
disk_pathPath to file or directory.
new_nameNew name.
overwriteOverwrite if destination exists.
Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

◆ restoreFromTrash()

bool YandexDiskClient::restoreFromTrash ( const std::string & trash_path)

Restore a file or directory from trash to its original location.

Parameters
trash_pathPath to resource in trash (from "path" field).
Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

◆ unpublish()

bool YandexDiskClient::unpublish ( const std::string & disk_path)

Unpublish a file or folder (remove public access).

Parameters
disk_pathPath to file or folder on Yandex.Disk.
Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

◆ uploadDirectory()

bool YandexDiskClient::uploadDirectory ( const std::string & disk_path,
const std::string & local_path )

Recursively upload a local directory to Yandex.Disk.

Parameters
disk_pathDestination directory on Yandex.Disk.
local_pathLocal directory to upload.
Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

◆ uploadFile()

bool YandexDiskClient::uploadFile ( const std::string & disk_dir,
const std::string & local_path )

Upload a local file to Yandex.Disk.

Parameters
disk_dirDestination directory or file path on Yandex.Disk.
local_pathPath to local file.
Returns
true on success.
Exceptions
std::runtime_erroron API/network error.

The documentation for this class was generated from the following files: