Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 113 additions & 1 deletion examples/example_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,115 @@ void printLog(LogLevel level, const string &msg) {
cout << lvl << msg << endl;
}

// // Callback function to write response data
// static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) {
// ((std::string*)userp)->append((char*)contents, size * nmemb);
// return size * nmemb;
// }

// // Custom HTTP client for macOS
// HTTPResponse customClient(bool use_post, const std::string &path, const std::string &data) {
// HTTPResponse response;
// response.success = false;
// cout << "Making real HTTP request to: " << path << endl;

// CURL *curl;
// CURLcode res;
// std::string readBuffer;

// curl = curl_easy_init();
// if(curl) {
// // Set URL
// curl_easy_setopt(curl, CURLOPT_URL, path.c_str());

// // Set callback function to write data
// curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
// curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);

// // Set timeout
// curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30L);

// // Follow redirects
// curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

// // SSL verification (set to 0 for testing, 1 for production)
// curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
// curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);

// // Set User-Agent
// curl_easy_setopt(curl, CURLOPT_USERAGENT, "Countly-SDK-CPP/1.0");

// if (use_post) {
// // Set POST method
// curl_easy_setopt(curl, CURLOPT_POST, 1L);

// if (!data.empty()) {
// // Set POST data
// curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
// curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.length());
// }

// // Set content type for POST
// struct curl_slist *headers = NULL;
// headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
// curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
// } else {
// // For GET requests, append data as query parameters
// if (!data.empty()) {
// std::string fullUrl = path;
// fullUrl += (path.find('?') != std::string::npos) ? "&" : "?";
// fullUrl += data;
// curl_easy_setopt(curl, CURLOPT_URL, fullUrl.c_str());
// }
// }

// // Perform the request
// res = curl_easy_perform(curl);

// if(res != CURLE_OK) {
// cout << "curl_easy_perform() failed: " << curl_easy_strerror(res) << endl;
// } else {
// // Get response code
// long response_code;
// curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);

// cout << "HTTP Response Code: " << response_code << endl;
// cout << "Raw response: " << readBuffer << endl;

// // Check if HTTP request was successful (2xx status codes)
// if (response_code >= 200 && response_code < 300) {
// // Check if response contains { result: 'Success' } or {"result":"Success"}
// if (readBuffer.find("\"result\"") != std::string::npos &&
// (readBuffer.find("\"Success\"") != std::string::npos ||
// readBuffer.find("'Success'") != std::string::npos)) {
// response.success = true;
// cout << "Success response detected!" << endl;
// } else {
// cout << "Response does not indicate success" << endl;
// }

// // Parse as JSON
// try {
// response.data = nlohmann::json::parse(readBuffer);
// } catch (const std::exception& e) {
// cout << "Failed to parse JSON response: " << e.what() << endl;
// response.data = nlohmann::json::object();
// }
// } else {
// cout << "HTTP request failed with code: " << response_code << endl;
// }
// }

// // Cleanup
// curl_easy_cleanup(curl);
// } else {
// cout << "Failed to initialize curl" << endl;
// }

// cout << "Request completed. Success: " << (response.success ? "true" : "false") << endl;
// return response;
// }

int main() {
cout << "Sample App" << endl;
Countly &ct = Countly::getInstance();
Expand All @@ -38,7 +147,10 @@ int main() {
// Please refer to the documentation for more information:
// https://support.count.ly/hc/en-us/articles/4416163384857-C-

ct.alwaysUsePost(true);
// Custom HTTP client
// HTTPClientFunction clientPtr = customClient;
// ct.setHTTPClient(clientPtr);
// ct.alwaysUsePost(true);
ct.setLogger(printLog);
ct.SetPath("databaseFileName.db"); // this will be only built into account if the correct configurations are set
ct.setDeviceID("test-device-id");
Expand Down
Loading