@@ -5,7 +5,7 @@ A powerful way to send personalized messages at scale and build effective custom
5
5
## Overview
6
6
This API client was generated by the [ OpenAPI Generator] ( https://openapi-generator.tech ) project. By using the [ OpenAPI spec] ( https://openapis.org ) from a remote server, you can easily generate an API client.
7
7
8
- - API version: 1.0.2
8
+ - API version: 1.0.1
9
9
- Package version:
10
10
- Build package: org.openapitools.codegen.languages.CppRestSdkClientCodegen
11
11
For more information, please visit [ https://onesignal.com ] ( https://onesignal.com )
@@ -20,13 +20,43 @@ For more information, please visit [https://onesignal.com](https://onesignal.com
20
20
Install [ cpprestsdk] ( https://github.com/Microsoft/cpprestsdk ) .
21
21
22
22
- Windows: ` vcpkg install cpprestsdk cpprestsdk:x64-windows boost-uuid boost-uuid:x64-windows `
23
- - Mac: ` brew install cpprestsdk `
23
+ - Mac:
24
+ ` brew install cpprestsdk `
25
+ ` brew install openssl `
24
26
- Linux: ` sudo apt-get install libcpprest-dev `
25
27
28
+ ### Cmake integration
29
+ You can ` cmake --install . ` and then use ` find_package(CppRestOneSignalAPIClient REQUIRED) ` .
30
+ Alternatively you can have it as a subdirectory as in the example below.
31
+
32
+
33
+ Take a look on our test ` CMakeLists.txt ` :
34
+ ```
35
+ cmake_minimum_required(VERSION 3.22)
36
+ project(CppRestOneSignalAPIClientTest)
37
+
38
+ set(CMAKE_CXX_STANDARD 14)
39
+
40
+ # Test dependencies
41
+ find_package(Catch2 REQUIRED)
42
+
43
+ # OneSignal Client Library
44
+ add_subdirectory(deps/onesignal)
45
+
46
+ # Executables for tests
47
+ add_executable(tests test.cpp)
48
+
49
+ target_link_libraries(tests Catch2::Catch2 CppRestOneSignalAPIClient)
50
+ ```
51
+
26
52
### Build
27
53
28
54
``` sh
29
- cmake -DCPPREST_ROOT=/usr -DCMAKE_CXX_FLAGS=" -I/usr/local/opt/openssl/include" -DCMAKE_MODULE_LINKER_FLAGS=" -L/usr/local/opt/openssl/lib"
55
+ cmake -DCMAKE_CXX_FLAGS=" -I/usr/local/include -I/usr/local/Cellar/include -I/usr/local/opt/include" \
56
+ -DCMAKE_MODULE_LINKER_FLAGS=" -L/usr/local/lib -L/usr/local/Cellar/lib -L/usr/local/opt/lib" \
57
+ -DCMAKE_EXE_LINKER_FLAGS=" -L/usr/local/lib -L/usr/local/Cellar/lib -L/usr/local/opt/lib -L/usr/local/opt/openssl/lib" \
58
+ -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \
59
+ -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib \
30
60
make
31
61
```
32
62
@@ -45,6 +75,226 @@ C++ tools for CMake' is selected in the 'Installation Details' section.
45
75
46
76
Also be sure to review the CMakeLists.txt file. Edits are likely required.*
47
77
78
+ ## How to use
79
+ ### Initializing the OneSignal CPP Client library
80
+ ``` cgo
81
+ #include "CppRestOneSignalAPIClient/ApiClient.h"
82
+ #include "CppRestOneSignalAPIClient/ApiConfiguration.h"
83
+ #include "CppRestOneSignalAPIClient/api/DefaultApi.h"
84
+
85
+ using com::onesignal::client::api::ApiClient;
86
+ using com::onesignal::client::api::ApiConfiguration;
87
+ using com::onesignal::client::api::DefaultApi;
88
+
89
+ using utility::string_t;
90
+ using utility::conversions::to_string_t;
91
+
92
+ const std::string APP_ID = "<YOUR_APP_ID>";
93
+ const std::string APP_KEY_TOKEN = "<YOUR_APP_KEY_TOKEN>";
94
+ const std::string USER_KEY_TOKEN = "<YOUR_USER_KEY_TOKEN>";
95
+
96
+ static DefaultApi * createApi() {
97
+ // Settings up the client
98
+ const auto configuration = ApiClient::getDefaultConfiguration();
99
+ configuration->setAppKeyToken(APP_KEY_TOKEN);
100
+ configuration->setUserKeyToken(USER_KEY_TOKEN);
101
+
102
+ const auto apiClient = std::make_shared<ApiClient>(configuration);
103
+
104
+ return new DefaultApi(apiClient);
105
+ }
106
+
107
+ ```
108
+
109
+ ### Creating a notification
110
+ ``` cgo
111
+ static std::shared_ptr<Notification> createNotification() {
112
+ const auto notification = std::make_shared<Notification>();
113
+ notification->setAppId(APP_ID);
114
+
115
+ const auto content = std::make_shared<StringMap>();
116
+ content->setEn(to_string_t("OneSignal C++ Client Test: Create notification"));
117
+ std::vector<string_t> vect{ to_string_t("Active Users") };
118
+
119
+ notification->setContents(content);
120
+ notification->setIncludedSegments(vect);
121
+ notification->setIsAnyWeb(true);
122
+ notification->setIsChrome(true);
123
+
124
+ return notification;
125
+ }
126
+ ```
127
+ ### Sending a notification
128
+ ``` cgo
129
+ const auto api = createApi();
130
+
131
+ // Creating a notification
132
+ const auto notification = createNotification();
133
+
134
+ // Send a notification
135
+ const auto response = api->createNotification(notification);
136
+ const auto & responseData = response.get();
137
+
138
+ // Check the result
139
+ CHECK(responseData->getId().size() > 0);
140
+ CHECK_FALSE(responseData->errorsIsSet());
141
+ ```
142
+
143
+ ### Sending and canceling scheduled notification
144
+ ``` cgo
145
+ const auto api = createApi();
146
+
147
+ // Create a scheduled notification
148
+ const auto notification = createNotification();
149
+
150
+ notification->setSendAfter(utility::datetime().utc_now() + utility::datetime().from_hours(1));
151
+
152
+ // Send a notification
153
+ const auto sendResponse = api->createNotification(notification);
154
+ const auto & sendResponseData = sendResponse.get();
155
+
156
+ // Cancel a scheduled notification
157
+ const auto cancelResponse = api->cancelNotification(APP_ID, sendResponseData->getId());
158
+ const auto & cancelResponseData = cancelResponse.get();
159
+
160
+ // Check the result
161
+ CHECK(cancelResponseData->isSuccess());
162
+ ```
163
+
164
+ ### Getting a notification
165
+ ``` cgo
166
+ const auto api = createApi();
167
+
168
+ // Get a notification
169
+ const auto getResponse = api->getNotification(APP_ID, "<your_notification_id>");
170
+ const auto & getResponseData = getResponse.get();
171
+
172
+ // Check the result
173
+ CHECK(getResponseData->getId() == sendResponseData->getId());
174
+ ```
175
+
176
+ ### Getting a list of notifications
177
+ ``` cgo
178
+ const auto api = createApi();
179
+
180
+ // Creating a notification
181
+ const auto notification = createNotification();
182
+
183
+ // Get list of notification with the limit of 10
184
+ const auto getResponse = api->getNotifications(APP_ID, 10, boost::none, boost::none);
185
+ const auto & notificationSlice = getResponse.get();
186
+
187
+ // Check the result
188
+ CHECK(notificationSlice->getNotifications().size() == 10);
189
+ ```
190
+
191
+ ### Creating and getting a player
192
+ ``` cgo
193
+ static std::shared_ptr<Player> createPlayer() {
194
+ const auto player = std::make_shared<Player>();
195
+
196
+ player->setAppId(APP_ID);
197
+ player->setIdentifier("Id_example");
198
+ player->setDeviceType(1);
199
+
200
+ return player;
201
+ }
202
+ ```
203
+
204
+ ``` cgo
205
+ const auto api = createApi();
206
+
207
+ // Creating a player
208
+ const auto player = createPlayer();
209
+
210
+ // Send a create request
211
+ const auto createResponse = api->createPlayer(player);
212
+ const auto & createResponseData = createResponse.get();
213
+
214
+ // Send a get request
215
+ const auto getResponse = api->getPlayer(APP_ID, createResponseData->getId(), boost::none);
216
+ const auto & getResponseData = getResponse.get();
217
+
218
+ CHECK(createResponseData->isSuccess());
219
+ CHECK(getResponseData->getId() == createResponseData->getId());
220
+ ```
221
+
222
+ ### Creating and deleting a segment
223
+ ``` cgo
224
+ static std::shared_ptr<Segment> createSegment(string_t segmentName) {
225
+ // Setting up filters
226
+ const auto filterExpressions = std::make_shared<FilterExpressions>();
227
+ filterExpressions->setField(to_string_t("session_count"));
228
+ filterExpressions->setRelation(to_string_t(">"));
229
+ filterExpressions->setValue("1");
230
+
231
+ std::vector<std::shared_ptr<FilterExpressions>> vect;
232
+ vect.push_back(filterExpressions);
233
+
234
+ // Setting up the segment
235
+ const auto segment = std::make_shared<Segment>();
236
+ segment->setName(segmentName);
237
+ segment->setFilters(vect);
238
+
239
+ return segment;
240
+ }
241
+ ```
242
+
243
+ ``` cgo
244
+ const auto api = createApi();
245
+
246
+ // Creating a segment
247
+ const auto segment = createSegment("<test_segment_name>");
248
+
249
+ // Send a create request
250
+ const auto createResponse = api->createSegments(APP_ID, segment);
251
+ const auto & createResponseData = createResponse.get();
252
+
253
+ sleep(10);
254
+
255
+ // Send a delete request
256
+ const auto deleteResponse = api->deleteSegments(APP_ID, createResponseData->getId());
257
+ const auto & deleteResponseData = deleteResponse.get();
258
+
259
+ // Check the result
260
+ CHECK(deleteResponseData->isSuccess());
261
+ ```
262
+
263
+ ### Getting an App
264
+ ``` cgo
265
+ const auto api = createApi();
266
+
267
+ // Send a get request
268
+ const auto getResponse = api->getApp(APP_ID);
269
+ const auto & app = getResponse.get();
270
+
271
+ // Check the result
272
+ CHECK(app->getId() == APP_ID);
273
+ ```
274
+
275
+ ### Getting outcomes
276
+ ``` cgo
277
+ const auto api = createApi();
278
+
279
+ // Set up the request
280
+ const auto outcomeNames = to_string_t("os__session_duration.count,os__click.count");
281
+ const auto outcomeTimeRange = to_string_t("1d");
282
+ const auto outcomePlatforms = to_string_t("5");
283
+ const auto outcomeAttribution = to_string_t("direct");
284
+
285
+ // Send the request
286
+ const auto outcomesResponse = api->getOutcomes(APP_ID,
287
+ outcomeNames,
288
+ boost::none,
289
+ outcomeTimeRange,
290
+ outcomePlatforms,
291
+ outcomeAttribution);
292
+ const auto outcomes = outcomesResponse.get()->getOutcomes();
293
+
294
+ // Check the result
295
+ CHECK(outcomes.size() > 0);
296
+ ```
297
+
48
298
## Author
49
299
50
300
0 commit comments