public void TestBuildSubscribeRequestCommon(string[] channels, string[] channelGroups,
                                                    object timetoken, string userState,
                                                    bool ssl, string authKey, string filterExpr, string region, int presenceHeartbeat, bool sendQueryParams)
        {
            string uuid = "customuuid";
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin       = EditorCommon.Origin;
            pnConfiguration.SubscribeKey = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey   = EditorCommon.PublishKey;
            pnConfiguration.Secure       = ssl;
            pnConfiguration.CipherKey    = "enigma";
            pnConfiguration.LogVerbosity = PNLogVerbosity.BODY;
            if (presenceHeartbeat != 0)
            {
                pnConfiguration.PresenceTimeout = presenceHeartbeat;
            }
            pnConfiguration.AuthKey = authKey;
            pnConfiguration.UUID    = uuid;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            string tt = "0";

            if (timetoken == null)
            {
                tt = "0";
            }
            else
            {
                tt = timetoken.ToString();
            }
            if (string.IsNullOrEmpty(tt))
            {
                tt = "0";
            }
            string ttStr = string.Format("&tt={0}", tt);

            string cgStr = "";
            string cg    = "";

            if (channelGroups != null)
            {
                cg    = string.Join(",", channelGroups);
                cgStr = string.Format("&channel-group={0}", Utility.EncodeUricomponent(cg, PNOperationType.PNSubscribeOperation, true, false));
            }

            string phb = "";
            // if (presenceHeartbeat != 0) {
            //     phb = string.Format("&heartbeat={0}", presenceHeartbeat);
            // }

            string chStr = ",";
            string ch    = "";

            if (channels != null)
            {
                ch    = string.Join(",", channels);
                chStr = ch;
            }

            Uri uri = BuildRequests.BuildSubscribeRequest(ch, cg, tt, userState, region, filterExpr, pnUnity, queryParams);

            string filterExpression = "";

            if (!string.IsNullOrEmpty(filterExpr))
            {
                filterExpression = string.Format("&filter-expr=({0})", Utility.EncodeUricomponent(filterExpr, PNOperationType.PNSubscribeOperation, false, false));
            }

            string reg = "";

            if (!string.IsNullOrEmpty(region))
            {
                reg = string.Format("&tr=({0})", Utility.EncodeUricomponent(region, PNOperationType.PNSubscribeOperation, false, false));
            }

            //http://ps.pndsn.com/v2/subscribe/demo-36/test/0?uuid=customuuid&tt=21221&state={"k":"v"}&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            //http://ps.pndsn.com/v2/subscribe/demo-36/test/0?uuid=customuuid&tt=0&filter-expr=(region%20%3D%3D%20%22east%22)&channel-group=cg&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX/3.7
            string expected = string.Format("http{0}://{1}/v2/subscribe/{2}/{3}/0?uuid={5}{4}{10}{11}{6}{7}{12}{8}{13}{15}&pnsdk={9}{14}",
                                            ssl?"s":"", pnConfiguration.Origin, pnConfiguration.SubscribeKey,
                                            chStr,
                                            ttStr,
                                            uuid,
                                            (userState == "")?"":"&state=",
                                            Utility.EncodeUricomponent(userState, PNOperationType.PNSubscribeOperation, false, false),
                                            authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNSubscribeOperation, false, false),
                                            filterExpression,
                                            reg,
                                            cgStr,
                                            phb,
                                            queryParamString,
                                            (pnConfiguration.PresenceTimeout > 0)?string.Format("&heartbeat={0}", pnConfiguration.PresenceTimeout) : ""
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
Example #2
0
        public void TestFetchMessagesBuildRequestCommon(bool ssl, bool reverse, bool includeTimetoken,
                                                        string authKey, long startTime, long endTime, int count, bool sendQueryParams, bool withMeta, bool withMessageActions)
        {
            string[] channels = new[] { "history_channel", "history_channel2" };
            string   uuid     = "customuuid";
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.AuthKey          = authKey;
            pnConfiguration.UUID             = uuid;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            string startTimeString = "";
            string endTimeString   = "";

            if (startTime != -1)
            {
                startTimeString = string.Format("&start={0}", startTime.ToString());
            }
            if (endTime != -1)
            {
                endTimeString = string.Format("&end={0}", endTime.ToString());
            }

            if (count == -1)
            {
                count = 100;
            }

            Uri uri = BuildRequests.BuildFetchRequest(channels, startTime, endTime, (uint)count, reverse,
                                                      includeTimetoken, pnUnity, queryParams, withMeta, withMessageActions
                                                      );

            if (count == -1)
            {
                count = 100;
            }
            string expected = "";

            if (withMessageActions)
            {
                //http://ps.pndsn.com/v3/history-with-actions/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
                expected = string.Format("http{0}://{1}/v3/history-with-actions/sub-key/{2}/channel/{3}?max={4}{5}{6}{7}{8}{13}{9}&uuid={10}&pnsdk={11}{12}",
                                         ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, string.Join(",", channels), count,
                                         includeTimetoken?"&include_token=true":"", reverse?"&reverse=true":"",
                                         startTimeString, endTimeString, authKeyString, uuid,
                                         Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNHistoryOperation, false, true),
                                         queryParamString, withMeta?"&include_meta=true":""
                                         );
            }
            else
            {
                //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
                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}",
                                         ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, string.Join(",", channels), count,
                                         includeTimetoken?"&include_token=true":"", reverse?"&reverse=true":"",
                                         startTimeString, endTimeString, authKeyString, uuid,
                                         Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNHistoryOperation, false, true),
                                         queryParamString, withMeta?"&include_meta=true":""
                                         );
            }
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
Example #3
0
        public void TestBuildDetailedHistoryRequestCommon(bool ssl, bool reverse, bool includeTimetoken,
                                                          string authKey, long startTime, long endTime, int count)
        {
            string channel = "history_channel";
            string uuid    = "customuuid";

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.AuthKey          = authKey;
            pnConfiguration.UUID             = uuid;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            string startTimeString = "";
            string endTimeString   = "";

            if (startTime != -1)
            {
                startTimeString = string.Format("&start={0}", startTime.ToString());
            }
            if (endTime != -1)
            {
                endTimeString = string.Format("&end={0}", endTime.ToString());
            }

            if (count == -1)
            {
                count = 100;
            }

            Uri uri = BuildRequests.BuildHistoryRequest(channel, startTime, endTime, (uint)count, reverse,
                                                        includeTimetoken, pnUnity
                                                        );

            if (count == -1)
            {
                count = 100;
            }
            //Received:http://ps.pndsn.com/v2/history/sub-key/demo/channel/history_channel?count=90&reverse=true&start=14498416434364941&end=14498416799269095&auth=authKey&uuid=customuuid&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            //Received:https://ps.pndsn.com/v2/history/sub-key/demo/channel/history_channel?count=90&include_token=true&start=14498416434364941&end=14498416799269095&auth=authKey&uuid=customuuid&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            //http://ps.pndsn.com/v2/history/sub-key/demo/channel/publish_channel?count=90&start=14498416434364941&end=14498416799269095&auth=authKey&uuid=customuuid&pnsdk=PubNub-CSharp-UnityOSX/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/history/sub-key/{2}/channel/{3}?count={4}{5}{6}{7}{8}{9}&uuid={10}&pnsdk={11}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, channel, count,
                                            includeTimetoken?"&include_token=true":"", reverse?"&reverse=true":"",
                                            startTimeString, endTimeString, authKeyString, uuid,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNHistoryOperation, false, true)
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
Example #4
0
        public void TestBuildGetUserStateRequestCommon(bool testCg, bool testCh, bool ssl, string authKey, bool sendQueryParams)
        {
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }
            string channel         = "user_state_channel";
            string userState       = "{\"k\":\"v\"}";
            string uuid            = "customuuid";
            string channelGroup    = "user_state_channelGroup";
            string channelGroupStr = string.Format("&channel-group={0}", Utility.EncodeUricomponent(channelGroup, PNOperationType.PNGetStateOperation, true, false));

            if (testCh && testCg)
            {
                // test both
            }
            else if (testCg)
            {
                channel = ",";
            }
            else
            {
                channelGroup    = "";
                channelGroupStr = "";
            }

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.AuthKey          = authKey;
            pnConfiguration.UUID             = uuid;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            Uri uri = BuildRequests.BuildGetStateRequest(channel, channelGroup, uuid, pnUnity, queryParams);

            //https://ps.pndsn.com/v2/presence/sub_key/demo-36/channel/user_state_channel/uuid/customuuid?uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/v2/presence/sub_key/{2}/channel/{3}/uuid/{4}?uuid={6}{9}{7}&pnsdk={8}{10}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, channel, uuid,
                                            Utility.EncodeUricomponent(userState, PNOperationType.PNGetStateOperation, false, false),
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNGetStateOperation, false, false),
                                            channelGroupStr,
                                            queryParamString
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }
Example #5
0
        public void BuildUnregisterDevicePushRequestCommon(bool ssl, string authKey, string pushToken, PNPushType pushType, bool sendQueryParams, bool withAPNS2, bool withEnvProd, bool withTopic)
        {
            string uuid = "customuuid";
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = uuid;
            pnConfiguration.AuthKey          = authKey;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            Uri uri = BuildRequests.BuildRemoveAllDevicePushRequest(pushType, pushToken, pnUnity, queryParams);

            if (withAPNS2)
            {
                uri = BuildRequests.BuildRemoveAllDevicePushRequest(pushType, pushToken, pnUnity, queryParams, (withTopic)?"topic":"", (withEnvProd)?PNPushEnvironment.Production: PNPushEnvironment.Development);
            }

            //[1, "Removed Device"]
            //https://ps.pndsn.com/v1/push/sub-key/demo-36/devices/pushToken/remove?type=wns&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/{9}/push/sub-key/{2}/{10}/{3}/remove?type={4}{12}{11}&uuid={5}{6}&pnsdk={7}{8}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, pushToken,
                                            pushType.ToString().ToLower(),
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNRemoveAllPushNotificationsOperation, false, true),
                                            queryParamString,
                                            (withAPNS2)?"v2":"v1",
                                            (withAPNS2)?"devices-apns2":"devices",
                                            (withAPNS2)?((withEnvProd)?"&environment=production":"&environment=development"):"",
                                            (withAPNS2)?((withTopic)?"&topic=topic":""):""
                                            );
            string received = uri.OriginalString;

            UnityEngine.Debug.Log("exp:" + expected);
            UnityEngine.Debug.Log(received);
            EditorCommon.LogAndCompare(expected, received);
        }
