Advertisement
DekkerBass

OMDbResource

May 22nd, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package aiss.model.resources;
  2.  
  3. import java.io.UnsupportedEncodingException;
  4. import java.net.URLEncoder;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7.  
  8. import org.restlet.resource.ClientResource;
  9.  
  10. import aiss.model.omdb.MovieSearch;
  11.  
  12. public class OMDbResource {
  13.  
  14.     private static final String OMDB_API_KEY = "a00dffb4"; // TODO: Change this API KEY for your personal Key
  15.     private static final Logger log = Logger.getLogger(OMDbResource.class.getName());
  16.  
  17.     public MovieSearch getMovies(String query) throws UnsupportedEncodingException {
  18.         String keyword = URLEncoder.encode(query, "UTF-8");
  19.         // TODO: Perform search in OMDb
  20.  
  21.         String uri = "http://www.omdbapi.com/?apikey=" + OMDB_API_KEY + "&s=" + keyword;
  22.         log.log(Level.FINE, "OMDB URI: " + uri);
  23.  
  24.         // http://www.omdbapi.com/?t=Dumbo&y=2019&plot=full
  25.         // http://www.omdbapi.com/?apikey=[yourkey]&
  26.  
  27.         ClientResource cr = new ClientResource(uri);
  28.         MovieSearch movieSearch = cr.get(MovieSearch.class);
  29.         return movieSearch;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement