3939#import < sys/sysctl.h>
4040
4141// SUBCLASSES - These subclasses each represent an individual request
42- @implementation OSRequestGetTags
43- + (instancetype )withUserId : (NSString *)userId appId : (NSString *)appId {
44- let request = [OSRequestGetTags new ];
45-
46- request.parameters = @{@" app_id" : appId};
47- request.method = GET;
48- request.path = [NSString stringWithFormat: @" players/%@ " , userId];
49- request.disableLocalCaching = true ;
50-
51- return request;
52- }
53- @end
5442
5543/*
5644 NOTE: The OSRequestGetIosParams request will not return a Cache-Control header
@@ -78,39 +66,6 @@ -(BOOL)missingAppId {
7866}
7967@end
8068
81- @implementation OSRequestSendTagsToServer
82- + (instancetype _Nonnull)withUserId : (NSString * _Nonnull)userId appId : (NSString * _Nonnull)appId tags : (NSDictionary * _Nonnull)tags networkType : (NSNumber * _Nonnull)netType withEmailAuthHashToken : (NSString * _Nullable)emailAuthToken withExternalIdAuthHashToken : (NSString * _Nullable)externalIdAuthToken {
83- return [self withUserId: userId appId: appId tags: tags networkType: netType withAuthHashToken: emailAuthToken withAuthTokenKey: @" email_auth_hash" withExternalIdAuthHashToken: externalIdAuthToken];
84- }
85-
86- + (instancetype )withUserId : (NSString *)userId appId : (NSString *)appId tags : (NSDictionary *)tags networkType : (NSNumber *)netType withSMSAuthHashToken : (NSString *)smsAuthToken withExternalIdAuthHashToken : (NSString *)externalIdAuthToken {
87- return [self withUserId: userId appId: appId tags: tags networkType: netType withAuthHashToken: smsAuthToken withAuthTokenKey: @" sms_auth_hash" withExternalIdAuthHashToken: externalIdAuthToken];
88- }
89-
90- + (instancetype )withUserId : (NSString *)userId appId : (NSString *)appId tags : (NSDictionary *)tags networkType : (NSNumber *)netType withAuthHashToken : (NSString *)authToken withAuthTokenKey : (NSString *)authTokenKey withExternalIdAuthHashToken : (NSString *)externalIdAuthToken {
91- let request = [OSRequestSendTagsToServer new ];
92-
93- let params = [NSMutableDictionary new ];
94- params[@" app_id" ] = appId;
95- params[@" tags" ] = tags;
96- params[@" net_type" ] = netType;
97-
98- if (authToken && authToken.length > 0 )
99- params[authTokenKey] = authToken;
100-
101- if (externalIdAuthToken && externalIdAuthToken.length > 0 )
102- params[@" external_user_id_auth_hash" ] = externalIdAuthToken;
103-
104- request.parameters = params;
105- request.method = PUT;
106- request.path = [NSString stringWithFormat: @" players/%@ " , userId];
107-
108- return request;
109- }
110-
111-
112- @end
113-
11469@implementation OSRequestPostNotification
11570+ (instancetype )withAppId : (NSString *)appId withJson : (NSMutableDictionary *)json {
11671 let request = [OSRequestPostNotification new ];
@@ -126,113 +81,6 @@ + (instancetype)withAppId:(NSString *)appId withJson:(NSMutableDictionary *)json
12681}
12782@end
12883
129- @implementation OSRequestCreateDevice
130- + (instancetype _Nonnull)withAppId : (NSString * _Nonnull)appId withDeviceType : (NSNumber * _Nonnull)deviceType withEmail : (NSString * _Nullable)email withPlayerId : (NSString * _Nullable)playerId withEmailAuthHash : (NSString * _Nullable)emailAuthHash withExternalUserId : (NSString * _Nullable)externalUserId withExternalIdAuthToken : (NSString * _Nullable)externalIdAuthToken {
131- let request = [OSRequestCreateDevice new ];
132-
133- let params = [[NSMutableDictionary alloc ] initWithDictionary: @{
134- @" app_id" : appId,
135- @" device_type" : deviceType,
136- @" identifier" : email ?: [NSNull null ],
137- @" email_auth_hash" : emailAuthHash ?: [NSNull null ],
138- @" external_user_id_auth_hash" : externalIdAuthToken ?: [NSNull null ],
139- @" device_player_id" : playerId ?: [NSNull null ]
140- }];
141-
142- if (externalUserId) {
143- params[@" external_user_id" ] = externalUserId;
144- }
145- request.parameters = params;
146- request.method = POST;
147- request.path = @" players" ;
148-
149- return request;
150- }
151-
152- + (instancetype )withAppId : (NSString *)appId withDeviceType : (NSNumber *)deviceType withSMSNumber : (NSString *)smsNumber withPlayerId : (NSString *)playerId withSMSAuthHash : (NSString *)smsAuthHash withExternalUserId : (NSString * _Nullable)externalUserId withExternalIdAuthToken : (NSString *)externalIdAuthToken {
153- let request = [OSRequestCreateDevice new ];
154-
155- let params = [[NSMutableDictionary alloc ] initWithDictionary: @{
156- @" app_id" : appId,
157- @" device_type" : deviceType,
158- @" identifier" : smsNumber ?: [NSNull null ],
159- SMS_NUMBER_AUTH_HASH_KEY : smsAuthHash ?: [NSNull null ],
160- @" external_user_id_auth_hash" : externalIdAuthToken ?: [NSNull null ],
161- @" device_player_id" : playerId ?: [NSNull null ]
162- }];
163-
164- if (externalUserId) {
165- params[@" external_user_id" ] = externalUserId;
166- }
167-
168- request.parameters = params;
169- request.method = POST;
170- request.path = @" players" ;
171-
172- return request;
173- }
174- @end
175-
176- @implementation OSRequestLogoutEmail
177-
178- + (instancetype _Nonnull)withAppId : (NSString * _Nonnull)appId emailPlayerId : (NSString * _Nonnull)emailPlayerId devicePlayerId : (NSString * _Nonnull)devicePlayerId emailAuthHash : (NSString * _Nullable)emailAuthHash {
179- let request = [OSRequestLogoutEmail new ];
180-
181- request.parameters = @{
182- @" parent_player_id" : emailPlayerId ?: [NSNull null ],
183- @" email_auth_hash" : emailAuthHash ?: [NSNull null ],
184- @" app_id" : appId
185- };
186-
187- request.method = POST;
188- request.path = [NSString stringWithFormat: @" players/%@ /email_logout" , devicePlayerId];
189-
190- return request;
191- }
192-
193- @end
194-
195- @implementation OSRequestUpdateNotificationTypes
196- + (instancetype )withUserId : (NSString *)userId appId : (NSString *)appId notificationTypes : (NSNumber *)notificationTypes {
197- let request = [OSRequestUpdateNotificationTypes new ];
198-
199- request.parameters = @{@" app_id" : appId, @" notification_types" : notificationTypes};
200- request.method = PUT;
201- request.path = [NSString stringWithFormat: @" players/%@ " , userId];
202-
203- return request;
204- }
205- @end
206-
207- @implementation OSRequestSendPurchases
208- + (instancetype )withUserId : (NSString *)userId externalIdAuthToken : (NSString * _Nullable)externalIdAuthToken appId : (NSString *)appId withPurchases : (NSArray *)purchases {
209- let request = [OSRequestSendPurchases new ];
210-
211- request.parameters = @{@" app_id" : appId,
212- @" purchases" : purchases,
213- @" external_user_id_auth_hash" : externalIdAuthToken ?: [NSNull null ]
214- };
215- request.method = POST;
216- request.path = [NSString stringWithFormat: @" players/%@ /on_purchase" , userId];
217-
218- return request;
219- }
220-
221- + (instancetype )withUserId : (NSString *)userId emailAuthToken : (NSString *)emailAuthToken appId : (NSString *)appId withPurchases : (NSArray *)purchases {
222- let request = [OSRequestSendPurchases new ];
223-
224- request.parameters = @{
225- @" app_id" : appId,
226- @" purchases" : purchases,
227- @" email_auth_hash" : emailAuthToken ?: [NSNull null ]
228- };
229- request.method = POST;
230- request.path = [NSString stringWithFormat: @" players/%@ /on_purchase" , userId];
231-
232- return request;
233- }
234- @end
235-
23684@implementation OSRequestSubmitNotificationOpened
23785+ (instancetype )withUserId : (NSString *)userId appId : (NSString *)appId wasOpened : (BOOL )opened messageId : (NSString *)messageId withDeviceType : (nonnull NSNumber *)deviceType {
23886 let request = [OSRequestSubmitNotificationOpened new ];
@@ -245,117 +93,6 @@ + (instancetype)withUserId:(NSString *)userId appId:(NSString *)appId wasOpened:
24593}
24694@end
24795
248- @implementation OSRequestRegisterUser
249- + (instancetype _Nonnull)withData : (NSDictionary * _Nonnull)registrationData userId : (NSString * _Nullable)userId {
250-
251- let request = [OSRequestRegisterUser new ];
252-
253- request.parameters = registrationData;
254- request.method = POST;
255- request.path = userId ? [NSString stringWithFormat: @" players/%@ /on_session" , userId] : @" players" ;
256-
257- return request;
258- }
259- @end
260-
261- @implementation OSRequestSyncHashedEmail
262- + (instancetype )withUserId : (NSString *)userId appId : (NSString *)appId email : (NSString *)email networkType : (NSNumber *)netType {
263- let request = [OSRequestSyncHashedEmail new ];
264-
265- let lowerCase = [email lowercaseString ];
266- let md5Hash = [OneSignalCoreHelper hashUsingMD5: lowerCase];
267- let sha1Hash = [OneSignalCoreHelper hashUsingSha1: lowerCase];
268-
269- [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: [NSString stringWithFormat: @" %@ - MD5: %@ , SHA1:%@ " , lowerCase, md5Hash, sha1Hash]];
270-
271- request.parameters = @{@" app_id" : appId, @" em_m" : md5Hash, @" em_s" : sha1Hash, @" net_type" : netType};
272- request.method = PUT;
273- request.path = [NSString stringWithFormat: @" players/%@ " , userId];
274-
275- return request;
276- }
277- @end
278-
279- @implementation OSRequestUpdateLanguage
280-
281- + (instancetype _Nonnull)withUserId : (NSString * _Nonnull)userId
282- appId : (NSString * _Nonnull)appId
283- language : (NSString * _Nonnull)language
284- emailAuthToken : (NSString * _Nullable)emailAuthHash
285- externalIdAuthToken : (NSString * _Nullable)externalIdAuthToken {
286- return [self withUserId: userId appId: appId language: language authToken: emailAuthHash authTokenKey: @" email_auth_hash" externalIdAuthToken: externalIdAuthToken];
287- }
288-
289- + (instancetype )withUserId : (NSString *)userId
290- appId : (NSString *)appId
291- language : (NSString *)language
292- smsAuthToken : (NSString *)smsAuthToken
293- externalIdAuthToken : (NSString *)externalIdAuthToken {
294- return [self withUserId: userId appId: appId language: language authToken: smsAuthToken authTokenKey: @" sms_auth_hash" externalIdAuthToken: externalIdAuthToken];
295- }
296-
297- + (instancetype )withUserId : (NSString *)userId
298- appId : (NSString *)appId
299- language : (NSString *)language
300- authToken : (NSString *)authToken
301- authTokenKey : (NSString *)authTokenKey
302- externalIdAuthToken : (NSString *)externalIdAuthToken {
303- let request = [OSRequestUpdateLanguage new ];
304-
305- [OneSignalLog onesignalLog: ONE_S_LL_VERBOSE message: @" Attempting Update to Language" ];
306-
307- let params = [NSMutableDictionary new ];
308- params[@" app_id" ] = appId;
309- params[@" language" ] = language;
310-
311- if (authToken && authToken.length > 0 && authTokenKey)
312- params[authTokenKey] = authToken;
313-
314- if (externalIdAuthToken && externalIdAuthToken.length > 0 )
315- params[@" external_user_id_auth_hash" ] = externalIdAuthToken;
316-
317- request.parameters = params;
318- request.method = PUT;
319- request.path = [NSString stringWithFormat: @" players/%@ " , userId];
320-
321- return request;
322- }
323-
324- @end
325-
326- @implementation OSRequestUpdateExternalUserId
327- + (instancetype _Nonnull)withUserId : (NSString * _Nullable)externalId withUserIdHashToken : (NSString * _Nullable)hashToken withOneSignalUserId : (NSString *)userId appId : (NSString *)appId {
328- return [self withUserId: externalId withUserIdHashToken: hashToken withOneSignalUserId: userId withChannelHashToken: nil withHashTokenKey: nil appId: appId];
329- }
330-
331- + (instancetype )withUserId : (NSString *)externalId withUserIdHashToken : (NSString *)hashToken withOneSignalUserId : (NSString *)userId withEmailHashToken : (NSString *)emailHashToken appId : (NSString *)appId {
332- return [self withUserId: externalId withUserIdHashToken: hashToken withOneSignalUserId: userId withChannelHashToken: emailHashToken withHashTokenKey: @" email_auth_hash" appId: appId];
333- }
334-
335- + (instancetype )withUserId : (NSString *)externalId withUserIdHashToken : (NSString *)hashToken withOneSignalUserId : (NSString *)userId withSMSHashToken : (NSString *)smsHashToken appId : (NSString *)appId {
336- return [self withUserId: externalId withUserIdHashToken: hashToken withOneSignalUserId: userId withChannelHashToken: smsHashToken withHashTokenKey: @" sms_auth_hash" appId: appId];
337- }
338-
339- + (instancetype )withUserId : (NSString *)externalId withUserIdHashToken : (NSString *)hashToken withOneSignalUserId : (NSString *)userId withChannelHashToken : (NSString *)channelHashToken withHashTokenKey : (NSString *)hashTokenKey appId : (NSString *)appId {
340- NSString *msg = [NSString stringWithFormat: @" App ID: %@ , external ID: %@ " , appId, externalId];
341- [OneSignalLog onesignalLog: ONE_S_LL_DEBUG message: msg];
342-
343- let request = [OSRequestUpdateExternalUserId new ];
344- NSMutableDictionary *parametres = [NSMutableDictionary new ];
345- [parametres setObject: appId forKey: @" app_id" ];
346- [parametres setObject: externalId ?: @" " forKey: @" external_user_id" ];
347- if (hashToken && [hashToken length ] > 0 )
348- [parametres setObject: hashToken forKey: @" external_user_id_auth_hash" ];
349- if (channelHashToken && hashTokenKey)
350- [parametres setObject: channelHashToken forKey: hashTokenKey];
351- request.parameters = parametres;
352- request.method = PUT;
353- request.path = [NSString stringWithFormat: @" players/%@ " , userId];
354-
355- return request;
356- }
357- @end
358-
35996@implementation OSRequestTrackV1
36097NSString * const OS_USAGE_DATA = @" OS-Usage-Data" ;
36198+ (instancetype )trackUsageData : (NSString *)osUsageData appId : (NSString *)appId {
0 commit comments