Skip to content

Commit 2a38667

Browse files
authored
Merge pull request #25 from pubnub/develop
Signals IncludeMeta in Fetch and History
2 parents 21d9106 + ffd4b1e commit 2a38667

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1460
-389
lines changed

.pubnub.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
---
22
changelog:
3+
-
4+
changes:
5+
-
6+
text: "Signals"
7+
type: improvement
8+
-
9+
text: "IncludeMeta in History and Fetch"
10+
type: improvement
11+
date: Oct 10, 19
12+
version: v4.3.0
313
-
414
changes:
515
-
@@ -350,6 +360,10 @@ features:
350360
- STORAGE-START-END
351361
- STORAGE-COUNT
352362
- STORAGE-DELETE-MESSAGES
363+
- STORAGE-FETCH-MESSAGES
364+
- STORAGE-MESSAGE-COUNT
365+
- STORAGE-HISTORY-WITH-META
366+
- STORAGE-FETCH-WITH-META
353367
subscribe:
354368
- SUBSCRIBE-CHANNELS
355369
- SUBSCRIBE-CHANNEL-GROUPS
@@ -360,9 +374,13 @@ features:
360374
- SUBSCRIBE-FILTER-EXPRESSION
361375
- SUBSCRIBE-PUBSUB-V2
362376
- SUBSCRIBE-PUBLISHER-UUID
363-
- REQUEST-MESSAGE-COUNT-EXCEEDED
377+
- SUBSCRIBE-SIGNAL-LISTENER
364378
time:
365379
- TIME-TIME
380+
signal:
381+
- SIGNAL-SEND
382+
notify:
383+
- REQUEST-MESSAGE-COUNT-EXCEEDED
366384
name: unity
367385
schema: 1
368386
scm: github.com/pubnub/unity
@@ -383,4 +401,4 @@ supported-platforms:
383401
- "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."
384402
- "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."
385403
version: "PubNub Unity SDK"
386-
version: v4.2.1
404+
version: v4.3.0

PubNubUnity/Assets/PubNub/Builders/History/FetchMessagesRequestBuilder.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ private ushort HistoryCount {
2929
}
3030
}
3131
}
32+
33+
private bool IncludeMetaInHistory;
3234

3335
private bool ReverseHistory;
3436
private bool IncludeTimetokenInHistory;
@@ -61,6 +63,11 @@ public FetchMessagesRequestBuilder Count(ushort historyCount){
6163
HistoryCount = historyCount;
6264
return this;
6365
}
66+
67+
public FetchMessagesRequestBuilder IncludeMeta(bool includeMeta){
68+
IncludeMetaInHistory = includeMeta;
69+
return this;
70+
}
6471

6572
#region IPubNubBuilder implementation
6673

@@ -96,7 +103,8 @@ protected override void RunWebRequest(QueueManager qm){
96103
this.ReverseHistory,
97104
this.IncludeTimetokenInHistory,
98105
this.PubNubInstance,
99-
this.QueryParams
106+
this.QueryParams,
107+
this.IncludeMetaInHistory
100108
);
101109
base.RunWebRequest(qm, request, requestState, this.PubNubInstance.PNConfig.NonSubscribeTimeout, 0, this);
102110

@@ -135,6 +143,7 @@ protected override void CreatePubNubResponse(object deSerializedResult, RequestS
135143
pnFetchMessagesResult = null;
136144
pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory);
137145
}
146+
138147
Callback(pnFetchMessagesResult, pnStatus);
139148
}
140149

