private string ProcessRequest(HttpRequestBuilder requestBuilder, SabnzbdSettings settings) { var httpRequest = requestBuilder.Build(); HttpResponse response; _logger.Debug("Url: {0}", httpRequest.Url); try { response = _httpClient.Execute(httpRequest); } catch (HttpException ex) { throw new DownloadClientException("Unable to connect to SABnzbd, please check your settings", ex); } catch (WebException ex) { throw new DownloadClientException("Unable to connect to SABnzbd, please check your settings", ex); } CheckForError(response); return(response.Content); }
public void RetryDownload(string id, SabnzbdSettings settings) { var request = new RestRequest(); var action = String.Format("mode=retry&value={0}", id); ProcessRequest(request, action, settings); }
private string ProcessRequest(HttpRequestBuilder requestBuilder, SabnzbdSettings settings) { var httpRequest = requestBuilder.Build(); HttpResponse response; _logger.Debug("Url: {0}", httpRequest.Url); try { response = _httpClient.Execute(httpRequest); } catch (HttpException ex) { throw new DownloadClientException("Unable to connect to SABnzbd, {0}", ex, ex.Message); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.TrustFailure) { throw new DownloadClientUnavailableException("Unable to connect to SABnzbd, certificate validation failed.", ex); } throw new DownloadClientUnavailableException("Unable to connect to SABnzbd, {0}", ex, ex.Message); } CheckForError(response); return(response.Content); }
private HttpRequestBuilder BuildRequest(string mode, SabnzbdSettings settings) { var baseUrl = string.Format(@"{0}://{1}:{2}/api", settings.UseSsl ? "https" : "http", settings.Host, settings.Port); var requestBuilder = new HttpRequestBuilder(baseUrl) .Accept(HttpAccept.Json) .AddQueryParam("mode", mode); requestBuilder.LogResponseContent = true; if (settings.ApiKey.IsNotNullOrWhiteSpace()) { requestBuilder.AddSuffixQueryParam("apikey", settings.ApiKey); } else { requestBuilder.AddSuffixQueryParam("ma_username", settings.Username); requestBuilder.AddSuffixQueryParam("ma_password", settings.Password); } requestBuilder.AddSuffixQueryParam("output", "json"); return(requestBuilder); }
public void RemoveFrom(string source, string id, SabnzbdSettings settings) { var request = new RestRequest(); var action = String.Format("mode={0}&name=delete&del_files=1&value={1}", source, id); ProcessRequest(request, action, settings); }
public SabnzbdConfig GetConfig(SabnzbdSettings settings) { var request = BuildRequest("get_config", settings); var response = Json.Deserialize <SabnzbdConfigResponse>(ProcessRequest(request, settings)); return(response.Config); }
public string GetBaseUrl(SabnzbdSettings settings, string relativePath = null) { var baseUrl = HttpRequestBuilder.BuildBaseUrl(settings.UseSsl, settings.Host, settings.Port, settings.UrlBase); baseUrl = HttpUri.CombinePath(baseUrl, relativePath); return(baseUrl); }
public SabnzbdConfig GetConfig(SabnzbdSettings settings) { var request = new RestRequest(); var action = "mode=get_config"; var response = Json.Deserialize <SabnzbdConfigResponse>(ProcessRequest(request, action, settings)); return(response.Config); }
public SabnzbdCategoryResponse GetCategories(SabnzbdSettings settings) { var request = new RestRequest(); var action = "mode=get_cats"; var response = Json.Deserialize <SabnzbdCategoryResponse>(ProcessRequest(request, action, settings)); return(response); }
public SabnzbdQueue GetQueue(int start, int limit, SabnzbdSettings settings) { var request = new RestRequest(); var action = String.Format("mode=queue&start={0}&limit={1}", start, limit); var response = ProcessRequest(request, action, settings); return(Json.Deserialize <SabnzbdQueue>(JObject.Parse(response).SelectToken("queue").ToString())); }
public void RemoveFrom(string source, string id, bool deleteData, SabnzbdSettings settings) { var request = BuildRequest(source, settings); request.AddQueryParam("name", "delete"); request.AddQueryParam("del_files", deleteData ? 1 : 0); request.AddQueryParam("value", id); ProcessRequest(request, settings); }
public SabnzbdFullStatus GetFullStatus(SabnzbdSettings settings) { var request = BuildRequest("fullstatus", settings); request.AddQueryParam("skip_dashboard", "1"); var response = Json.Deserialize <SabnzbdFullStatusResponse>(ProcessRequest(request, settings)); return(response.Status); }
public SabnzbdQueue GetQueue(int start, int limit, SabnzbdSettings settings) { var request = BuildRequest("queue", settings); request.AddQueryParam("start", start); request.AddQueryParam("limit", limit); var response = ProcessRequest(request, settings); return(Json.Deserialize <SabnzbdQueue>(JObject.Parse(response).SelectToken("queue").ToString())); }
public string ProcessRequest(IRestRequest restRequest, string action, SabnzbdSettings settings) { var client = BuildClient(action, settings); var response = client.Execute(restRequest); _logger.Trace("Response: {0}", response.Content); CheckForError(response); return(response.Content); }
public string GetVersion(SabnzbdSettings settings) { var request = BuildRequest("version", settings); SabnzbdVersionResponse response; if (!Json.TryDeserialize <SabnzbdVersionResponse>(ProcessRequest(request, settings), out response)) { response = new SabnzbdVersionResponse(); } return(response.Version); }
public SabnzbdHistory GetHistory(int start, int limit, string category, SabnzbdSettings settings) { var request = new RestRequest(); var action = string.Format("mode=history&start={0}&limit={1}", start, limit); if (category.IsNotNullOrWhiteSpace()) { action += "&category=" + category; } var response = ProcessRequest(request, action, settings); return(Json.Deserialize <SabnzbdHistory>(JObject.Parse(response).SelectToken("history").ToString())); }
public SabnzbdVersionResponse GetVersion(SabnzbdSettings settings) { var request = new RestRequest(); var action = "mode=version"; SabnzbdVersionResponse response; if (!Json.TryDeserialize <SabnzbdVersionResponse>(ProcessRequest(request, action, settings), out response)) { response = new SabnzbdVersionResponse(); } return(response); }
public string RetryDownload(string id, SabnzbdSettings settings) { var request = new RestRequest(); var action = String.Format("mode=retry&value={0}", id); SabnzbdRetryResponse response; if (!Json.TryDeserialize <SabnzbdRetryResponse>(ProcessRequest(request, action, settings), out response)) { response = new SabnzbdRetryResponse(); response.Status = true; } return(response.Id); }
public SabnzbdHistory GetHistory(int start, int limit, string category, SabnzbdSettings settings) { var request = BuildRequest("history", settings); request.AddQueryParam("start", start); request.AddQueryParam("limit", limit); if (category.IsNotNullOrWhiteSpace()) { request.AddQueryParam("category", category); } var response = ProcessRequest(request, settings); return(Json.Deserialize <SabnzbdHistory>(JObject.Parse(response).SelectToken("history").ToString())); }
public string RetryDownload(string id, SabnzbdSettings settings) { var request = BuildRequest("retry", settings); request.AddQueryParam("value", id); SabnzbdRetryResponse response; if (!Json.TryDeserialize <SabnzbdRetryResponse>(ProcessRequest(request, settings), out response)) { response = new SabnzbdRetryResponse(); response.Status = true; } return(response.Id); }
private IRestClient BuildClient(string action, SabnzbdSettings settings) { var protocol = settings.UseSsl ? "https" : "http"; var authentication = settings.ApiKey.IsNullOrWhiteSpace() ? String.Format("ma_username={0}&ma_password={1}", settings.Username, Uri.EscapeDataString(settings.Password)) : String.Format("apikey={0}", settings.ApiKey); var url = String.Format(@"{0}://{1}:{2}/api?{3}&{4}&output=json", protocol, settings.Host, settings.Port, action, authentication); _logger.Debug("Url: " + url); return(RestClientFactory.BuildClient(url)); }
public SabnzbdAddResponse DownloadNzbByUrl(string url, string category, int priority, SabnzbdSettings settings) { var request = BuildRequest("addurl", settings).Post(); request.AddQueryParam("name", url); request.AddQueryParam("cat", category); request.AddQueryParam("priority", priority); SabnzbdAddResponse response; if (!Json.TryDeserialize <SabnzbdAddResponse>(ProcessRequest(request, settings), out response)) { response = new SabnzbdAddResponse(); response.Status = true; } return(response); }
public SabnzbdAddResponse DownloadNzb(Byte[] nzbData, string filename, string category, int priority, SabnzbdSettings settings) { var request = new RestRequest(Method.POST); var action = String.Format("mode=addfile&cat={0}&priority={1}", Uri.EscapeDataString(category), priority); request.AddFile("name", nzbData, filename, "application/x-nzb"); SabnzbdAddResponse response; if (!Json.TryDeserialize <SabnzbdAddResponse>(ProcessRequest(request, action, settings), out response)) { response = new SabnzbdAddResponse(); response.Status = true; } return(response); }
public SabnzbdAddResponse DownloadNzb(byte[] nzbData, string filename, string category, int priority, SabnzbdSettings settings) { var request = BuildRequest("addfile", settings).Post(); request.AddQueryParam("cat", category); request.AddQueryParam("priority", priority); request.AddFormUpload("name", filename, nzbData, "application/x-nzb"); SabnzbdAddResponse response; if (!Json.TryDeserialize <SabnzbdAddResponse>(ProcessRequest(request, settings), out response)) { response = new SabnzbdAddResponse(); response.Status = true; } return(response); }