Ejemplo n.º 1
0
        public void SendWebhook(WebhookPayload body, WebhookSettings settings)
        {
            try
            {
                var request = new HttpRequestBuilder(settings.Url)
                              .Accept(HttpAccept.Json)
                              .Build();

                request.Method = settings.Method switch
                {
                    (int)WebhookMethod.POST => HttpMethod.Post,
                    (int)WebhookMethod.PUT => HttpMethod.Put,
                    _ => throw new ArgumentOutOfRangeException($"Invalid Webhook method {settings.Method}")
                };

                request.Headers.ContentType = "application/json";
                request.SetContent(body.ToJson());

                if (settings.Username.IsNotNullOrWhiteSpace() || settings.Password.IsNotNullOrWhiteSpace())
                {
                    request.AddBasicAuthentication(settings.Username, settings.Password);
                }

                _httpClient.Execute(request);
            }
            catch (HttpException ex)
            {
                throw new WebhookException("Unable to post to webhook: {0}", ex, ex.Message);
            }
        }
Ejemplo n.º 2
0
        public ValidationFailure Test(WebhookSettings settings)
        {
            try
            {
                NotifyWebhook(
                    new WebhookPayload
                {
                    EventType = "Test",
                    Movie     = new WebhookMovie()
                    {
                        Id       = 1,
                        Title    = "Test Title",
                        FilePath = "C:\\testpath",
                    },
                    RemoteMovie = new WebhookRemoteMovie()
                    {
                        ImdbId = "tt012345",
                        Title  = "My Awesome Movie!"
                    }
                },

                    settings
                    );
            }
            catch (WebhookException ex)
            {
                return(new NzbDroneValidationFailure("Url", ex.Message));
            }

            return(null);
        }
Ejemplo n.º 3
0
        public void SendWebhook(WebhookPayload body, WebhookSettings settings)
        {
            try
            {
                var request = new HttpRequestBuilder(settings.Url)
                              .Accept(HttpAccept.Json)
                              .Build();

                request.Method = (HttpMethod)settings.Method;
                request.Headers.ContentType = "application/json";
                request.SetContent(body.ToJson());

                if (!String.IsNullOrEmpty(settings.Username) || !String.IsNullOrEmpty(settings.Password))
                {
                    var authInfo = settings.Username + ":" + settings.Password;
                    authInfo = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes(authInfo));
                    request.Headers.Set("Authorization", "Basic " + authInfo);
                }

                _httpClient.Execute(request);
            }
            catch (RestException ex)
            {
                throw new WebhookException("Unable to post to webhook: {0}", ex, ex.Message);
            }
        }
Ejemplo n.º 4
0
        public void OnRename(Movie movie, WebhookSettings settings)
        {
            var payload = new WebhookPayload
            {
                EventType = "Rename",
                Movie     = new WebhookMovie(movie)
            };

            NotifyWebhook(payload, settings);
        }
Ejemplo n.º 5
0
        public void OnRename(Series series, WebhookSettings settings)
        {
            var payload = new WebhookPayload
            {
                EventType = "Rename",
                Series    = new WebhookSeries(series)
            };

            NotifyWebhook(payload, settings);
        }
Ejemplo n.º 6
0
        public void OnDownload(Movie movie, MovieFile movieFile, WebhookSettings settings)
        {
            var payload = new WebhookPayload
            {
                EventType   = "Download",
                Movie       = new WebhookMovie(movie, movieFile),
                RemoteMovie = new WebhookRemoteMovie(movie)
            };

            NotifyWebhook(payload, settings);
        }
Ejemplo n.º 7
0
 public void NotifyWebhook(WebhookPayload body, WebhookSettings settings)
 {
     try {
         var client  = RestClientFactory.BuildClient(settings.Url);
         var request = new RestRequest((Method)settings.Method);
         request.RequestFormat = DataFormat.Json;
         request.AddBody(body);
         client.ExecuteAndValidate(request);
     }
     catch (RestException ex)
     {
         throw new WebhookException("Unable to post to webhook: {0}", ex, ex.Message);
     }
 }
