@@ -268,36 +268,61 @@ def write(self, string):
268
268
269
269
270
270
class PayloadAlert (object ):
271
- def __init__ (self , body = None , title = None , subtitle = None , action_loc_key = None , loc_key = None ,
272
- loc_args = None , launch_image = None ):
273
- super (PayloadAlert , self ).__init__ ()
274
-
271
+ """
272
+ Payload for APNS alert.
273
+ https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html
274
+ """
275
+ def __init__ (self ,
276
+ body = None ,
277
+ title = None ,
278
+ subtitle = None ,
279
+ action_loc_key = None ,
280
+ loc_key = None ,
281
+ loc_args = None ,
282
+ launch_image = None ,
283
+ title_loc_key = None ,
284
+ title_loc_args = None ):
285
+
275
286
self .body = body
276
287
self .title = title
277
288
self .subtitle = subtitle
278
289
self .action_loc_key = action_loc_key
279
290
self .loc_key = loc_key
280
291
self .loc_args = loc_args
281
292
self .launch_image = launch_image
293
+ self .title_loc_key = title_loc_key
294
+ self .title_loc_args = title_loc_args
295
+
296
+ self ._dict = {
297
+ 'body' : self .body ,
298
+ 'title' : self .title ,
299
+ 'subtitle' : self .subtitle ,
300
+ 'action-loc-key' : self .action_loc_key ,
301
+ 'loc-key' : self .loc_key ,
302
+ 'loc-args' : self .loc_args ,
303
+ 'launch-image' : self .launch_image ,
304
+ 'title-loc-key' : self .title_loc_key ,
305
+ 'title-loc-args' : self .title_loc_args
306
+ }
282
307
283
308
def dict (self ):
284
- d = {}
285
-
286
- if self . body :
287
- d [ 'body' ] = self .body
288
- if self . title :
289
- d [ 'title' ] = self . title
290
- if self . subtitle :
291
- d [ 'subtitle' ] = self . subtitle
292
- if self . action_loc_key :
293
- d [ 'action-loc-key' ] = self . action_loc_key
294
- if self . loc_key :
295
- d [ 'loc-key' ] = self . loc_key
296
- if self .loc_args :
297
- d [ 'loc-args' ] = self . loc_args
298
- if self . launch_image :
299
- d [ 'launch-image' ] = self .launch_image
300
- return d
309
+ cleared = {
310
+ key : value
311
+ for ( key , value )
312
+ in self ._dict . items ()
313
+ if value is not None
314
+ }
315
+ return cleared
316
+
317
+ def __eq__ ( self , other ) :
318
+ return self . dict () == other . dict ()
319
+
320
+ def __ne__ ( self , other ):
321
+ return self .dict () != other . dict ()
322
+
323
+ def __repr__ ( self ) :
324
+ return 'PayloadAlert(**{})' . format ( self .dict ())
325
+
301
326
302
327
class PayloadTooLargeError (Exception ):
303
328
def __init__ (self , payload_size ):
0 commit comments