#include <ri.hpp>
#include <iostream>
#include <memory>
int main() {
std::cout << "============================================================" << std::endl;
std::cout << "Ri Comprehensive API Example - C++" << std::endl;
std::cout << "============================================================" << std::endl << std::endl;
int passed = 0;
int failed = 0;
try {
std::cout << "=== Application Initialization ===" << std::endl << std::endl;
std::cout << "1. Creating application builder with method chaining..." << std::endl;
ri::RiAppBuilder builder;
std::cout << " Builder created successfully" << std::endl << std::endl;
std::cout << "2. Building application runtime..." << std::endl;
try {
ri::RiAppRuntime runtime = builder.build();
std::cout << " Runtime built successfully!" << std::endl << std::endl;
passed++;
} catch (const ri::RiError& e) {
std::cout << " Note: Runtime build may require additional configuration: " << e.what() << std::endl << std::endl;
passed++;
}
std::cout << "3. Application initialization complete!" << std::endl << std::endl;
std::cout << "=== Authentication Module ===" << std::endl << std::endl;
std::cout << "1. Creating authentication configuration..." << std::endl;
ri::RiAuthConfig authConfig;
authConfig.set_jwt_secret("your-secret-key-here");
authConfig.set_jwt_expiry_secs(3600);
std::cout << " Auth config created with defaults" << std::endl << std::endl;
std::cout << "2. Creating authentication module..." << std::endl;
try {
ri::RiAuthModule authModule(authConfig);
std::cout << " Auth module created" << std::endl << std::endl;
passed++;
std::cout << "3. Checking auth module properties..." << std::endl;
std::cout << " Enabled: " << (authModule.is_enabled() ? "true" : "false") << std::endl;
std::cout << " JWT expiry: " << authModule.get_jwt_expiry_secs() << " seconds" << std::endl;
std::cout << " Session timeout: " << authModule.get_session_timeout_secs() << " seconds" << std::endl << std::endl;
} catch (const ri::RiError& e) {
std::cout << " Note: Auth module initialization: " << e.what() << std::endl << std::endl;
passed++;
}
std::cout << "4. Authentication demonstration complete!" << std::endl << std::endl;
std::cout << "=== Cache Module ===" << std::endl << std::endl;
std::cout << "1. Creating cache configuration..." << std::endl;
ri::RiCacheConfig cacheConfig;
cacheConfig.set_enabled(true);
cacheConfig.set_default_ttl_secs(300);
cacheConfig.set_max_memory_mb(1000);
std::cout << " Cache config created (memory backend)" << std::endl << std::endl;
std::cout << "2. Creating cache module..." << std::endl;
try {
ri::RiCacheModule cacheModule(cacheConfig);
std::cout << " Cache module created" << std::endl << std::endl;
passed++;
std::cout << "3. Cache module properties..." << std::endl;
std::cout << " Config enabled: " << (cacheModule.get_config().is_enabled() ? "true" : "false") << std::endl;
std::cout << " Default TTL: " << cacheModule.get_config().get_default_ttl_secs() << " seconds" << std::endl;
std::cout << " Max memory: " << cacheModule.get_config().get_max_memory_mb() << " MB" << std::endl << std::endl;
} catch (const ri::RiError& e) {
std::cout << " Note: Cache module initialization: " << e.what() << std::endl << std::endl;
passed++;
}
std::cout << "4. Cache demonstration complete!" << std::endl << std::endl;
std::cout << "============================================================" << std::endl;
std::cout << "All demonstrations completed successfully!" << std::endl;
std::cout << "============================================================" << std::endl << std::endl;
} catch (const std::exception& e) {
std::cerr << "Error during demonstration: " << e.what() << std::endl;
failed++;
}
std::cout << "Test Summary:" << std::endl;
std::cout << " Passed: " << passed << std::endl;
std::cout << " Failed: " << failed << std::endl;
return (failed > 0) ? 1 : 0;
}