Ejemplo n.º 8
0
        public void OnDownload(Series series, EpisodeFile episodeFile, WebhookSettings settings)
        {
            var payload = new WebhookPayload
            {
                EventType = "Download",
                Series    = new WebhookSeries(series),
                Episodes  = episodeFile.Episodes.Value.ConvertAll(x => new WebhookEpisode(x)
                {
                    Quality        = episodeFile.Quality.Quality.Name,
                    QualityVersion = episodeFile.Quality.Revision.Version,
                    ReleaseGroup   = episodeFile.ReleaseGroup,
                    SceneName      = episodeFile.SceneName
                })
            };

            NotifyWebhook(payload, settings);
        }
Ejemplo n.º 9
0
        public void SendWebhook(WebhookPayload body, WebhookSettings settings)
        {
            try
            {
                var request = new HttpRequestBuilder(settings.Url)
                              .Accept(HttpAccept.Json)
                              .Build();

                request.Method = (HttpMethod)settings.Method;
                request.Headers.ContentType = "application/json";
                request.SetContent(body.ToJson());

                _httpClient.Execute(request);
            }
            catch (RestException ex)
            {
                throw new WebhookException("Unable to post to webhook: {0}", ex, ex.Message);
            }
        }
Ejemplo n.º 10
0
        public void SendWebhook(WebhookPayload body, WebhookSettings settings)
        {
            try
            {
                var request = new HttpRequestBuilder(settings.Url)
                              .Accept(HttpAccept.Json)
                              .Build();

                request.Method = (HttpMethod)settings.Method;
                request.Headers.ContentType = "application/json";
                request.SetContent(body.ToJson());

                if (settings.Username.IsNotNullOrWhiteSpace() || settings.Password.IsNotNullOrWhiteSpace())
                {
                    request.AddBasicAuthentication(settings.Username, settings.Password);
                }
                _httpClient.Execute(request);
            }
            catch (HttpException ex)
            {
                throw new WebhookException("Unable to post to webhook: {0}", ex, ex.Message);
            }
        }
Ejemplo n.º 11
0
        public ValidationFailure Test(WebhookSettings settings)
        {
            try
            {
                NotifyWebhook(
                    new WebhookPayload
                {
                    EventType = "Test",
                    Series    = new WebhookSeries()
                    {
                        Id     = 1,
                        Title  = "Test Title",
                        Path   = "C:\\testpath",
                        TvdbId = 1234
                    },
                    Episodes = new List <WebhookEpisode>()
                    {
                        new WebhookEpisode()
                        {
                            Id            = 123,
                            EpisodeNumber = 1,
                            SeasonNumber  = 1,
                            Title         = "Test title"
                        }
                    }
                },
                    settings
                    );
            }
            catch (WebhookException ex)
            {
                return(new NzbDroneValidationFailure("Url", ex.Message));
            }

            return(null);
        }
Ejemplo n.º 12
0
        public void OnGrab(Movie movie, RemoteMovie remoteMovie, QualityModel quality, WebhookSettings settings)
        {
            var payload = new WebhookPayload
            {
                EventType   = "Grab",
                Movie       = new WebhookMovie(movie),
                RemoteMovie = new WebhookRemoteMovie(remoteMovie)
            };

            NotifyWebhook(payload, settings);
        }
Ejemplo n.º 13
0
        public void OnGrab(Series series, RemoteEpisode episode, QualityModel quality, WebhookSettings settings)
        {
            var payload = new WebhookPayload
            {
                EventType = "Grab",
                Series    = new WebhookSeries(series),
                Episodes  = episode.Episodes.ConvertAll(x => new WebhookEpisode(x)
                {
                    Quality        = quality.Quality.Name,
                    QualityVersion = quality.Revision.Version,
                    ReleaseGroup   = episode.ParsedEpisodeInfo.ReleaseGroup
                })
            };

            NotifyWebhook(payload, settings);
        }