示例#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();
        }