From 60519a43d6326810661e10c27c34f2602d0f959c Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 8 May 2016 23:24:15 +0800 Subject: [PATCH] Add convenience API --- source/net/filebot/web/TheTVDBClient.java | 19 ++++++++++++------- test/net/filebot/web/TheTVDBClientTest.java | 13 ++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/source/net/filebot/web/TheTVDBClient.java b/source/net/filebot/web/TheTVDBClient.java index 1e791a21..a23903a9 100644 --- a/source/net/filebot/web/TheTVDBClient.java +++ b/source/net/filebot/web/TheTVDBClient.java @@ -98,11 +98,6 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor } } - protected String[] languages() throws Exception { - Object response = requestJson("languages", Locale.ROOT, Cache.ONE_MONTH); - return streamJsonObjects(response, "data").map(it -> getString(it, "abbreviation")).toArray(String[]::new); - } - protected List search(String path, Map query, Locale locale, Duration expirationTime) throws Exception { Object json = requestJson(path + "?" + encodeParameters(query, true), locale, expirationTime); @@ -244,7 +239,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor @Override public List getArtwork(int id, String category, Locale locale) throws Exception { - Object json = requestJson("series/" + id + "/images/query?keyType=" + category, locale, Cache.ONE_WEEK); + Object json = requestJson("series/" + id + "/images/query?keyType=" + category, locale, Cache.ONE_MONTH); return streamJsonObjects(json, "data").map(it -> { try { @@ -270,8 +265,18 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor try { return new URL("http://thetvdb.com/banners/" + path); } catch (Exception e) { - throw new IllegalArgumentException(Objects.toString(path)); + throw new IllegalArgumentException(path); } } + public List getLanguages() throws Exception { + Object response = requestJson("languages", Locale.ROOT, Cache.ONE_MONTH); + return streamJsonObjects(response, "data").map(it -> getString(it, "abbreviation")).collect(toList()); + } + + public List> getActors(int id, Locale locale) throws Exception { + Object response = requestJson("series/" + id + "/actors", locale, Cache.ONE_MONTH); + return streamJsonObjects(response, "data").map(it -> asMap(it)).collect(toList()); + } + } diff --git a/test/net/filebot/web/TheTVDBClientTest.java b/test/net/filebot/web/TheTVDBClientTest.java index 16e1f75b..901a3d66 100644 --- a/test/net/filebot/web/TheTVDBClientTest.java +++ b/test/net/filebot/web/TheTVDBClientTest.java @@ -1,6 +1,5 @@ package net.filebot.web; -import static java.util.Arrays.*; import static org.junit.Assert.*; import java.util.List; @@ -16,12 +15,6 @@ public class TheTVDBClientTest { SearchResult wonderfalls = new SearchResult(78845, "Wonderfalls"); SearchResult firefly = new SearchResult(78874, "Firefly"); - @Test - public void languages() throws Exception { - String[] languages = thetvdb.languages(); - assertEquals("[zh, en, sv, no, da, fi, nl, de, it, es, fr, pl, hu, el, tr, ru, he, ja, pt, cs, sl, hr, ko]", asList(languages).toString()); - } - @Test public void search() throws Exception { // test default language and query escaping (blanks) @@ -150,4 +143,10 @@ public class TheTVDBClientTest { assertEquals(8.0, i.getRating(), 1.0); } + @Test + public void getLanguages() throws Exception { + List languages = thetvdb.getLanguages(); + assertEquals("[zh, en, sv, no, da, fi, nl, de, it, es, fr, pl, hu, el, tr, ru, he, ja, pt, cs, sl, hr, ko]", languages.toString()); + } + }