示例#1
0
        private IEnumerable<IndexerRequest> GetPagedRequests(string mode, int? tvdbId, string query, params object[] args)
        {
            var httpRequest = new HttpRequest(Settings.BaseUrl + "/pubapi_v2.php", HttpAccept.Json);

            httpRequest.AddQueryParam("mode", mode);

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

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

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

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

            yield return new IndexerRequest(httpRequest);
        }
        private NewznabCapabilities FetchCapabilities(NewznabSettings indexerSettings)
        {
            var capabilities = new NewznabCapabilities();

            var url = string.Format("{0}/api?t=caps", indexerSettings.Url.TrimEnd('/'));

            if (indexerSettings.ApiKey.IsNotNullOrWhiteSpace())
            {
                url += "&apikey=" + indexerSettings.ApiKey;
            }

            var request = new HttpRequest(url, HttpAccept.Rss);

            try
            {
                var response = _httpClient.Get(request);

                capabilities = ParseCapabilities(response);
            }
            catch (Exception ex)
            {
                _logger.DebugException(string.Format("Failed to get capabilities from {0}: {1}", indexerSettings.Url, ex.Message), ex);
            }

            return capabilities;
        }
        protected override void Apply(HttpRequest request)
        {
            base.Apply(request);

            request.Headers.ContentType = JsonRpcContentType;

            var parameterData = new object[JsonParameters.Count];
            var parameterSummary = new string[JsonParameters.Count];

            for (var i = 0; i < JsonParameters.Count; i++)
            {
                ConvertParameter(JsonParameters[i], out parameterData[i], out parameterSummary[i]);
            }

            var message = new Dictionary<string, object>();
            message["jsonrpc"] = "2.0";
            message["method"] = JsonMethod;
            message["params"] = parameterData;
            message["id"] = CreateNextId();

            request.SetContent(message.ToJson());

            if (request.ContentSummary == null)
            {
                request.ContentSummary = string.Format("{0}({1})", JsonMethod, string.Join(", ", parameterSummary));
            }
        }
 public TooManyRequestsException(HttpRequest request, HttpResponse response)
     : base(request, response)
 {
     if (response.Headers.ContainsKey("Retry-After"))
     {
         RetryAfter = TimeSpan.FromSeconds(int.Parse(response.Headers["Retry-After"].ToString()));
     }
 }
示例#5
0
        public void should_add_single_segment_url_segments(string url, string result)
        {
            var request = new HttpRequest(url);

            request.AddSegment("seg", "dir");

            request.Url.Should().Be(result);
        }
        public HttpRequest PreRequest(HttpRequest request)
        {
            if (request.Url.Host == "torcache.net" && request.UriBuilder.Query.IsNotNullOrWhiteSpace())
            {
                request.UriBuilder.Query = string.Empty;
            }

            return request;
        }
示例#7
0
        private String ProcessRequest(HttpRequest request, MediaBrowserSettings settings)
        {
            request.Headers.Add("X-MediaBrowser-Token", settings.ApiKey);

            var response = _httpClient.Post(request);
            _logger.Trace("Response: {0}", response.Content);

            CheckForError(response);

            return response.Content;
        }
        public HttpRequest PreRequest(HttpRequest request)
        {
            // torcache behaves strangely when it has query params and/or no Referer or browser User-Agent.
            // It's a bit vague, and we don't need the query params. So we remove the query params and set a Referer to be safe.
            if (request.Url.Host == "torcache.net")
            {
                request.Url = request.Url.SetQuery(string.Empty);
                request.Headers.Add("Referer", request.Url.Scheme + @"://torcache.net/");
            }

            return request;
        }
示例#9
0
        public TooManyRequestsException(HttpRequest request, HttpResponse response)
            : base(request, response)
        {
            if (response.Headers.ContainsKey("Retry-After"))
            {
                var retryAfter = response.Headers["Retry-After"].ToString();
                int seconds;
                DateTime date;

                if (int.TryParse(retryAfter, out seconds))
                {
                    RetryAfter = TimeSpan.FromSeconds(seconds);
                }
                else if (DateTime.TryParse(retryAfter, out date))
                {
                    RetryAfter = date.ToUniversalTime() - DateTime.UtcNow;
                }
            }
        }
示例#10
0
 public HttpException(HttpRequest request, HttpResponse response)
     : base(string.Format("HTTP request failed: [{0}:{1}] [{2}] at [{3}]", (int)response.StatusCode, response.StatusCode, request.Method, request.Url.ToString()))
 {
     Request = request;
     Response = response;
 }
示例#11
0
 public IndexerRequest(HttpRequest httpRequest)
 {
     HttpRequest = httpRequest;
 }
示例#12
0
 public IndexerRequest(string url, HttpAccept httpAccept)
 {
     HttpRequest = new HttpRequest(url, httpAccept);
 }
示例#13
0
 public void shouldnt_add_value_for_nonexisting_segment()
 {
     var request = new HttpRequest("http://host/{seg}/some");
     Assert.Throws<InvalidOperationException>(() => request.AddSegment("seg2", "dir"));
 }