Example #6
0
        //GetChannels
        //Get All CG
        public void TestBuildGetChannelsForChannelGroupRequestCommon(bool allCg, bool ssl, string authKey, bool sendQueryParams)
        {
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }


            string channelGroup    = "channelGroup";
            string channelGroupStr = "channel-group/";

            if (allCg)
            {
                channelGroup    = "";
                channelGroupStr = "channel-group";
            }
            string uuid = "customuuid";

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.AuthKey          = authKey;
            pnConfiguration.UUID             = uuid;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            Uri uri = BuildRequests.BuildGetChannelsForChannelGroupRequest("", channelGroup, allCg,
                                                                           pnUnity, queryParams
                                                                           );

            //http://ps.pndsn.com/v1/channel-registration/sub-key/demo-36/channel-group/channelGroup?add=addChannel1,%20addChannel2&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityOSX%2F3.7
            string expected = string.Format("http{0}://{1}/v1/channel-registration/sub-key/{2}/{8}{3}?uuid={5}{6}&pnsdk={7}{9}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, channelGroup,
                                            "",
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNChannelsForGroupOperation, false, true),
                                            channelGroupStr,
                                            queryParamString
                                            );
            string received = uri.OriginalString;

            EditorCommon.LogAndCompare(expected, received);
        }