示例#1
0
        private static void DoPush(CLArguments parsedArgs)
        {
            using (var client = new PushbulletClient(parsedArgs.ApiKey))
            {
                PushbulletDevices devices        = client.GetDevices();
                string            targetDeviceId = (
                    devices.Devices.SingleOrDefault(device => String.Compare(device.Name, parsedArgs.Device, StringComparison.OrdinalIgnoreCase) == 0)
                    ??
                    new PushbulletDevice()
                    ).Id;

                if (string.IsNullOrEmpty(targetDeviceId))
                {
                    ConsoleHelpers.WriteErrorAndExit("No device found with the given name.");
                }

                // validate or autodetect push type
                PushbulletPushType pushType;
                if (String.IsNullOrEmpty(parsedArgs.Type))
                {
                    pushType = PushbulletClient.DetectType(parsedArgs.Body);
                }
                else
                {
                    if (!Enum.TryParse(parsedArgs.Type, true, out pushType))
                    {
                        ConsoleHelpers.WriteErrorAndExit("Incorrect push type specified.");
                    }
                }
                dynamic response = null;
                try
                {
                    System.Console.Write("Pushing {0} {1}... ", pushType != PushbulletPushType.Address ? "a" : "an", pushType.ToString().ToLowerInvariant());
                    response = client.Push(targetDeviceId, pushType, parsedArgs.Title, parsedArgs.Body);
                    System.Console.WriteLine("SUCCESS");
                }
                catch (Exception ex)
                {
                    ConsoleHelpers.WriteErrorAndExit("Exception during pushing: " + ex.Message);
                }
                if (parsedArgs.ShowResponse)
                {
                    System.Console.WriteLine("Response:\r\n{0}", new[] { response.ToString() });
                }
            }
        }
示例#2
0
 public async void SendPush(string deviceId, PushbulletPushType type, string title, string body)
 {
     EnsureClient();
     _client.Push(deviceId, type, title, body);
 }