Skip to content

Krasnovvvvv/yandex-disk-cpp-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

116 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

☁️ Yandex Disk C++ Client

GitHub Tag Documentation License

Ubuntu Windows macOS

CI Ubuntu CI Windows CI macOS

Modern C++ client library for the Yandex.Disk REST API
A simple, lightweight, and efficient static library for integrating Yandex.Disk cloud storage into C++ projects across platforms

🔥 Now available on vcpkg – install in one command!

You can quickly install the library using vcpkg


✨ Features

  • Wide API Coverage:
    Upload and download files and directories, manage directories, move and rename resources, handle trash operations, publish and unpublish files, and retrieve public links

  • Robust File Management:
    Recursive upload and download of directories, existence checks, and detailed resource information retrieval

  • Trash Support:
    List trash contents, restore files or folders to original locations, delete individual items, or empty the entire trash

  • Search Functionality:
    Find files and folders by name both on the disk and in the trash, with recursive search support

  • Cross-Platform Compatibility:
    Works on Windows, Linux, and macOS with Unicode path support

  • Minimal Dependencies:
    Uses only libcurl for HTTP communication and nlohmann/json for JSON parsing

  • Easy Integration:
    Provided as a static library with a clean public header interface for straightforward use in CMake projects


📁 Project Structure

yandex-disk-cpp-client/
├── .github/workflows/       # GitHub Actions CI
├── cmake/                   # Package config templates
├── docs/                    # Generated Doxygen documentation and extra docs
├── examples/                # Example usage programs
├── include/                 # Public headers
├── src/                     # Library source files
├── tests/                   # Unit tests and test CMake configuration
├── CMakeLists.txt           # Root build configuration
├── vcpkg.json               # vcpkg manifest dependencies
├── README.md                # This file
├── LICENSE                  # License file
└── .gitignore               # Git ignore rules

🚀 Quick Start

🛠️ Prerequisites

  • C++17 compatible compiler
  • CMake 3.28 or newer
  • vcpkg
  • Yandex.Disk OAuth token with the required permissions

🔑 OAuth Token

Set the YADISK_TOKEN environment variable before running examples or your own application.

Detailed step-by-step instructions for registering a Yandex OAuth application and obtaining a token are available in docs/OAUTH_TOKEN.md.

⚡ Build and Run Example

git clone https://github.com/Krasnovvvvv/yandex-disk-cpp-client.git
cd yandex-disk-cpp-client

cmake -B build -S . \
  -DCMAKE_TOOLCHAIN_FILE=<path-to-vcpkg>/scripts/buildsystems/vcpkg.cmake \
  -DBUILD_EXAMPLES=ON

cmake --build build

Then run an example executable, for example:

./build/example_basic_usage

On Windows:

.\build\Debug\example_basic_usage.exe

📦 Installation via vcpkg

You can install yandex-disk-cpp-client directly from the official vcpkg registry.

Install

vcpkg install yandex-disk-cpp-client

If you use a specific triplet:

vcpkg install yandex-disk-cpp-client:x64-mingw-static

Use in CMake

find_package(yandex-disk-cpp-client CONFIG REQUIRED)
target_link_libraries(example PRIVATE yandex-disk-cpp-client::yandex-disk-cpp-client)

Notes

  • libcurl and nlohmann-json are resolved automatically via vcpkg
  • Works on Windows, Linux, and macOS
  • Useful both for local development and CI environments

📖 Example Usage

#include "YandexDiskClient.h"
#include <cstdlib>
#include <iostream>

int main() {
    const char* token = std::getenv("YADISK_TOKEN");
    if (!token) {
        std::cerr << "Please set YADISK_TOKEN environment variable." << std::endl;
        return 1;
    }

    YandexDiskClient yandex(token);

    auto quota = yandex.getQuotaInfo();
    std::cout << yandex.formatQuotaInfo(quota) << std::endl;

    auto list = yandex.getResourceList("/");
    std::cout << yandex.formatResourceList(list) << std::endl;

    return 0;
}

For more examples, see examples/


🧭 API Coverage

Category Methods
Disk info getQuotaInfo(), formatQuotaInfo()
Resource listing getResourceList(path), formatResourceList(json), getResourceInfo(path)
File operations uploadFile(disk_path, local_path), downloadFile(disk_path, local_path)
Directory operations createDirectory(path), uploadDirectory(disk_path, local_path), downloadDirectory(disk_path, local_path)
Resource management deleteFileOrDir(path), moveFileOrDir(from, to, overwrite), renameFileOrDir(path, new_name, overwrite), exists(path)
Public access publish(path), unpublish(path), getPublicDownloadLink(path)
Trash operations getTrashResourceList(path), formatTrashResourceList(json), restoreFromTrash(path), deleteFromTrash(path), emptyTrash()
Search findResourcePathByName(name, start_path), findTrashPathByName(name)

🧪 Tests

Unit tests are located in the tests/ directory and are built through a dedicated tests/CMakeLists.txt.

To build and run tests:

cmake -B build -S . \
  -DCMAKE_TOOLCHAIN_FILE=<path-to-vcpkg>/scripts/buildsystems/vcpkg.cmake \
  -DBUILD_TESTS=ON \
  -DBUILD_EXAMPLES=OFF

cmake --build build
ctest --test-dir build --output-on-failure

📚 Documentation

API documentation is generated with Doxygen and published from the docs/ directory.

Online documentation: Documentation


📦 Dependencies

If you use vcpkg manifest mode, dependencies are installed automatically from vcpkg.json.


🤝 Contribution

Contributions, bug reports, and feature requests are welcome.
Please open an issue or submit a pull request.


📝 License

This project is licensed under the MIT License — see LICENSE