コード例 #1
0
ファイル: SkyHookProxy.cs プロジェクト: Djohnnie/Sonarr
        public SkyHookProxy(IHttpClient httpClient, Logger logger)
        {
            _httpClient = httpClient;
            _logger = logger;

            _requestBuilder = new HttpRequestBuilder("http://skyhook.sonarr.tv/v1/tvdb/{route}/en/");
        }
コード例 #2
0
        public SonarrCloudRequestBuilder()
        {
            Services = new HttpRequestBuilder("http://services.sonarr.tv/v1/")
                .CreateFactory();

            SkyHookTvdb = new HttpRequestBuilder("http://skyhook.sonarr.tv/v1/tvdb/{route}/{language}/")
                .SetSegment("language", "en")
                .CreateFactory();
        }
コード例 #3
0
        public void should_remove_duplicated_slashes()
        {
            var builder = new HttpRequestBuilder("http://domain/");

            var request = builder.Build("/v1/");

            request.Url.ToString().Should().Be("http://domain/v1/");

        }
コード例 #4
0
        public string GetToken(RarbgSettings settings)
        {
            return _tokenCache.Get(settings.BaseUrl, () =>
                {
                    var requestBuilder = new HttpRequestBuilder(settings.BaseUrl.Trim('/'))
                        .WithRateLimit(3.0)
                        .Resource("/pubapi_v2.php?get_token=get_token&app_id=Sonarr")
                        .Accept(HttpAccept.Json);

                    if (settings.CaptchaToken.IsNotNullOrWhiteSpace())
                    {
                        requestBuilder.UseSimplifiedUserAgent = true;
                        requestBuilder.SetCookie("cf_clearance", settings.CaptchaToken);
                    }

                    var response = _httpClient.Get<JObject>(requestBuilder.Build());

                    return response.Resource["token"].ToString();
                }, TimeSpan.FromMinutes(14.0));
        }
コード例 #5
0
        public UTorrentResponse ProcessRequest(HttpRequestBuilder requestBuilder, UTorrentSettings settings)
        {
            AuthenticateClient(requestBuilder, settings);

            var request = requestBuilder.Build();

            HttpResponse response;
            try
            {
                response = _httpClient.Execute(request);
            }
            catch (HttpException ex)
            {
                if (ex.Response.StatusCode == HttpStatusCode.BadRequest || ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    _logger.Debug("Authentication required, logging in.");

                    AuthenticateClient(requestBuilder, settings, true);

                    request = requestBuilder.Build();

                    response = _httpClient.Execute(request);
                }
                else
                {
                    throw new DownloadClientException("Unable to connect to uTorrent, please check your settings", ex);
                }
            }
            catch (WebException ex)
            {
                throw new DownloadClientException("Unable to connect to uTorrent, please check your settings", ex);
            }

            return Json.Deserialize<UTorrentResponse>(response.Content);
        }
コード例 #6
0
        private IEnumerable<IndexerRequest> GetPagedRequests(string mode, int? tvdbId, string query, params object[] args)
        {
            var requestBuilder = new HttpRequestBuilder(Settings.BaseUrl)
                .Resource("/pubapi_v2.php")
                .Accept(HttpAccept.Json);

            requestBuilder.AddQueryParam("mode", mode);

            if (tvdbId.HasValue)
            {
                requestBuilder.AddQueryParam("search_tvdb", tvdbId.Value);
            }

            if (query.IsNotNullOrWhiteSpace())
            {
                requestBuilder.AddQueryParam("search_string", string.Format(query, args));
            }

            if (!Settings.RankedOnly)
            {
                requestBuilder.AddQueryParam("ranked", "0");
            }

            requestBuilder.AddQueryParam("category", "18;41");
            requestBuilder.AddQueryParam("limit", "100");
            requestBuilder.AddQueryParam("token", _tokenProvider.GetToken(Settings));
            requestBuilder.AddQueryParam("format", "json_extended");
            requestBuilder.AddQueryParam("app_id", "Sonarr");

            yield return new IndexerRequest(requestBuilder.Build());
        }
コード例 #7
0
ファイル: SabnzbdProxy.cs プロジェクト: mike-tesch/Sonarr
        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;
        }
コード例 #8
0
ファイル: SabnzbdProxy.cs プロジェクト: mike-tesch/Sonarr
        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;
        }
コード例 #9
0
        private IEnumerable<IndexerRequest> GetRequest(TorrentQuery query)
        {
            var request = new HttpRequestBuilder(Settings.BaseUrl)
                .Resource("/api/torrents")
                .Build();

            request.Method = HttpMethod.POST;
            const string appJson = "application/json";
            request.Headers.Accept = appJson;
            request.Headers.ContentType = appJson;

            query.Username = Settings.Username;
            query.Passkey = Settings.ApiKey;

            request.SetContent(query.ToJson());

            yield return new IndexerRequest(request);
        }
