Example #1
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);
        }
Example #2
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);
        }