public List <LazyLibrarianIndexer> GetIndexers(LazyLibrarianSettings settings) { var request = BuildRequest(settings, "/api", "listNabProviders", HttpMethod.Get); var response = Execute <LazyLibrarianIndexerResponse>(request); if (!response.Success) { throw new LazyLibrarianException(string.Format("LazyLibrarian Error - Code {0}: {1}", response.Error.Code, response.Error.Message)); } var indexers = new List <LazyLibrarianIndexer>(); var torIndexers = response.Data.Torznabs; torIndexers.ForEach(i => i.Type = LazyLibrarianProviderType.Torznab); var nzbIndexers = response.Data.Newznabs; nzbIndexers.ForEach(i => i.Type = LazyLibrarianProviderType.Newznab); indexers.AddRange(torIndexers); indexers.AddRange(nzbIndexers); indexers.ForEach(i => i.Altername = i.Name); return(indexers); }
private HttpRequest BuildRequest(LazyLibrarianSettings 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); }
public ValidationFailure TestConnection(LazyLibrarianSettings 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 (LazyLibrarianException 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); }
public LazyLibrarianIndexer AddIndexer(LazyLibrarianIndexer indexer, LazyLibrarianSettings 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 <LazyLibrarianStatus>(request)); return(indexer); }
public void RemoveIndexer(string indexerName, LazyLibrarianProviderType indexerType, LazyLibrarianSettings settings) { var parameters = new Dictionary <string, string> { { "name", indexerName }, { "providertype", indexerType.ToString().ToLower() } }; var request = BuildRequest(settings, "/api", "delProvider", HttpMethod.Get, parameters); CheckForError(Execute <LazyLibrarianStatus>(request)); }
public LazyLibrarianIndexer GetIndexer(string indexerName, LazyLibrarianProviderType indexerType, LazyLibrarianSettings settings) { var indexers = GetIndexers(settings); return(indexers.SingleOrDefault(i => i.Name == indexerName && i.Type == indexerType)); }
public LazyLibrarianStatus GetStatus(LazyLibrarianSettings settings) { var request = BuildRequest(settings, "/api", "getVersion", HttpMethod.Get); return(Execute <LazyLibrarianStatus>(request)); }