예제 #1
0
        private static void TestPush()
        {
            Console.WriteLine("================ TESTING PUSH ================");
            Console.WriteLine();

            Console.WriteLine("PUSH Broadcast Alert");
            var response = _urbanAirSharpGateway.Push(new Push("Broadcast Alert"));
            Console.Write(response.HttpResponseCode + " - ");
            Console.WriteLine(response.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();

            Console.WriteLine("PUSH Broadcast Alert to Androids");
            response = _urbanAirSharpGateway.Push(new Push("Broadcast Alert to Androids") { DeviceTypes = new[] { DeviceType.Android } });
            Console.Write(response.HttpResponseCode + " - ");
            Console.WriteLine(response.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();

            Console.WriteLine("PUSH Targeted Alert to device");
            response = _urbanAirSharpGateway.Push(new Push(new Device("android-id-blah-blah", DeviceType.Android), "Targeted Alert to device"));
            Console.Write(response.HttpResponseCode + " - ");
            Console.WriteLine(response.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();

            Console.WriteLine("PUSH Custom Alert per device type");
            response = _urbanAirSharpGateway.Push(new Push("Custom Alert per device type", new[]
            {
                new AndroidAlert
                {
                    Alert = "Custom Android Alert",
                    CollapseKey = "Collapse_Key",
                    DelayWhileIdle = true,
                    GcmTimeToLive = 5
                }
            }));
            Console.Write(response.HttpResponseCode + " - ");
            Console.WriteLine(response.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();

            //these are just examples of tags
            var rugbyFanAudience = new Audience(AudienceType.Tag, "Rugby Fan");
            var footballFanAudience = new Audience(AudienceType.Tag, "Football Fan");
            var notFootballFanAudience = new AudienceNot { Audience = footballFanAudience };
            var newZealandAudience = new Audience(AudienceType.Alias, "NZ");
            var englishAudience = new Audience(AudienceType.Tag, "language_en");

            var fansAudience = englishAudience.Or(new IAudience[] { rugbyFanAudience, notFootballFanAudience });

            var customAudience = rugbyFanAudience.And(new IAudience[] { fansAudience, !newZealandAudience, !englishAudience });
            var customAudience2 = rugbyFanAudience & fansAudience & !newZealandAudience & !englishAudience;

            Console.WriteLine("PUSH to custom Audience");
            response = _urbanAirSharpGateway.Push(new Push(customAudience, "Rugby fans that's not English or NewZealanders"));

            Console.Write(response.HttpResponseCode + " - ");
            Console.WriteLine(response.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();
        }
예제 #2
0
        private static void TestPush()
        {
            Console.WriteLine("================ TESTING PUSH ================");
            Console.WriteLine();

            Console.WriteLine("PUSH Broadcast Alert");
            var response = _urbanAirSharpGateway.Push("Broadcast Alert");
            Console.Write(response.HttpResponseCode + " - ");
            Console.WriteLine(response.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();

            Console.WriteLine("PUSH Broadcast Alert to Androids");
            response = _urbanAirSharpGateway.Push("Broadcast Alert to Androids", new List<DeviceType> { DeviceType.Android });
            Console.Write(response.HttpResponseCode + " - ");
            Console.WriteLine(response.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();

            Console.WriteLine("PUSH Targeted Alert to device");
            response = _urbanAirSharpGateway.Push("Targeted Alert to device", new List<DeviceType> { DeviceType.Android }, TestDeviceGuid);
            Console.Write(response.HttpResponseCode + " - ");
            Console.WriteLine(response.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();

            Console.WriteLine("PUSH Custom Alert per device type");
            response = _urbanAirSharpGateway.Push("Custom Alert per device type", null, null, new List<BaseAlert>
            {
                new AndroidAlert
                {
                    Alert = "Custom Android Alert",
                    CollapseKey = "Collapse_Key",
                    DelayWhileIdle = true,
                    GcmTimeToLive = 5
                }
            });
            Console.Write(response.HttpResponseCode + " - ");
            Console.WriteLine(response.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();

            //these are just examples of tags
            var rugbyFanAudience = new Audience(AudienceType.Tag, "Rugby Fan");
            var footballFanAudience = new Audience(AudienceType.Tag, "Football Fan");
            var notFootballFanAudience = new Audience().NotAudience(footballFanAudience);
            var newZealandAudience = new Audience(AudienceType.Alias, "NZ");
            var englishAudience = new Audience(AudienceType.Tag, "language_en");

            var fansAudience = new Audience().OrAudience(new List<Audience> { rugbyFanAudience, notFootballFanAudience });

            var customAudience = new Audience().AndAudience(new List<Audience> { fansAudience, newZealandAudience, englishAudience });

            Console.WriteLine("PUSH to custom Audience");
            response = _urbanAirSharpGateway.Push("English speaking New Zealand Rugby fans", null, null, null, customAudience);

            Console.Write(response.HttpResponseCode + " - ");
            Console.WriteLine(response.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();
        }
예제 #3
0
 public void SetAudience(AudienceType audienceType, String value)
 {
     Audience = new Audience(audienceType, value);
 }
예제 #4
0
        public Audience NotAudience(Audience audience)
        {
            ClearAudience();

            Not = audience;

            return this;
        }
예제 #5
0
 public void SetAudience(AudienceType audienceType, String value)
 {
     Audience = new Audience(audienceType, value);
 }
예제 #6
0
        private static void TestTags()
        {
            Console.WriteLine("================ TESTING TAGS ================");
            Console.WriteLine();

            const string testTag = "some_tag";

            var tag = new Tag
            {
                TagName = testTag,
                AndroidChannels = new AddRemoveList
                {
                    Add = new[] { "TEST_ANDROID_CHANNEL" }
                }
            };

            Console.WriteLine("CREATE TAG:");
            var response = _urbanAirSharpGateway.CreateTag(tag);
            Console.Write(response.HttpResponseCode + " - ");
            Console.WriteLine(response.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();

            Console.WriteLine("LIST TAGS:");
            var listResponse = _urbanAirSharpGateway.ListTags();
            Console.Write(listResponse.HttpResponseCode + " - ");
            Console.WriteLine(listResponse.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();

            Console.WriteLine("DELETE TAG:");
            response = _urbanAirSharpGateway.DeleteTag(testTag);
            Console.Write(response.HttpResponseCode + " - ");
            Console.WriteLine(response.Ok ? "SUCCESS" : "FAILED");
            Console.WriteLine();

            var client = new UrbanAirSharpGateway(AppKey, AppMasterSecret);
            var compoundAudience = new Audience(AudienceType.Android, "") & new Audience(AudienceType.Blackberry, "") & new Audience(AudienceType.Android, "");
            compoundAudience &= new Audience(AudienceType.Android, "");

            var moreAudience = new AudienceAnd { Audiences = new[] { new Audience(AudienceType.Tag, ""), new Audience(AudienceType.Tag, "") } };
            compoundAudience &= moreAudience;

            var message = new Push(compoundAudience, "What's up");

            client.Push(new Push("Custom Android Alert per device type", new[]
            {
                new AndroidAlert()
                {
                    Alert = "Custom Android Alert",
                    CollapseKey = "Collapse_Key",
                    DelayWhileIdle = true,
                    GcmTimeToLive = 5
                }
            }));
        }