public void DetectType_BodyWithWww_ReturnsLinkType()
        {
            const string body = "www.fakedomain.au/subpage";

            var detectedType = PushbulletClient.DetectType(body);

            Assert.AreEqual(PushbulletPushType.Link, detectedType);
        }
        public void DetectType_NullBody_ReturnsNoteType()
        {
            const string body = null;

            var detectedType = PushbulletClient.DetectType(body);

            Assert.AreEqual(PushbulletPushType.Note, detectedType);
        }
        public void DetectType_RegularText_ReturnsNoteType()
        {
            const string body = "just a note";

            var detectedType = PushbulletClient.DetectType(body);

            Assert.AreEqual(PushbulletPushType.Note, detectedType);
        }
        public void DetectType_BodyWithList_ReturnsListType()
        {
            const string body = "item 1;item 2;item 3";

            var detectedType = PushbulletClient.DetectType(body);

            Assert.AreEqual(PushbulletPushType.List, detectedType);
        }
        public void DetectType_BodyWithFileScheme_ReturnsFileType()
        {
            const string body = "file:///c:/temp/test.jpg";

            var detectedType = PushbulletClient.DetectType(body);

            Assert.AreEqual(PushbulletPushType.File, detectedType);
        }
        public void DetectType_BodyWithFilePath_ReturnsFileType()
        {
            const string body = @"c:\temp\test.jpg";

            var detectedType = PushbulletClient.DetectType(body);

            Assert.AreEqual(PushbulletPushType.File, detectedType);
        }
Exemple #7
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() });
                }
            }
        }