11import six
22
33from 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
56from pubnub .exceptions import PubNubException
6- from pubnub .enums import HttpMethod , PNOperationType
7+ from pubnub .enums import HttpMethod , PNOperationType , PNPushType , PNPushEnvironment
78from pubnub .models .consumer .push import PNPushRemoveChannelResult
89from pubnub import utils
910
1011
1112class RemoveChannelsFromPush (Endpoint ):
1213 # v1/push/sub-key/{subKey}/devices/{pushToken}
1314 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"
1417
1518 def __init__ (self , pubnub ):
1619 Endpoint .__init__ (self , pubnub )
1720 self ._channels = None
1821 self ._device_id = None
1922 self ._push_type = None
23+ self ._topic = None
24+ self ._environment = None
2025
2126 def channels (self , channels ):
2227 self ._channels = channels
@@ -30,14 +35,35 @@ def push_type(self, push_type):
3035 self ._push_type = push_type
3136 return self
3237
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+
3346 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
3557
3658 return params
3759
3860 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 )
4167
4268 def http_method (self ):
4369 return HttpMethod .GET
@@ -54,6 +80,10 @@ def validate_params(self):
5480 if self ._push_type is None :
5581 raise PubNubException (pn_error = PNERROR_PUSH_TYPE_MISSING )
5682
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+
5787 def create_response (self , envelope ):
5888 return PNPushRemoveChannelResult ()
5989
0 commit comments