Skip to content

Commit 9cdcae0

Browse files
authored
Merge pull request pubnub#34 from pubnub/develop
APNS2 and CreatePushPayload helper method
2 parents e0210b8 + fc4414f commit 9cdcae0

25 files changed

+1819
-75
lines changed

.pubnub.yml

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
---
22
changelog:
3+
-
4+
changes:
5+
-
6+
text: "APNS2"
7+
type: improvement
8+
-
9+
text: "Push payload helper class"
10+
type: improvement
11+
date: Dec 24, 19
12+
version: v4.7.0
313
-
414
changes:
515
-
@@ -359,6 +369,7 @@ features:
359369
others:
360370
- TELEMETRY
361371
- QUERY-PARAM
372+
- CREATE-PUSH-PAYLOAD
362373
presence:
363374
- PRESENCE-HERE-NOW
364375
- PRESENCE-WHERE-NOW
@@ -381,6 +392,10 @@ features:
381392
- PUSH-REMOVE-DEVICE-FROM-CHANNELS
382393
- PUSH-LIST-CHANNELS-FROM-DEVICE
383394
- PUSH-REMOVE-DEVICE
395+
- PUSH-TYPE-APNS
396+
- PUSH-TYPE-APNS2
397+
- PUSH-TYPE-FCM
398+
- PUSH-TYPE-MPNS
384399
storage:
385400
- STORAGE-REVERSE
386401
- STORAGE-INCLUDE-TIMETOKEN
@@ -452,4 +467,4 @@ supported-platforms:
452467
- "Ubuntu 12.04+, with Graphics card DX9 (shader model 3.0) or DX11 with feature level 9.3 capabilities; and CPU SSE2 instruction set support."
453468
- "Mac OS X 10.8+, with Graphics card DX9 (shader model 3.0) or DX11 with feature level 9.3 capabilities; and CPU SSE2 instruction set support."
454469
version: "PubNub Unity SDK"
455-
version: v4.6.0
470+
version: v4.7.0

PubNubUnity/Assets/PubNub/Builders/Push/AddChannelsToPushRequestBuilder.cs

+39-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ public class AddChannelsToPushRequestBuilder: PubNubNonSubBuilder<AddChannelsToP
1010
public AddChannelsToPushRequestBuilder(PubNubUnity pn):base(pn, PNOperationType.PNAddPushNotificationsOnChannelsOperation){
1111
}
1212
private string DeviceIDForPush{ get; set;}
13+
private string TopicForPush{ get; set;}
14+
private PNPushEnvironment EnvironmentForPush{ get; set;}
15+
public void Topic(string topic){
16+
TopicForPush = topic;
17+
}
18+
19+
public void Environment(PNPushEnvironment environment){
20+
EnvironmentForPush = environment;
21+
}
22+
1323
public void Channels(List<string> channelNames){
1424
ChannelsToUse = channelNames;
1525
}
@@ -45,6 +55,14 @@ public void Async(Action<PNPushAddChannelResult, PNStatus> callback)
4555
#endif
4656
PushType = PNPushType.GCM;
4757
}
58+
59+
if (PushType.Equals(PNPushType.APNS2) && (string.IsNullOrEmpty(TopicForPush))) {
60+
PNStatus pnStatus = base.CreateErrorResponseFromMessage(CommonText.APNS2TopicEmpty, null, PNStatusCategory.PNBadRequestCategory);
61+
Callback(null, pnStatus);
62+
63+
return;
64+
}
65+
4866
base.Async(this);
4967
}
5068
#endregion
@@ -53,13 +71,27 @@ protected override void RunWebRequest(QueueManager qm){
5371
RequestState requestState = new RequestState ();
5472
requestState.OperationType = OperationType;
5573

56-
Uri request = BuildRequests.BuildRegisterDevicePushRequest(
57-
string.Join(",", ChannelsToUse.ToArray()),
58-
PushType,
59-
DeviceIDForPush,
60-
this.PubNubInstance,
61-
this.QueryParams
62-
);
74+
Uri request;
75+
if(PushType.Equals(PNPushType.APNS2)){
76+
request = BuildRequests.BuildRegisterDevicePushRequest(
77+
string.Join(",", ChannelsToUse.ToArray()),
78+
PushType,
79+
DeviceIDForPush,
80+
this.PubNubInstance,
81+
this.QueryParams,
82+
TopicForPush,
83+
EnvironmentForPush
84+
);
85+
} else {
86+
request = BuildRequests.BuildRegisterDevicePushRequest(
87+
string.Join(",", ChannelsToUse.ToArray()),
88+
PushType,
89+
DeviceIDForPush,
90+
this.PubNubInstance,
91+
this.QueryParams
92+
);
93+
}
94+
6395
base.RunWebRequest(qm, request, requestState, this.PubNubInstance.PNConfig.NonSubscribeTimeout, 0, this);
6496
}
6597

