Usage examples
Authentication method 1: key-based
Users authenticate with a unique key (e.g., MYAPP-1234-5678-ABCD-EFGH).
C++Copy
std::string userKey;
std::cout << "Enter your key: ";
std::cin >> userKey;
if (client.AuthenticateWithKey(userKey)) {
std::cout << "Authentication successful!" << std::endl;
auto session = client.GetCurrentSession();
std::cout << "App ID: " << session.appId << std::endl;
std::cout << "Token expires: " << session.tokenExpiry << std::endl;
// User is now authenticated - proceed with your app logic
} else {
std::cout << "Authentication failed: " << client.GetLastError() << std::endl;
}
Authentication method 2: username and password
Traditional login with username/email and password.
C++Copy
std::string username, password;
std::cout << "Username: ";
std::cin >> username;
std::cout << "Password: ";
std::cin >> password;
if (client.AuthenticateWithUsername(username, password)) {
std::cout << "Authentication successful!" << std::endl;
auto session = client.GetCurrentSession();
std::cout << "Welcome, " << username << "!" << std::endl;
std::cout << "App ID: " << session.appId << std::endl;
// User is now authenticated
} else {
std::cout << "Login failed: " << client.GetLastError() << std::endl;
}
Downloading files
Download encrypted files from a product. Files are automatically decrypted.
C++Copy
std::string productId = "your-product-id";
std::string fileName = "update.exe";
std::string outputPath = "./update.exe";
if (client.DownloadFile(productId, fileName, outputPath)) {
std::cout << "File downloaded successfully!" << std::endl;
} else {
std::cout << "Download failed: " << client.GetLastError() << std::endl;
}
// Download to memory instead of file
auto fileData = client.DownloadFileToMemory(productId, fileName);
if (!fileData.empty()) {
std::cout << "Downloaded " << fileData.size() << " bytes" << std::endl;
// Use fileData...
}
Downloading folders
Download entire folders as encrypted ZIP archives.
C++Copy
std::string productId = "your-product-id";
std::string folderName = "Release";
std::string outputPath = "./Release.zip";
if (client.DownloadFolder(productId, folderName, outputPath)) {
std::cout << "Folder downloaded successfully!" << std::endl;
// Extract the ZIP file...
} else {
std::cout << "Download failed: " << client.GetLastError() << std::endl;
}
Fetching product variables
Get configuration variables set for a product (e.g., version numbers, feature flags).
C++Copy
auto variables = client.GetProductVariables(productId);
if (!variables.empty()) {
std::cout << "Product Variables:" << std::endl;
for (const auto& [name, value] : variables) {
std::cout << " " << name << " = " << value << std::endl;
}
}
// Example output:
// VERSION = 1.2.3
// FEATURE_X_ENABLED = true
// API_ENDPOINT = https://api.example.com
Checking subscription status
Verify the user’s subscription to a specific product.
C++Copy
auto subscription = client.GetUserSubscriptionByProduct(productId);
if (!subscription.subscriptionId.empty()) {
std::cout << "Subscription Status: " << subscription.status << std::endl;
std::cout << "Expires At: "
<< (subscription.expiresAt.empty() ? "Lifetime" : subscription.expiresAt)
<< std::endl;
std::cout << "Is Paused: " << (subscription.isPaused ? "Yes" : "No") << std::endl;
if (subscription.status == "active" && !subscription.isPaused) {
// User has valid subscription
std::cout << "Access granted!" << std::endl;
}
} else {
std::cout << "No subscription found for this product" << std::endl;
}