@@ -164,6 +173,14 @@ protected bool CreateFetchMessagesResult(object objChannelsDict, out Dictionary<
164173
object objPayload;
165174
messageDataDict.TryGetValue("message", out objPayload);
166175

176+
object meta;
177+
178+
if(messageDataDict.TryGetValue("meta", out meta)){
179+
#if (ENABLE_PUBNUB_LOGGING)
180+
this.PubNubInstance.PNLog.WriteToLog(string.Format ("CreateFetchMessagesResult: meta {0}.", meta.ToString()), PNLoggingMethod.LevelInfo);
181+
#endif
182+
}
183+
167184
object objTimetoken;
168185
messageDataDict.TryGetValue("timetoken", out objTimetoken);
169186
long timetoken;
@@ -183,10 +200,14 @@ protected bool CreateFetchMessagesResult(object objChannelsDict, out Dictionary<
183200
objPayload,
184201
timetoken,
185202
timetoken,
186-
null,
203+
meta,
187204
""
188205
);
189206
lstMessageResult.Add(pnMessageResult);
207+
#if (ENABLE_PUBNUB_LOGGING)
208+
this.PubNubInstance.PNLog.WriteToLog(string.Format ("CreateFetchMessagesResult: pnMessageResult {0}.", pnMessageResult.ToString()), PNLoggingMethod.LevelInfo);
209+
#endif
210+
190211
}
191212
}
192213
channelsResult.Add(channelName, lstMessageResult);

PubNubUnity/Assets/PubNub/Builders/History/HistoryRequestBuilder.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ private ushort HistoryCount {
2727
}
2828
}
2929

30+
private bool IncludeMetaInHistory;
3031
private bool ReverseHistory;
3132
private bool IncludeTimetokenInHistory;
3233
public HistoryRequestBuilder(PubNubUnity pn): base(pn, PNOperationType.PNHistoryOperation){
@@ -62,6 +63,12 @@ public HistoryRequestBuilder Count(ushort historyCount){
6263
HistoryCount = historyCount;
6364
return this;
6465
}
66+
public HistoryRequestBuilder IncludeMeta(bool includeMeta){
67+
IncludeMetaInHistory = includeMeta;
68+
return this;
69+
}
70+
71+
6572

6673
#region IPubNubBuilder implementation
6774

@@ -96,7 +103,8 @@ protected override void RunWebRequest(QueueManager qm){
96103
this.ReverseHistory,
97104
this.IncludeTimetokenInHistory,
98105
this.PubNubInstance,
99-
this.QueryParams
106+
this.QueryParams,
107+
this.IncludeMetaInHistory
100108
);
101109
base.RunWebRequest(qm, request, requestState, this.PubNubInstance.PNConfig.NonSubscribeTimeout, 0, this);
102110
}
@@ -164,12 +172,20 @@ private void ExtractMessageWithTimetokens( object element, string cipherKey, out
164172
#endif
165173

166174
object t;
167-
historyMessage.TryGetValue("timetoken", out t);
168-
pnHistoryItemResult.Timetoken = Utility.ValidateTimetoken(t.ToString(), false);
169-
#if (ENABLE_PUBNUB_LOGGING)
170-
this.PubNubInstance.PNLog.WriteToLog(string.Format ("ExtractMessageWithTimetokens: t {0}", t), PNLoggingMethod.LevelInfo);
171-
#endif
175+
if(historyMessage.TryGetValue("timetoken", out t)){
176+
pnHistoryItemResult.Timetoken = Utility.ValidateTimetoken(t.ToString(), false);
177+
#if (ENABLE_PUBNUB_LOGGING)
178+
this.PubNubInstance.PNLog.WriteToLog(string.Format ("ExtractMessageWithTimetokens: t {0}", t), PNLoggingMethod.LevelInfo);
179+
#endif
180+
}
172181

182+
object m;
183+
if(historyMessage.TryGetValue("meta", out m)){
184+
pnHistoryItemResult.Meta = m;
185+
#if (ENABLE_PUBNUB_LOGGING)
186+
this.PubNubInstance.PNLog.WriteToLog(string.Format ("ExtractMessageWithTimetokens: m {0}", m), PNLoggingMethod.LevelInfo);
187+
#endif
188+
}
173189
}
174190

