User Functions
Additional functions that are available
Register
Register a new user (although in general NewzNab based indexers are invitation only). An email address is required, and a username and password is then returned.
import java.io.IOException;
import synapticloop.newznab.api.NewzNabApi;
import synapticloop.newznab.api.exception.NewzNabApiException;
import synapticloop.newznab.api.response.RegistrationResponse;
public class Register {
public static void main(String[] args) throws IOException, NewzNabApiException {
NewzNabApi newzNabApi = new NewzNabApi("YOUR_API_URL", "YOUR_API_KEY");
RegistrationResponse registrationResponse = newzNabApi.register("something@example.com");
System.out.println("Congratulations, you have just registered with the following details:");
System.out.println(" username: " + registrationResponse.getUsername());
System.out.println(" password: " + registrationResponse.getPassword());
System.out.println(" api key: " + registrationResponse.getApiKey());
}
}
see Register.java
User details
Retrieve your user details, which include the membership level, the number of grabs per day and when the user was created (i.e. joined).
import java.io.IOException;
import synapticloop.newznab.api.NewzNabApi;
import synapticloop.newznab.api.exception.NewzNabApiException;
import synapticloop.newznab.api.response.UserResponse;
public class User {
public static void main(String[] args) throws IOException, NewzNabApiException {
NewzNabApi newzNabApi = new NewzNabApi("YOUR_API_URL", "YOUR_API_KEY");
UserResponse userResponse = newzNabApi.getUser("your_username");
System.out.println("username: " + userResponse.getUsername());
System.out.println(" role: " + userResponse.getRole());
System.out.println(" joined: " + userResponse.getCreatedDate());
System.out.println(" number of api requests allowed per day: " + userResponse.getNumApiRequests());
System.out.println("number of download requests allowed per day: " + userResponse.getNumDownloadRequests());
System.out.println(" number of grabbed releases: " + userResponse.getNumGrabs());
System.out.println("has a console view?: " + userResponse.getHasConsoleView());
System.out.println(" has a movie view?: " + userResponse.getHasMovieView());
System.out.println(" has a music view?: " + userResponse.getHasMusicView());
}
}
see User.java
Capabilities
Determine the capabilities of the NewzNab indexer, which may vary from indexer to indexer.
import java.io.IOException;
import java.util.List;
import synapticloop.newznab.api.NewzNabApi;
import synapticloop.newznab.api.exception.NewzNabApiException;
import synapticloop.newznab.api.response.CapabilitiesResponse;
import synapticloop.newznab.api.response.model.Genre;
import synapticloop.newznab.api.response.model.Group;
import synapticloop.newznab.api.response.model.attributes.GenreAttributes;
import synapticloop.newznab.api.response.model.attributes.GroupAttributes;
public class Capabilities {
public static void main(String[] args) throws IOException, NewzNabApiException {
NewzNabApi newzNabApi = new NewzNabApi("YOUR_API_URL", "YOUR_API_KEY");
CapabilitiesResponse capabilitiesResponse = newzNabApi.getCapabilities();
// test whether the NewzNab indexer has specific searches
capabilitiesResponse.getHasAudioSearch();
capabilitiesResponse.getHasMovieSearch();
capabilitiesResponse.getHasTvSearch();
capabilitiesResponse.getHasBookSearch();
// get a list of the genres that the indexer has
List genres = capabilitiesResponse.getGenres();
for (Genre genre : genres) {
List genreAttributes = genre.getGenreAttributes();
for (GenreAttributes genreAttributesInner : genreAttributes) {
genreAttributesInner.getName(); // the name of the genre
genreAttributesInner.getCategory(); // the category which this genre relates to
}
}
// get a list of the groups
List groups = capabilitiesResponse.getGroups();
for (Group group : groups) {
List groupAttributes = group.getGroupAttributes();
for (GroupAttributes groupAttributesInner : groupAttributes) {
groupAttributesInner.getName(); // the name of the usenet group
groupAttributesInner.getLastUpdate(); // when this group was last updated
}
}
// registration options
capabilitiesResponse.getIsRegistrationAvailable(); // is registration available
capabilitiesResponse.getIsRegistrationOpen(); // is registration open
capabilitiesResponse.getDefaultResultsLimit(); // the default number of results that are returned through a search or a feed
capabilitiesResponse.getMaxResultsLimit(); // the maximum results that can be returned through a search or a feed
}
}
see Capabilities.java
Cart Utilities
The API can list the cart contents, add an item to the cart, and delete an item.
import java.io.IOException;
import java.util.List;
import synapticloop.newznab.api.NewzNabApi;
import synapticloop.newznab.api.exception.NewzNabApiException;
import synapticloop.newznab.api.response.FeedResponse;
import synapticloop.newznab.api.response.model.FeedItem;
public class Cart {
public static void main(String[] args) throws IOException, NewzNabApiException {
NewzNabApi newzNabApi = new NewzNabApi("YOUR_API_URL", "YOUR_API_KEY");
FeedResponse feedResponse = newzNabApi.getFeedForCart();
List feedItems = feedResponse.getFeedItems();
for (FeedItem feedItem : feedItems) {
System.out.println("You have an item in the cart: " + feedItem.getTitle());
}
// you can add something to the cart
newzNabApi.cartAdd("some-guid");
// and delete it again
newzNabApi.cartDelete("some-guid");
}
}
see Cart.java