Skip to content

Commit ac5f2c7

Browse files
committed
Http client example
1 parent 74ae31c commit ac5f2c7

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

examples/example_integration.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include <chrono>
33
#include <iostream>
44
#include <random>
5+
#include <string>
56
#include <thread>
6-
77
using namespace std;
88
using namespace cly;
99

@@ -30,6 +30,27 @@ void printLog(LogLevel level, const string &msg) {
3030
cout << lvl << msg << endl;
3131
}
3232

33+
// // Custom HTTP client
34+
// HTTPResponse customClient(bool use_post, const std::string &path, const std::string &data) {
35+
// HTTPResponse response;
36+
// response.success = false;
37+
// cout << "Will send the request!!" << endl;
38+
39+
// // asynchronous operation
40+
// std::thread requestThread([&response]() {
41+
// std::this_thread::sleep_for(std::chrono::seconds(2)); // network delay
42+
// // you should add extra logic to check if request is successful normally
43+
// response.success = true;
44+
// response.data = R"({"some":"data"})"; // response data
45+
// });
46+
47+
// // Wait for the request to complete
48+
// requestThread.join();
49+
// cout << "Got RESPONSE:[" + response.data.dump() + "]" << endl;
50+
51+
// return response;
52+
// }
53+
3354
int main() {
3455
cout << "Sample App" << endl;
3556
Countly &ct = Countly::getInstance();
@@ -38,13 +59,17 @@ int main() {
3859
// Please refer to the documentation for more information:
3960
// https://support.count.ly/hc/en-us/articles/4416163384857-C-
4061

41-
ct.alwaysUsePost(true);
62+
// Custom HTTP client
63+
// HTTPClientFunction clientPtr = customClient;
64+
// ct.setHTTPClient(clientPtr);
65+
// ct.alwaysUsePost(true);
66+
4267
ct.setLogger(printLog);
4368
ct.SetPath("databaseFileName.db"); // this will be only built into account if the correct configurations are set
4469
ct.setDeviceID("test-device-id");
4570
// ct.setSalt("test-salt");
4671
// OS, OS_version, device, resolution, carrier, app_version);
47-
ct.SetMetrics("Windows 10", "10.22", "Mac", "800x600", "Carrier", "1.0");
72+
// ct.SetMetrics("Windows 10", "10.22", "Mac", "800x600", "Carrier", "1.0");
4873

4974
// start the SDK (initialize the SDK)
5075
string _appKey = "YOUR_APP_KEY";

0 commit comments

Comments
 (0)