175191
private void ExtractMessage( object element, string cipherKey, out PNHistoryItemResult pnHistoryItemResult){
@@ -202,7 +218,7 @@ private bool ExtractMessages(object[] historyResponseArray, ref PNHistoryResult
202218
#endif
203219
PNHistoryItemResult pnHistoryItemResult;
204220

205-
if(this.IncludeTimetokenInHistory){
221+
if((this.IncludeTimetokenInHistory) || (this.IncludeMetaInHistory)){
206222
ExtractMessageWithTimetokens(element, this.PubNubInstance.PNConfig.CipherKey, out pnHistoryItemResult);
207223
} else {
208224
ExtractMessage(element, this.PubNubInstance.PNConfig.CipherKey, out pnHistoryItemResult);
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System;
2+
using System.Linq;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
6+
namespace PubNubAPI
7+
{
8+
public class SignalRequestBuilder: PubNubNonSubBuilder<SignalRequestBuilder, PNSignalResult>, IPubNubNonSubscribeBuilder<SignalRequestBuilder, PNSignalResult>
9+
{
10+
private object SignalMessage { get; set;}
11+
private string SignalChannel { get; set;}
12+
13+
public SignalRequestBuilder(PubNubUnity pn): base(pn, PNOperationType.PNSignalOperation){
14+
}
15+
16+
#region IPubNubBuilder implementation
17+
public void Async(Action<PNSignalResult, PNStatus> callback)
18+
{
19+
this.Callback = callback;
20+
if(string.IsNullOrEmpty(this.PubNubInstance.PNConfig.PublishKey)){
21+
PNStatus pnStatus = base.CreateErrorResponseFromMessage("Publish Key is empty", null, PNStatusCategory.PNBadRequestCategory);
22+
Callback(null, pnStatus);
23+
return;
24+
}
25+
if(string.IsNullOrEmpty(this.SignalChannel)){
26+
PNStatus pnStatus = base.CreateErrorResponseFromMessage("Channel is empty", null, PNStatusCategory.PNBadRequestCategory);
27+
Callback(null, pnStatus);
28+
return;
29+
}
30+
if(this.SignalMessage == null){
31+
PNStatus pnStatus = base.CreateErrorResponseFromMessage("Message is empty", null, PNStatusCategory.PNBadRequestCategory);
32+
Callback(null, pnStatus);
33+
return;
34+
}
35+
36+
base.Async(this);
37+
}
38+
#endregion
39+
40+
public SignalRequestBuilder Message(object messageToPublish){
41+
SignalMessage = messageToPublish;
42+
return this;
43+
}
44+
45+
public SignalRequestBuilder Channel(string channelName){
46+
SignalChannel = channelName;
47+
return this;
48+
}
49+
50+
protected override void RunWebRequest(QueueManager qm){
51+
RequestState requestState = new RequestState ();
52+
requestState.OperationType = OperationType;
53+
54+
string jsonMessage = Helpers.JsonEncodePublishMsg (SignalMessage, "", this.PubNubInstance.JsonLibrary, this.PubNubInstance.PNLog);
55+
Uri request = BuildRequests.BuildSignalRequest(
56+
this.SignalChannel,
57+
jsonMessage,
58+
this.PubNubInstance,
59+
this.QueryParams
60+
);
61+
base.RunWebRequest(qm, request, requestState, this.PubNubInstance.PNConfig.NonSubscribeTimeout, 0, this);
62+
}
63+
64+
protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState){
65+
object[] c = deSerializedResult as object[];
66+
PNSignalResult pnSignalResult = new PNSignalResult();
67+
PNStatus pnStatus = new PNStatus();
68+
if (c != null) {
69+
string status = "";
70+
string statusCode = "0";
71+
if(c.Length > 0){
72+
statusCode = c[0].ToString();
73+
}
74+
if(c.Length > 1){
75+
status = c[1].ToString();
76+
}
77+
if(statusCode.Equals("0") || (!status.ToLowerInvariant().Equals("sent"))){
78+
pnSignalResult = null;
79+
string message = "";
80+
if(c.Length > 2){
81+
message = c[2].ToString();
82+
}
83+
pnStatus = base.CreateErrorResponseFromMessage(string.Format("Signal Failure: {0}", message), requestState, PNStatusCategory.PNBadRequestCategory);
84+
} else {
85+
if(c.Length > 2){
86+
pnSignalResult.Timetoken = Utility.ValidateTimetoken(c[2].ToString(), false);
87+
} else {
88+
pnSignalResult.Timetoken = 0;
89+
}
90+
}
91+
} else {
92+
pnSignalResult = null;
93+
pnStatus = base.CreateErrorResponseFromMessage("Response is null", requestState, PNStatusCategory.PNMalformedResponseCategory);
94+
}
95+
Callback(pnSignalResult, pnStatus);
96+
97+
}
98+
99+
}
100+
}

PubNubUnity/Assets/PubNub/Builders/PubSub/SignalRequestBuilder.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PubNubUnity/Assets/PubNub/Editor/FetchMessagesBuildRequestsTests.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,22 @@ public void TestBuildFetchMessagesRequest ()
1919
TestFetchMessagesBuildRequestCommon (false, false, false, "authKey", startTime, endTime, 25, false);
2020
}
2121

22+
[Test]
23+
public void TestBuildFetchMessagesRequestWithMeta ()
24+
{
25+
long startTime = 14498416434364941;
26+
long endTime = 14498416799269095;
27+
28+
TestFetchMessagesBuildRequestCommon (false, false, false, "authKey", startTime, endTime, 25, false, true);
29+
}
30+
2231
public void TestFetchMessagesBuildRequestCommon(bool ssl, bool reverse, bool includeTimetoken,
2332
string authKey, long startTime, long endTime, int count, bool sendQueryParams){
33+
TestFetchMessagesBuildRequestCommon (false, false, false, "authKey", startTime, endTime, 25, false, false);
34+
}
35+
36+
public void TestFetchMessagesBuildRequestCommon(bool ssl, bool reverse, bool includeTimetoken,
37+
string authKey, long startTime, long endTime, int count, bool sendQueryParams, bool withMeta){
2438
string[] channels = new[] {"history_channel", "history_channel2"};
2539
string uuid = "customuuid";
2640
Dictionary<string,string> queryParams = new Dictionary<string, string>();
@@ -65,19 +79,19 @@ public void TestFetchMessagesBuildRequestCommon(bool ssl, bool reverse, bool inc
6579
}
6680

6781
Uri uri = BuildRequests.BuildFetchRequest (channels, startTime, endTime, (uint)count, reverse,
68-
includeTimetoken, pnUnity, queryParams
82+
includeTimetoken, pnUnity, queryParams, withMeta
6983
);
7084

7185
if (count == -1) {
7286
count = 100;
7387
}
7488
//http://ps.pndsn.com/v3/history/sub-key/demo/channel/history_channel,history_channel2?max=90&start=14498416434364941&end=14498416799269095&auth=authKey&uuid=customuuid&pnsdk=PubNub-CSharp-UnityOSX%2F4.1.1
75-
string expected = string.Format ("http{0}://{1}/v3/history/sub-key/{2}/channel/{3}?max={4}{5}{6}{7}{8}{9}&uuid={10}&pnsdk={11}{12}",
89+
string expected = string.Format ("http{0}://{1}/v3/history/sub-key/{2}/channel/{3}?max={4}{5}{6}{7}{8}{13}{9}&uuid={10}&pnsdk={11}{12}",
7690
ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, string.Join(",", channels), count,
7791
includeTimetoken?"&include_token=true":"", reverse?"&reverse=true":"",
7892
startTimeString, endTimeString, authKeyString, uuid,
7993
Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNHistoryOperation, false, true),
80-
queryParamString
94+
queryParamString, withMeta?"&include_meta=true":""
8195
);
8296
string received = uri.OriginalString;
8397
EditorCommon.LogAndCompare (expected, received);

0 commit comments

Comments
 (0)