示例#1
0
        public async void PushBulletPushLinkTest()
        {
            try
            {
                var devices = await Client.CurrentUsersDevices();

                Assert.IsNotNull(devices);

                var device = devices.Devices.FirstOrDefault(o => o.Nickname == TestHelper.GetConfig("Device"));
                Assert.IsNotNull(device, "Could not find the device specified.");

                PushLinkRequest reqeust = new PushLinkRequest()
                {
                    DeviceIden = device.Iden,
                    Title      = "Google",
                    Url        = "http://google.com/",
                    Body       = "Search the internet."
                };

                var response = await Client.PushLink(reqeust);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
示例#2
0
        public void PushbulletPushLinkTest()
        {
            try
            {
                var devices = Client.CurrentUsersDevices();
                Assert.IsNotNull(devices);

                var device = devices.Devices.Where(o => o.manufacturer == "Apple").FirstOrDefault();
                Assert.IsNotNull(device, "Could not find the device specified.");

                PushLinkRequest reqeust = new PushLinkRequest()
                {
                    device_iden = device.iden,
                    title       = "Google",
                    url         = "http://google.com/",
                    body        = "Search the internet."
                };

                var response = Client.PushLink(reqeust);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
示例#3
0
        public async Task <IActionResult> SendPushBulletFromAppVeyor(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
            HttpRequest req)
        {
            try
            {
                var pushBulletApiKey        = Environment.GetEnvironmentVariable("PUSHBULLET_API_KEY", EnvironmentVariableTarget.Process);
                var pushBulletEncryptionKey = Environment.GetEnvironmentVariable("PUSHBULLET_ENCRYPTION_KEY", EnvironmentVariableTarget.Process);

                if (pushBulletApiKey.IsNullOrEmpty())
                {
                    return(new BadRequestErrorMessageResult("PushBelletApiKey cannot be found"));
                }

                if (pushBulletEncryptionKey.IsNullOrEmpty())
                {
                    return(new BadRequestErrorMessageResult("PushBulletEncryptionKey cannot be found"));
                }

                var requestBody = await req.GetRawBodyStringAsync();

                var appVeyor = JsonConvert.DeserializeObject <AppVeyor>(requestBody);

                Log.Logger.Information("AppVeyor Request Built: {@AppVeyor}", appVeyor);
                //_logger.LogInformation("AppVeyor Request Built: {@AppVeyor}", appVeyor);

                var client = new PushBulletClient(pushBulletApiKey, pushBulletEncryptionKey, TimeZoneInfo.Local);

                var channel = req.Headers["Channel"].ToString();
                var title   = $"{appVeyor.EventData.ProjectName} Release";
                var body    = $"There's a new version of {appVeyor.EventData.ProjectName}! Update: {appVeyor.EventData.CommitMessage}";
                var url     = $"https://www.nuget.org/packages/{appVeyor.EventData.ProjectName}/{appVeyor.EventData.BuildVersion}";

                if (channel.IsNullOrEmpty())
                {
                    return(new BadRequestErrorMessageResult($"Unknown channel from project {appVeyor.EventData.ProjectName}"));
                }

                var pushLinkRequest = new PushLinkRequest
                {
                    ChannelTag = channel,
                    Title      = title,
                    Url        = url,
                    Body       = body
                };

                var pushLinkResponse = await client.PushLink(pushLinkRequest);

                _logger.LogInformation("PushBullet Sent Link Message. {@PushLinkRequest} {@PushLinkResponse}", pushLinkRequest, pushLinkResponse);

                return(new OkObjectResult(pushLinkResponse));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error sending PushBullet message");
                return(new BadRequestErrorMessageResult(ex.Message));
            }
        }
示例#4
0
        /// <summary>
        /// Pushes the link.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="ignoreEmptyFields">if set to <c>true</c> [ignore empty fields].</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">link request</exception>
        /// <exception cref="System.Exception">
        /// </exception>
        public PushResponse PushLink(PushLinkRequest request, bool ignoreEmptyFields = false)
        {
            try
            {
                #region pre-processing

                if (request == null)
                {
                    throw new ArgumentNullException("link request");
                }

                if (string.IsNullOrWhiteSpace(request.DeviceIden) && string.IsNullOrWhiteSpace(request.Email))
                {
                    throw new Exception(PushbulletConstants.PushRequestErrorMessages.EmptyEmailProperty);
                }

                if (string.IsNullOrWhiteSpace(request.Type))
                {
                    throw new Exception(PushbulletConstants.PushRequestErrorMessages.EmptyTypeProperty);
                }

                if (!ignoreEmptyFields)
                {
                    if (string.IsNullOrWhiteSpace(request.Title))
                    {
                        throw new Exception(PushbulletConstants.PushLinkErrorMessages.EmptyTitleProperty);
                    }

                    if (string.IsNullOrWhiteSpace(request.Url))
                    {
                        throw new Exception(PushbulletConstants.PushLinkErrorMessages.EmptyUrlProperty);
                    }

                    //the body property is optional.
                }

                #endregion pre-processing


                #region processing

                return(PostPushRequest <PushLinkRequest>(request));

                #endregion processing
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#5
0
        private async Task <List <PushResponse> > SendToDevices(PushBulletClient client, PushBullet pushBulletModel, string userId)
        {
            var devices = await client.CurrentUsersDevices();

            var deviceToSend = devices.Devices.Where(x => pushBulletModel.DeviceNickNames.Contains(x.Nickname)).ToList();

            if (!deviceToSend.Any())
            {
                throw new NullReferenceException($"No device nicknames matched {string.Join(", ", pushBulletModel.DeviceNickNames)}");
            }

            var responses = new List <PushResponse>();

            deviceToSend.ForEach(async device =>
            {
                if (string.IsNullOrEmpty(pushBulletModel.Url))
                {
                    var pushNoteRequest = new PushNoteRequest
                    {
                        DeviceIden = device.Iden,
                        Title      = pushBulletModel.Title,
                        Body       = pushBulletModel.Body
                    };

                    var pushNoteResponse = await client.PushNote(pushNoteRequest);

                    _logger.LogInformation("PushBullet Sent Message by {UserId}.", userId);

                    responses.Add(pushNoteResponse);
                }
                else
                {
                    var pushLinkRequest = new PushLinkRequest
                    {
                        DeviceIden = device.Iden,
                        Title      = pushBulletModel.Title,
                        Url        = pushBulletModel.Url,
                        Body       = pushBulletModel.Body
                    };

                    var pushLinkResponse = await client.PushLink(pushLinkRequest);

                    _logger.LogInformation("PushBullet Sent Link Message by {UserId}.", userId);

                    responses.Add(pushLinkResponse);
                }
            });

            return(responses);
        }
示例#6
0
        public void Push(string title, string message, string url)
        {
            var device = GetDevice();

            if (device != null)
            {
                var request = new PushLinkRequest
                {
                    DeviceIden = device.Iden,
                    Title      = title,
                    Body       = message,
                    Url        = url
                };

                var response = _client.PushLink(request);
            }
        }
示例#7
0
        private async Task <List <PushResponse> > SendToChannel(PushBulletClient client, PushBullet pushBulletModel, string userId)
        {
            var responses = new List <PushResponse>();

            if (string.IsNullOrEmpty(pushBulletModel.Url))
            {
                var pushNoteRequest = new PushNoteRequest
                {
                    ChannelTag = pushBulletModel.Channel,
                    Title      = pushBulletModel.Title,
                    Body       = pushBulletModel.Body
                };

                var pushNoteResponse = await client.PushNote(pushNoteRequest);

                _logger.LogInformation("PushBullet Sent Message by {UserId}.", userId);

                responses.Add(pushNoteResponse);
            }
            else
            {
                var pushLinkRequest = new PushLinkRequest
                {
                    ChannelTag = pushBulletModel.Channel,
                    Title      = pushBulletModel.Title,
                    Url        = pushBulletModel.Url,
                    Body       = pushBulletModel.Body
                };

                var pushLinkResponse = await client.PushLink(pushLinkRequest);

                _logger.LogInformation("PushBullet Sent Link Message by {UserId}.", userId);

                responses.Add(pushLinkResponse);
            }

            return(responses);
        }