private T ProcessRequest <T>(HadoukenSettings settings, string method, params object[] parameters) { var baseUrl = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, "api"); var requestBuilder = new JsonRpcRequestBuilder(baseUrl, method, parameters); requestBuilder.LogResponseContent = true; requestBuilder.NetworkCredential = new NetworkCredential(settings.Username, settings.Password); requestBuilder.Headers.Add("Accept-Encoding", "gzip,deflate"); var httpRequest = requestBuilder.Build(); HttpResponse response; try { response = _httpClient.Execute(httpRequest); } catch (HttpException ex) { throw new DownloadClientException("Unable to connect to Hadouken, please check your settings", ex); } catch (WebException ex) { throw new DownloadClientUnavailableException("Unable to connect to Hadouken, please check your settings", ex); } var result = Json.Deserialize <JsonRpcResponse <T> >(response.Content); if (result.Error != null) { throw new DownloadClientException("Error response received from Hadouken: {0}", result.Error.ToString()); } return(result.Result); }
public string GetBaseUrl(NzbgetSettings settings, string relativePath = null) { var baseUrl = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, settings.UrlBase); baseUrl = HttpUri.CombinePath(baseUrl, relativePath); return(baseUrl); }
private HttpRequestBuilder BuildRequest(NzbVortexSettings settings) { var baseUrl = HttpRequestBuilder.BuildBaseUrl(true, settings.Host, settings.Port, settings.UrlBase); baseUrl = HttpUri.CombinePath(baseUrl, "api"); var requestBuilder = new HttpRequestBuilder(baseUrl); requestBuilder.LogResponseContent = true; return(requestBuilder); }
private string SendCommand(XbmcSettings settings, string command) { var url = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, $"xbmcCmds/xbmcHttp?command={command}"); if (!string.IsNullOrEmpty(settings.Username)) { return(_httpProvider.DownloadString(url, settings.Username, settings.Password)); } return(_httpProvider.DownloadString(url)); }
private JsonRpcRequestBuilder BuildRequest(DelugeSettings settings) { string url = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, settings.UrlBase); var requestBuilder = new JsonRpcRequestBuilder(url); requestBuilder.LogResponseContent = true; requestBuilder.Resource("json"); requestBuilder.PostProcess += r => r.RequestTimeout = TimeSpan.FromSeconds(15); AuthenticateClient(requestBuilder, settings); return(requestBuilder); }
private HttpRequestBuilder GetBuilder(string relativePath, CalibreSettings settings) { var baseUrl = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, settings.UrlBase); baseUrl = HttpUri.CombinePath(baseUrl, relativePath); var builder = new HttpRequestBuilder(baseUrl) .Accept(HttpAccept.Json); builder.LogResponseContent = true; if (settings.Username.IsNotNullOrWhiteSpace()) { builder.NetworkCredential = new NetworkCredential(settings.Username, settings.Password); } return(builder); }
private T ProcessRequest <T>(NzbgetSettings settings, string method, params object[] parameters) { var baseUrl = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, "jsonrpc"); var requestBuilder = new JsonRpcRequestBuilder(baseUrl, method, parameters); requestBuilder.LogResponseContent = true; requestBuilder.NetworkCredential = new NetworkCredential(settings.Username, settings.Password); var httpRequest = requestBuilder.Build(); HttpResponse response; try { response = _httpClient.Execute(httpRequest); } catch (HttpException ex) { if (ex.Response.StatusCode == HttpStatusCode.Unauthorized) { throw new DownloadClientAuthenticationException("Authentication failed for NzbGet, please check your settings", ex); } throw new DownloadClientException("Unable to connect to NzbGet. " + ex.Message, ex); } catch (WebException ex) { throw new DownloadClientUnavailableException("Unable to connect to NzbGet. " + ex.Message, ex); } var result = Json.Deserialize <JsonRpcResponse <T> >(response.Content); if (result.Error != null) { throw new DownloadClientException("Error response received from nzbget: {0}", result.Error.ToString()); } return(result.Result); }
private string ProcessRequest(XbmcSettings settings, string method, params object[] parameters) { var url = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, "jsonrpc"); var requestBuilder = new JsonRpcRequestBuilder(url, method, parameters); requestBuilder.LogResponseContent = true; var request = requestBuilder.Build(); if (!settings.Username.IsNullOrWhiteSpace()) { request.Credentials = new BasicNetworkCredential(settings.Username, settings.Password); } var response = _httpClient.Execute(request); _logger.Trace("Response: {0}", response.Content); CheckForError(response); return(response.Content); }
private ValidationFailure TestSettings() { var config = _proxy.GetSettings(Settings); if (!config.CreateAlbumFolder) { return(new NzbDroneValidationFailure(string.Empty, "Deemix must have 'Create Album Folders' enabled") { InfoLink = HttpRequestBuilder.BuildBaseUrl(Settings.UseSsl, Settings.Host, Settings.Port, Settings.UrlBase), DetailedDescription = "Deemix must have 'Create Album Folders' enabled, otherwise Lidarr will not be able to import the downloads", }); } if (!config.CreateSingleFolder) { return(new NzbDroneValidationFailure(string.Empty, "Deemix must have 'Create folder structure for singles' enabled") { InfoLink = HttpRequestBuilder.BuildBaseUrl(Settings.UseSsl, Settings.Host, Settings.Port, Settings.UrlBase), DetailedDescription = "Deemix must have 'Create folder structure for singles' enabled, otherwise Lidarr will not be able to import single downloads", }); } try { _proxy.Authenticate(Settings); } catch (DownloadClientException) { return(new NzbDroneValidationFailure(string.Empty, "Could not login to Deemix. Invalid ARL?") { InfoLink = HttpRequestBuilder.BuildBaseUrl(Settings.UseSsl, Settings.Host, Settings.Port, Settings.UrlBase), DetailedDescription = "Deemix requires a valid ARL to initiate downloads", }); } return(null); }
private string GetLibraryUri(CalibreSettings settings) { return(HttpUri.CombinePath(HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, settings.UrlBase), settings.Library)); }