diff --git a/src/main/java/tokyo/northside/oxfordapi/OxfordClient.java b/src/main/java/tokyo/northside/oxfordapi/OxfordClient.java index 3b7ba36..5502f9f 100644 --- a/src/main/java/tokyo/northside/oxfordapi/OxfordClient.java +++ b/src/main/java/tokyo/northside/oxfordapi/OxfordClient.java @@ -24,9 +24,6 @@ * @author Hiroshi Miura */ public class OxfordClient extends OxfordClientBase { - - private static final String BASE_URL = "https://od-api.oxforddictionaries.com/"; - private final String endpointUrl; private final String appId; private final String appKey; @@ -35,22 +32,10 @@ public class OxfordClient extends OxfordClientBase { * * @param appId AppId of the OD API credentials. * @param appKey AppKey of the OD API credentials. - * @param baseUrl base URL of the OD API v2. */ - public OxfordClient(final String appId, final String appKey, final String baseUrl) { + public OxfordClient(final String appId, final String appKey) { this.appId = appId; this.appKey = appKey; - endpointUrl = baseUrl; - } - - /** - * Construcotr with default v2 URL. - * - * @param appId AppId of the OD API credentials. - * @param appKey AppKey of the OD API credentials. - */ - public OxfordClient(final String appId, final String appKey) { - this(appId, appKey, BASE_URL); } @Override @@ -76,7 +61,7 @@ public Map> queryTranslations(final Collection word public List queryTranslation(final String word, final String source, final String target) throws OxfordClientException { Set fields = new HashSet<>(Arrays.asList("definitions", "pronunciations")); - RequestFactory f = new RequestFactory(appId, appKey, endpointUrl) + RequestFactory f = new RequestFactory(appId, appKey) .setType(RequestFactory.QueryType.TRANSLATIONS) .setSourceLanguage(source) .setTargetLanguage(target) @@ -107,7 +92,7 @@ public Map> queryEntries(final Collection words, fi @Override public List queryEntry(final String word, final String language, final boolean strict) throws OxfordClientException { - RequestFactory f = new RequestFactory(appId, appKey, endpointUrl) + RequestFactory f = new RequestFactory(appId, appKey) .setType(RequestFactory.QueryType.ENTRIES) .setLanguage(language) .setQueryWord(word) diff --git a/src/main/java/tokyo/northside/oxfordapi/OxfordThreadClient.java b/src/main/java/tokyo/northside/oxfordapi/OxfordThreadClient.java index a70f4c2..00bba81 100644 --- a/src/main/java/tokyo/northside/oxfordapi/OxfordThreadClient.java +++ b/src/main/java/tokyo/northside/oxfordapi/OxfordThreadClient.java @@ -23,7 +23,6 @@ * @author Hiroshi Miura */ public class OxfordThreadClient extends OxfordClientBase { - private static final String ENDPOINT_URL = "https://od-api.oxforddictionaries.com/api/v2/"; private final String appId; private final String appKey; @@ -42,7 +41,7 @@ public Map> queryEntries(final Collection words, fi .build()) { final List requests = new ArrayList<>(); for (final String query : words) { - RequestFactory factory = new RequestFactory(appId, appKey, ENDPOINT_URL); + RequestFactory factory = new RequestFactory(appId, appKey); factory.setQueryWord(query).setLanguage(language).setStrictMatch(strict); requests.add(factory); } @@ -63,7 +62,7 @@ public Map> queryTranslations(final Collection word .build()) { List requests = new ArrayList<>(); for (final String query : words) { - RequestFactory factory = new RequestFactory(appId, appKey, ENDPOINT_URL); + RequestFactory factory = new RequestFactory(appId, appKey); factory.setQueryWord(query).setSourceLanguage(source).setTargetLanguage(target); requests.add(factory); } diff --git a/src/main/java/tokyo/northside/oxfordapi/RequestFactory.java b/src/main/java/tokyo/northside/oxfordapi/RequestFactory.java index ddf3cdc..73a1eb4 100644 --- a/src/main/java/tokyo/northside/oxfordapi/RequestFactory.java +++ b/src/main/java/tokyo/northside/oxfordapi/RequestFactory.java @@ -17,8 +17,8 @@ public enum QueryType { TRANSLATIONS, } + private static final String ENDPOINT_URL = "https://od-api.oxforddictionaries.com"; private static final String BASE_PATH = "/api/v2/"; - private final String endpointUrl; private final String appId; private final String appKey; @@ -39,12 +39,7 @@ public enum QueryType { */ private Set fields; - public RequestFactory(final String appId, final String appKey, final String endpointHost) { - if (endpointHost.endsWith("/")) { - this.endpointUrl = endpointHost.substring(0, endpointHost.length() - 1); - } else { - this.endpointUrl = endpointHost; - } + public RequestFactory(final String appId, final String appKey) { this.appId = appId; this.appKey = appKey; strictMatch = "false"; @@ -159,7 +154,7 @@ public String getUrl() throws OxfordClientException { if (queryWord == null) { throw new OxfordClientException("Query word is mandatory"); } - return String.format("%s%s?%s", endpointUrl, getPath(), getQueryString()); + return String.format("%s%s?%s", ENDPOINT_URL, getPath(), getQueryString()); } public String getQueryWord() { diff --git a/src/test/groovy/tokyo/northside/oxfordapi/OxfordClientTest.groovy b/src/test/groovy/tokyo/northside/oxfordapi/OxfordClientTest.groovy index f9b4926..ef669fb 100644 --- a/src/test/groovy/tokyo/northside/oxfordapi/OxfordClientTest.groovy +++ b/src/test/groovy/tokyo/northside/oxfordapi/OxfordClientTest.groovy @@ -6,13 +6,12 @@ import tokyo.northside.oxfordapi.dtd.Result import static org.junit.Assert.assertEquals class OxfordClientTest { - def ENDPOINT_URL = "https://od-api.oxforddictionaries.com/" def appId = System.properties.getProperty("oxfordId") def appKey = System.properties.getProperty("oxfordKey") @Test void simpleQueryTest() { - OxfordClient client = new OxfordClient(appId, appKey, ENDPOINT_URL) + OxfordClient client = new OxfordClient(appId, appKey) List result = client.queryEntry("ace", "en-GB", true) assertEquals(2, result.size()) client.close() @@ -20,7 +19,7 @@ class OxfordClientTest { @Test void queryResultTest() { - OxfordClient client = new OxfordClient(appId, appKey, ENDPOINT_URL) + OxfordClient client = new OxfordClient(appId, appKey) List result = client.getDefinitions(Collections.singletonList("ace"), "en-GB", true) assertEquals(5, result.size()) client.close()