PubNubUnity/Assets/PubNub/Builders/Push/ListPushProvisionsRequestBuilder.cs

+34-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ public class ListPushProvisionsRequestBuilder: PubNubNonSubBuilder<ListPushProvi
99
{
1010
public ListPushProvisionsRequestBuilder(PubNubUnity pn):base(pn, PNOperationType.PNPushNotificationEnabledChannelsOperation){
1111
}
12-
12+
private string TopicForPush{ get; set;}
13+
private PNPushEnvironment EnvironmentForPush{ get; set;}
14+
public void Topic(string topic){
15+
TopicForPush = topic;
16+
}
17+
public void Environment(PNPushEnvironment environment){
18+
EnvironmentForPush = environment;
19+
}
1320
private string DeviceIDForPush{ get; set;}
1421

1522
public void DeviceId(string deviceIdToPush){
@@ -36,6 +43,14 @@ public void Async(Action<PNPushListProvisionsResult, PNStatus> callback)
3643
#endif
3744
PushType = PNPushType.GCM;
3845
}
46+
47+
if (PushType.Equals(PNPushType.APNS2) && (string.IsNullOrEmpty(TopicForPush))) {
48+
PNStatus pnStatus = base.CreateErrorResponseFromMessage(CommonText.APNS2TopicEmpty, null, PNStatusCategory.PNBadRequestCategory);
49+
Callback(null, pnStatus);
50+
51+
return;
52+
}
53+
3954
base.Async(this);
4055
}
4156
#endregion
@@ -44,12 +59,24 @@ protected override void RunWebRequest(QueueManager qm){
4459
RequestState requestState = new RequestState ();
4560
requestState.OperationType = OperationType;
4661

47-
Uri request = BuildRequests.BuildGetChannelsPushRequest(
48-
PushType,
49-
DeviceIDForPush,
50-
this.PubNubInstance,
51-
this.QueryParams
52-
);
62+
Uri request;
63+
if(PushType.Equals(PNPushType.APNS2)){
64+
request = BuildRequests.BuildGetChannelsPushRequest(
65+
PushType,
66+
DeviceIDForPush,
67+
this.PubNubInstance,
68+
this.QueryParams,
69+
TopicForPush,
70+
EnvironmentForPush
71+
);
72+
} else {
73+
request = BuildRequests.BuildGetChannelsPushRequest(
74+
PushType,
75+
DeviceIDForPush,
76+
this.PubNubInstance,
77+
this.QueryParams
78+
);
79+
}
5380

5481
base.RunWebRequest(qm, request, requestState, this.PubNubInstance.PNConfig.NonSubscribeTimeout, 0, this);
5582
}

PubNubUnity/Assets/PubNub/Builders/Push/RemoveAllPushChannelsForDeviceRequestBuilder.cs