コード例 #10
0
 protected void SetRootBuilder(HttpRequestBuilder rootBuilder)
 {
     _rootBuilder = rootBuilder.Clone();
 }
コード例 #11
0
 public HttpRequestBuilderFactory(HttpRequestBuilder rootBuilder)
 {
     SetRootBuilder(rootBuilder);
 }
コード例 #12
0
        private HttpRequestBuilder BuildRequest(TransmissionSettings settings)
        {
            var requestBuilder = new HttpRequestBuilder(settings.UseSsl, settings.Host, settings.Port, settings.UrlBase)
                .Resource("rpc")
                .Accept(HttpAccept.Json);

            requestBuilder.LogResponseContent = true;
            requestBuilder.NetworkCredential = new NetworkCredential(settings.Username, settings.Password);
            requestBuilder.AllowAutoRedirect = false;

            return requestBuilder;
        }
コード例 #13
0
        private void AuthenticateClient(HttpRequestBuilder requestBuilder, TransmissionSettings settings, bool reauthenticate = false)
        {
            var authKey = string.Format("{0}:{1}", requestBuilder.BaseUrl, settings.Password);

            var sessionId = _authSessionIDCache.Find(authKey);

            if (sessionId == null || reauthenticate)
            {
                _authSessionIDCache.Remove(authKey);

                var authLoginRequest = BuildRequest(settings).Build();
                authLoginRequest.SuppressHttpError = true;

                var response = _httpClient.Execute(authLoginRequest);
                if (response.StatusCode == HttpStatusCode.MovedPermanently)
                {
                    var url = response.Headers.GetSingleValue("Location");

                    throw new DownloadClientException("Remote site redirected to " + url);
                }
                else if (response.StatusCode == HttpStatusCode.Conflict)
                {
                    sessionId = response.Headers.GetSingleValue("X-Transmission-Session-Id");

                    if (sessionId == null)
                    {
                        throw new DownloadClientException("Remote host did not return a Session Id.");
                    }
                }
                else
                {
                    throw new DownloadClientAuthenticationException("Failed to authenticate with Transmission.");
                }

                _logger.Debug("Transmission authentication succeeded.");

                _authSessionIDCache.Set(authKey, sessionId);
            }

            requestBuilder.SetHeader("X-Transmission-Session-Id", sessionId);
        }
コード例 #14
0
        private void AuthenticateClient(HttpRequestBuilder requestBuilder, UTorrentSettings settings, bool reauthenticate = false)
        {
            var authKey = string.Format("{0}:{1}", requestBuilder.BaseUrl, settings.Password);

            var cookies = _authCookieCache.Find(authKey);
            var authToken = _authTokenCache.Find(authKey);

            if (cookies == null || authToken == null || reauthenticate)
            {
                _authCookieCache.Remove(authKey);
                _authTokenCache.Remove(authKey);

                var authLoginRequest = BuildRequest(settings).Resource("/gui/token.html").Build();

                HttpResponse response;
                try
                {
                    response = _httpClient.Execute(authLoginRequest);
                    _logger.Debug("uTorrent authentication succeeded.");

                    var xmlDoc = new System.Xml.XmlDocument();
                    xmlDoc.LoadXml(response.Content);

                    authToken = xmlDoc.FirstChild.FirstChild.InnerText;
                }
                catch (HttpException ex)
                {
                    if (ex.Response.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        _logger.Debug("uTorrent authentication failed.");
                        throw new DownloadClientAuthenticationException("Failed to authenticate with uTorrent.");
                    }

                    throw new DownloadClientException("Unable to connect to uTorrent, please check your settings", ex);
                }
                catch (WebException ex)
                {
                    throw new DownloadClientException("Unable to connect to uTorrent, please check your settings", ex);
                }

                cookies = response.GetCookies();

                _authCookieCache.Set(authKey, cookies);
                _authTokenCache.Set(authKey, authToken);
            }

            requestBuilder.SetCookies(cookies);
            requestBuilder.AddPrefixQueryParam("token", authToken, true);
        }
コード例 #15
0
 protected void SetRootBuilder(HttpRequestBuilder rootBuilder)
 {
     _rootBuilder = rootBuilder.Clone();
 }
コード例 #16
0
        private HttpRequestBuilder BuildRequest(UTorrentSettings settings)
        {
            var requestBuilder = new HttpRequestBuilder(false, settings.Host, settings.Port)
                .Resource("/gui/")
                .KeepAlive()
                .SetHeader("Cache-Control", "no-cache")
                .Accept(HttpAccept.Json);

            requestBuilder.LogResponseContent = true;
            requestBuilder.NetworkCredential = new NetworkCredential(settings.Username, settings.Password);

            return requestBuilder;
        }
コード例 #17
0
 public HttpRequestBuilderFactory(HttpRequestBuilder rootBuilder)
 {
     SetRootBuilder(rootBuilder);
 }