コード例 #1
0
ファイル: MylarV3Proxy.cs プロジェクト: bakerboy448/Prowlarr
        public List<MylarIndexer> GetIndexers(MylarSettings settings)
        {
            var request = BuildRequest(settings, "/api", "listProviders", HttpMethod.Get);

            var response = Execute<MylarIndexerResponse>(request);

            if (!response.Success)
            {
                throw new MylarException(string.Format("Mylar Error - Code {0}: {1}", response.Error.Code, response.Error.Message));
            }

            var indexers = new List<MylarIndexer>();

            var torIndexers = response.Data.Torznabs;
            torIndexers.ForEach(i => i.Type = MylarProviderType.Torznab);

            var nzbIndexers = response.Data.Newznabs;
            nzbIndexers.ForEach(i => i.Type = MylarProviderType.Newznab);

            indexers.AddRange(torIndexers);
            indexers.AddRange(nzbIndexers);
            indexers.ForEach(i => i.Altername = i.Name);

            return indexers;
        }
コード例 #2
0
ファイル: MylarV3Proxy.cs プロジェクト: bakerboy448/Prowlarr
        private HttpRequest BuildRequest(MylarSettings settings, string resource, string command, HttpMethod method, Dictionary<string, string> parameters = null)
        {
            var baseUrl = settings.BaseUrl.TrimEnd('/');

            var requestBuilder = new HttpRequestBuilder(baseUrl).Resource(resource)
                .AddQueryParam("cmd", command)
                .AddQueryParam("apikey", settings.ApiKey);

            if (parameters != null)
            {
                foreach (var param in parameters)
                {
                    requestBuilder.AddQueryParam(param.Key, param.Value);
                }
            }

            var request = requestBuilder.Build();

            request.Headers.ContentType = "application/json";

            request.Method = method;
            request.AllowAutoRedirect = true;

            return request;
        }
コード例 #3
0
ファイル: MylarV3Proxy.cs プロジェクト: bakerboy448/Prowlarr
        public ValidationFailure TestConnection(MylarSettings settings)
        {
            try
            {
                var status = GetStatus(settings);

                if (!status.Success)
                {
                    return new ValidationFailure("ApiKey", status.Error.Message);
                }

                var indexers = GetIndexers(settings);
            }
            catch (HttpException ex)
            {
                _logger.Error(ex, "Unable to send test message");
                return new ValidationFailure("BaseUrl", "Unable to complete application test");
            }
            catch (MylarException ex)
            {
                _logger.Error(ex, "Connection test failed");
                return new ValidationFailure("", ex.Message);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Unable to send test message");
                return new ValidationFailure("", "Unable to send test message");
            }

            return null;
        }
コード例 #4
0
ファイル: MylarV3Proxy.cs プロジェクト: bakerboy448/Prowlarr
        public void RemoveIndexer(string indexerName, MylarProviderType indexerType, MylarSettings settings)
        {
            var parameters = new Dictionary<string, string>
            {
                { "name", indexerName },
                { "providertype", indexerType.ToString().ToLower() }
            };

            var request = BuildRequest(settings, "/api", "delProvider", HttpMethod.Get, parameters);
            CheckForError(Execute<MylarStatus>(request));
        }
コード例 #5
0
ファイル: MylarV3Proxy.cs プロジェクト: bakerboy448/Prowlarr
        public MylarIndexer AddIndexer(MylarIndexer indexer, MylarSettings settings)
        {
            var parameters = new Dictionary<string, string>
            {
                { "name", indexer.Name },
                { "providertype", indexer.Type.ToString().ToLower() },
                { "host", indexer.Host },
                { "prov_apikey", indexer.Apikey },
                { "enabled", indexer.Enabled.ToString().ToLower() },
                { "categories", indexer.Categories }
            };

            var request = BuildRequest(settings, "/api", "addProvider", HttpMethod.Get, parameters);
            CheckForError(Execute<MylarStatus>(request));
            return indexer;
        }
コード例 #6
0
ファイル: MylarV3Proxy.cs プロジェクト: bakerboy448/Prowlarr
        public MylarIndexer GetIndexer(string indexerName, MylarProviderType indexerType, MylarSettings settings)
        {
            var indexers = GetIndexers(settings);

            return indexers.SingleOrDefault(i => i.Name == indexerName && i.Type == indexerType);
        }
コード例 #7
0
ファイル: MylarV3Proxy.cs プロジェクト: bakerboy448/Prowlarr
 public MylarStatus GetStatus(MylarSettings settings)
 {
     var request = BuildRequest(settings, "/api", "getVersion", HttpMethod.Get);
     return Execute<MylarStatus>(request);
 }