WikiClient { public PageRevision getMostRecentRevision(String... titles) throws Exception { URL url = new URL(entryPoint + "/w/api.php?format=json&action=query&prop=revisions&rvprop=user|timestamp&titles=" + encode(Joiner.on("|").join(titles), "UTF-8") ); String response = readURL(url); List<PageRevision> revisions = extractRevisions(response); Collections.sort(revisions, new Comparator<PageRevision>() { @Override public int compare(final PageRevision o1, final PageRevision o2) { return o2.date.compareTo(o1.date); } }); return revisions.get(0); } WikiClient(final String entryPoint); PageRevision getMostRecentRevision(String... titles); static final SimpleDateFormat DATE_FORMAT; }
@Test public void shouldWork() throws Exception { whenHttp(server).match( get("/w/api.php"), parameter("titles", "Title 1|Title 2") ).then(resourceContent("revisions.json")); String entryPoint = "http: PageRevision revision = new WikiClient(entryPoint).getMostRecentRevision("Title 1", "Title 2"); assertThat(revision.name, is("Title 2")); }