Java tutorial
/** * NZBMatrixLib provides an intuitive java interface library to interact with the API provided by (http://www.nzbmatrix.com) * * The author(s) of NZBMatrixLib are in NO WAY associated with (http://nzbmatrix.com) or its affiliates * * If you would like to contribute to this library, find us at (https://github.com/TheBigS/NZBMatrixLib) * * Copyright (C) 2010 Steven King * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.text.ParseException; import org.apache.http.client.ClientProtocolException; import com.github.thebigs.nzbmatrixapi.ApiCredentials; import com.github.thebigs.nzbmatrixapi.NZBMatrixApi; import com.github.thebigs.nzbmatrixapi.NZBMatrixApiException; import com.github.thebigs.nzbmatrixapi.response.DirectDownloadResponse; public class GetDirectDownload { private static String USER_NAME = "<YOUR USER NAME>"; private static String API_KEY = "<YOUR API KEY>"; /** * @param args * @throws ParseException */ public static void main(final String[] args) throws ParseException { // you can either set the 2 strings above, or pass them in to this program if (args.length == 2) { USER_NAME = args[0]; API_KEY = args[1]; } // make sure the credentials got set if (USER_NAME.equals("<YOUR USER NAME>") || API_KEY.equals("<YOUR API KEY>")) { System.err.println( "You must either edit this example file and put in your username and apikey OR pass them in as program arguments"); System.exit(1); } final ApiCredentials credentials = new ApiCredentials(USER_NAME, API_KEY); final NZBMatrixApi api = new NZBMatrixApi(credentials); try { // makes the request to the nzbMatrixAPI for a direct download of a particular post id final DirectDownloadResponse directDownload = api.getDirectDownload(314694); // save the nzb file to disk final String fileName = directDownload.getSuggestedFileName(); final BufferedWriter out = new BufferedWriter(new FileWriter(fileName)); out.write(directDownload.getNzbFileContents()); out.close(); System.out.println("Nzb File Saved As: " + fileName); } catch (final ClientProtocolException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } catch (final NZBMatrixApiException e) { e.printStackTrace(); } } }