Skip to content

Commit 858a158

Browse files
author
OneSignal
committed
Update CPP API
1 parent c7ee495 commit 858a158

File tree

102 files changed

+11686
-2813
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+11686
-2813
lines changed

LICENSE

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Modified MIT License
2+
3+
Copyright 2022 OneSignal
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
1. The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
2. All copies of substantial portions of the Software may only be used in connection
16+
with services provided by OneSignal.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
THE SOFTWARE.

README.md

+253-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A powerful way to send personalized messages at scale and build effective custom
55
## Overview
66
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.
77

8-
- API version: 1.0.2
8+
- API version: 1.0.1
99
- Package version:
1010
- Build package: org.openapitools.codegen.languages.CppRestSdkClientCodegen
1111
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
2020
Install [cpprestsdk](https://github.com/Microsoft/cpprestsdk).
2121

2222
- 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`
2426
- Linux: `sudo apt-get install libcpprest-dev`
2527

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+
2652
### Build
2753

2854
```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 \
3060
make
3161
```
3262

@@ -45,6 +75,226 @@ C++ tools for CMake' is selected in the 'Installation Details' section.
4575

4676
Also be sure to review the CMakeLists.txt file. Edits are likely required.*
4777

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+
48298
## Author
49299

50300

include/CppRestOneSignalAPIClient/ApiClient.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OneSignal
33
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
44
*
5-
* The version of the OpenAPI document: 1.0.2
5+
* The version of the OpenAPI document: 1.0.1
66
* Contact: [email protected]
77
*
88
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
@@ -64,6 +64,7 @@ class ApiClient
6464
static utility::string_t parameterToString(double value);
6565
static utility::string_t parameterToString(const utility::datetime &value);
6666
static utility::string_t parameterToString(bool value);
67+
static std::shared_ptr<ApiConfiguration> getDefaultConfiguration();
6768
template<class T>
6869
static utility::string_t parameterToString(const std::vector<T>& value);
6970
template<class T>

include/CppRestOneSignalAPIClient/ApiConfiguration.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OneSignal
33
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
44
*
5-
* The version of the OpenAPI document: 1.0.2
5+
* The version of the OpenAPI document: 1.0.1
66
* Contact: [email protected]
77
*
88
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.
@@ -52,10 +52,18 @@ class ApiConfiguration
5252
utility::string_t getApiKey( const utility::string_t& prefix) const;
5353
void setApiKey( const utility::string_t& prefix, const utility::string_t& apiKey );
5454

55+
utility::string_t getBearerToken( const utility::string_t& prefix ) const;
56+
void setBearerToken( const utility::string_t& prefix, const utility::string_t& bearerToken );
57+
58+
void setAppKeyToken( const utility::string_t& bearerToken );
59+
void setUserKeyToken( const utility::string_t& bearerToken );
60+
61+
5562
protected:
5663
utility::string_t m_BaseUrl;
5764
std::map<utility::string_t, utility::string_t> m_DefaultHeaders;
5865
std::map<utility::string_t, utility::string_t> m_ApiKeys;
66+
std::map<utility::string_t, utility::string_t> m_BearerTokens;
5967
web::http::client::http_client_config m_HttpConfig;
6068
utility::string_t m_UserAgent;
6169
};

include/CppRestOneSignalAPIClient/ApiException.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OneSignal
33
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
44
*
5-
* The version of the OpenAPI document: 1.0.2
5+
* The version of the OpenAPI document: 1.0.1
66
* Contact: [email protected]
77
*
88
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.

include/CppRestOneSignalAPIClient/HttpContent.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OneSignal
33
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
44
*
5-
* The version of the OpenAPI document: 1.0.2
5+
* The version of the OpenAPI document: 1.0.1
66
* Contact: [email protected]
77
*
88
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.

include/CppRestOneSignalAPIClient/IHttpBody.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OneSignal
33
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
44
*
5-
* The version of the OpenAPI document: 1.0.2
5+
* The version of the OpenAPI document: 1.0.1
66
* Contact: [email protected]
77
*
88
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.

include/CppRestOneSignalAPIClient/JsonBody.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* OneSignal
33
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
44
*
5-
* The version of the OpenAPI document: 1.0.2
5+
* The version of the OpenAPI document: 1.0.1
66
* Contact: [email protected]
77
*
88
* NOTE: This class is auto generated by OpenAPI-Generator 6.0.0-SNAPSHOT.

0 commit comments

Comments
 (0)