+34-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ public class RemoveAllPushChannelsForDeviceRequestBuilder: PubNubNonSubBuilder<R
99
{
1010
public RemoveAllPushChannelsForDeviceRequestBuilder(PubNubUnity pn):base(pn, PNOperationType.PNRemoveAllPushNotificationsOperation){
1111
}
12+
private string TopicForPush{ get; set;}
13+
private PNPushEnvironment EnvironmentForPush{ get; set;}
14+
public void Topic(string topic){
15+
TopicForPush = topic;
16+
}
1217

18+
public void Environment(PNPushEnvironment environment){
19+
EnvironmentForPush = environment;
20+
}
1321
private string DeviceIDForPush{ get; set;}
1422

1523
public void DeviceId(string deviceIdForPush){
@@ -36,6 +44,14 @@ public void Async(Action<PNPushRemoveAllChannelsResult, PNStatus> callback)
3644
#endif
3745
PushType = PNPushType.GCM;
3846
}
47+
48+
if (PushType.Equals(PNPushType.APNS2) && (string.IsNullOrEmpty(TopicForPush))) {
49+
PNStatus pnStatus = base.CreateErrorResponseFromMessage(CommonText.APNS2TopicEmpty, null, PNStatusCategory.PNBadRequestCategory);
50+
Callback(null, pnStatus);
51+
52+
return;
53+
}
54+
3955
base.Async(this);
4056
}
4157
#endregion
@@ -44,12 +60,24 @@ protected override void RunWebRequest(QueueManager qm){
4460
RequestState requestState = new RequestState ();
4561
requestState.OperationType = OperationType;
4662

47-
Uri request = BuildRequests.BuildRemoveAllDevicePushRequest(
48-
PushType,
49-
DeviceIDForPush,
50-
this.PubNubInstance,
51-
this.QueryParams
52-
);
63+
Uri request;
64+
if(PushType.Equals(PNPushType.APNS2)){
65+
request = BuildRequests.BuildRemoveAllDevicePushRequest(
66+
PushType,
67+
DeviceIDForPush,
68+
this.PubNubInstance,
69+
this.QueryParams,
70+
TopicForPush,
71+
EnvironmentForPush
72+
);
73+
} else {
74+
request = BuildRequests.BuildRemoveAllDevicePushRequest(
75+
PushType,
76+
DeviceIDForPush,
77+
this.PubNubInstance,
78+
this.QueryParams
79+
);
80+
}
5381

5482
base.RunWebRequest(qm, request, requestState, this.PubNubInstance.PNConfig.NonSubscribeTimeout, 0, this);
5583
}

PubNubUnity/Assets/PubNub/Builders/Push/RemoveChannelsFromPushRequestBuilder.cs

+35-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ public class RemoveChannelsFromPushRequestBuilder: PubNubNonSubBuilder<RemoveCha
1010
public RemoveChannelsFromPushRequestBuilder(PubNubUnity pn):base(pn, PNOperationType.PNRemovePushNotificationsFromChannelsOperation){
1111

1212
}
13+
private string TopicForPush{ get; set;}
14+
private PNPushEnvironment EnvironmentForPush{ get; set;}
15+
public void Topic(string topic){
16+
TopicForPush = topic;
17+
}
1318

19+
public void Environment(PNPushEnvironment environment){
20+
EnvironmentForPush = environment;
21+
}
1422
private string DeviceIDForPush{ get; set;}
1523
public void Channels(List<string> channelNames){
1624
ChannelsToUse = channelNames;
@@ -41,6 +49,13 @@ public void Async(Action<PNPushRemoveChannelResult, PNStatus> callback)
4149
return;
4250
}
4351

52+
if (PushType.Equals(PNPushType.APNS2) && (string.IsNullOrEmpty(TopicForPush))) {
53+
PNStatus pnStatus = base.CreateErrorResponseFromMessage(CommonText.APNS2TopicEmpty, null, PNStatusCategory.PNBadRequestCategory);
54+
Callback(null, pnStatus);
55+
56+
return;
57+
}
58+
4459
base.Async(this);
4560
}
4661
#endregion
@@ -49,13 +64,26 @@ protected override void RunWebRequest(QueueManager qm){
4964
RequestState requestState = new RequestState ();
5065
requestState.OperationType = OperationType;
5166

52-
Uri request = BuildRequests.BuildRemoveChannelPushRequest(
53-
string.Join(",", ChannelsToUse.ToArray()),
54-
PushType,
55-
DeviceIDForPush,
56-
this.PubNubInstance,
57-
this.QueryParams
58-
);
67+
Uri request;
68+
if(PushType.Equals(PNPushType.APNS2)){
69+
request = BuildRequests.BuildRemoveChannelPushRequest(
70+
string.Join(",", ChannelsToUse.ToArray()),
71+
PushType,
72+
DeviceIDForPush,
73+
this.PubNubInstance,
74+
this.QueryParams,
75+
TopicForPush,
76+
EnvironmentForPush
77+
);
78+
} else {
79+
request = BuildRequests.BuildRemoveChannelPushRequest(
80+
string.Join(",", ChannelsToUse.ToArray()),
81+
PushType,
82+
DeviceIDForPush,
83+
this.PubNubInstance,
84+
this.QueryParams
85+
);
86+
}
5987

6088
base.RunWebRequest(qm, request, requestState, this.PubNubInstance.PNConfig.NonSubscribeTimeout, 0, this);
6189
}

0 commit comments

Comments
 (0)