1
1
import six
2
2
3
3
from pubnub .endpoints .endpoint import Endpoint
4
- from pubnub .errors import PNERR_CHANNEL_MISSING , PNERR_PUSH_DEVICE_MISSING , PNERROR_PUSH_TYPE_MISSING
4
+ from pubnub .errors import PNERR_CHANNEL_MISSING , PNERR_PUSH_DEVICE_MISSING , PNERROR_PUSH_TYPE_MISSING , \
5
+ PNERR_PUSH_TOPIC_MISSING
5
6
from pubnub .exceptions import PubNubException
6
- from pubnub .enums import HttpMethod , PNOperationType
7
+ from pubnub .enums import HttpMethod , PNOperationType , PNPushType , PNPushEnvironment
7
8
from pubnub .models .consumer .push import PNPushRemoveChannelResult
8
9
from pubnub import utils
9
10
10
11
11
12
class RemoveChannelsFromPush (Endpoint ):
12
13
# v1/push/sub-key/{subKey}/devices/{pushToken}
13
14
REMOVE_PATH = "/v1/push/sub-key/%s/devices/%s"
15
+ # v2/push/sub-key/{subKey}/devices-apns2/{deviceApns2}
16
+ REMOVE_PATH_APNS2 = "/v2/push/sub-key/%s/devices-apns2/%s"
14
17
15
18
def __init__ (self , pubnub ):
16
19
Endpoint .__init__ (self , pubnub )
17
20
self ._channels = None
18
21
self ._device_id = None
19
22
self ._push_type = None
23
+ self ._topic = None
24
+ self ._environment = None
20
25
21
26
def channels (self , channels ):
22
27
self ._channels = channels
@@ -30,14 +35,35 @@ def push_type(self, push_type):
30
35
self ._push_type = push_type
31
36
return self
32
37
38
+ def topic (self , topic ):
39
+ self ._topic = topic
40
+ return self
41
+
42
+ def environment (self , environment ):
43
+ self ._environment = environment
44
+ return self
45
+
33
46
def custom_params (self ):
34
- params = {'remove' : utils .join_items (self ._channels ), 'type' : utils .push_type_to_string (self ._push_type )}
47
+ params = {'remove' : utils .join_items (self ._channels )}
48
+
49
+ if self ._push_type != PNPushType .APNS2 :
50
+ params ['type' ] = utils .push_type_to_string (self ._push_type )
51
+ else :
52
+ if self ._environment is None :
53
+ self ._environment = PNPushEnvironment .DEVELOPMENT
54
+
55
+ params ['environment' ] = self ._environment
56
+ params ['topic' ] = self ._topic
35
57
36
58
return params
37
59
38
60
def build_path (self ):
39
- return RemoveChannelsFromPush .REMOVE_PATH % (
40
- self .pubnub .config .subscribe_key , self ._device_id )
61
+ if self ._push_type != PNPushType .APNS2 :
62
+ return RemoveChannelsFromPush .REMOVE_PATH % (
63
+ self .pubnub .config .subscribe_key , self ._device_id )
64
+ else :
65
+ return RemoveChannelsFromPush .REMOVE_PATH_APNS2 % (
66
+ self .pubnub .config .subscribe_key , self ._device_id )
41
67
42
68
def http_method (self ):
43
69
return HttpMethod .GET
@@ -54,6 +80,10 @@ def validate_params(self):
54
80
if self ._push_type is None :
55
81
raise PubNubException (pn_error = PNERROR_PUSH_TYPE_MISSING )
56
82
83
+ if self ._push_type == PNPushType .APNS2 :
84
+ if not isinstance (self ._topic , six .string_types ) or len (self ._topic ) == 0 :
85
+ raise PubNubException (pn_error = PNERR_PUSH_TOPIC_MISSING )
86
+
57
87
def create_response (self , envelope ):
58
88
return PNPushRemoveChannelResult ()
59
89
0 commit comments