Example #1
0
        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);
        }
Example #2
0
 public void RemoveTorrentAndData(HadoukenSettings settings, string downloadId)
 {
     ProcessRequest <bool>(settings, "webui.perform", "removedata", new string[] { downloadId });
 }
Example #3
0
 public void AddTorrentUri(HadoukenSettings settings, string torrentUrl)
 {
     ProcessRequest <string>(settings, "webui.addTorrent", "url", torrentUrl, new { label = settings.Category });
 }
Example #4
0
 public string AddTorrentFile(HadoukenSettings settings, byte[] fileContent)
 {
     return(ProcessRequest <string>(settings, "webui.addTorrent", "file", Convert.ToBase64String(fileContent), new { label = settings.Category }));
 }
Example #5
0
 public IReadOnlyDictionary <string, object> GetConfig(HadoukenSettings settings)
 {
     return(ProcessRequest <IReadOnlyDictionary <string, object> >(settings, "webui.getSettings"));
 }
Example #6
0
        public HadoukenTorrent[] GetTorrents(HadoukenSettings settings)
        {
            var result = ProcessRequest <HadoukenTorrentResponse>(settings, "webui.list");

            return(GetTorrents(result.Torrents));
        }
Example #7
0
 public HadoukenSystemInfo GetSystemInfo(HadoukenSettings settings)
 {
     return(ProcessRequest <HadoukenSystemInfo>(settings, "core.getSystemInfo"));
 }