SHARE
TWEET

OMDbResource

DekkerBass May 22nd, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top