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); } }
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); }
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); } }
public void OnRename(Movie movie, WebhookSettings settings) { var payload = new WebhookPayload { EventType = "Rename", Movie = new WebhookMovie(movie) }; NotifyWebhook(payload, settings); }
public void OnRename(Series series, WebhookSettings settings) { var payload = new WebhookPayload { EventType = "Rename", Series = new WebhookSeries(series) }; NotifyWebhook(payload, settings); }
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); }
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); } }
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); }
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); } }
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); } }
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); }
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); }
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); }