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 void RemoveTorrentAndData(HadoukenSettings settings, string downloadId) { ProcessRequest <bool>(settings, "webui.perform", "removedata", new string[] { downloadId }); }
public void AddTorrentUri(HadoukenSettings settings, string torrentUrl) { ProcessRequest <string>(settings, "webui.addTorrent", "url", torrentUrl, new { label = settings.Category }); }
public string AddTorrentFile(HadoukenSettings settings, byte[] fileContent) { return(ProcessRequest <string>(settings, "webui.addTorrent", "file", Convert.ToBase64String(fileContent), new { label = settings.Category })); }
public IReadOnlyDictionary <string, object> GetConfig(HadoukenSettings settings) { return(ProcessRequest <IReadOnlyDictionary <string, object> >(settings, "webui.getSettings")); }
public HadoukenTorrent[] GetTorrents(HadoukenSettings settings) { var result = ProcessRequest <HadoukenTorrentResponse>(settings, "webui.list"); return(GetTorrents(result.Torrents)); }
public HadoukenSystemInfo GetSystemInfo(HadoukenSettings settings) { return(ProcessRequest <HadoukenSystemInfo>(settings, "core.getSystemInfo")); }