updated client

This commit is contained in:
Tony Tam 2014-06-10 08:22:40 -07:00
parent 64604124c9
commit 7d4c10043d
8 changed files with 252 additions and 73 deletions

View File

@ -178,6 +178,17 @@
<version>${jackson-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${jodatime-version}</version>
<scope>compile</scope>
</dependency>
<!-- test dependencies -->
<dependency>
@ -203,6 +214,7 @@
<properties>
<jersey-version>1.7</jersey-version>
<jackson-version>2.1.4</jackson-version>
<jodatime-version>2.3</jodatime-version>
<scala-version>2.9.1-1</scala-version>
<junit-version>4.8.1</junit-version>
<maven-plugin-version>1.0.0</maven-plugin-version>

View File

@ -2,10 +2,12 @@ package com.wordnik.client.api;
import com.wordnik.client.common.ApiException;
import com.wordnik.client.common.ApiInvoker;
import com.wordnik.client.model.User;
import com.wordnik.client.model.WordList;
import com.wordnik.client.model.ApiTokenStatus;
import com.wordnik.client.model.AuthenticationToken;
import java.io.File;
import java.util.*;
public class AccountApi {
@ -35,13 +37,17 @@ public class AccountApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(password)))
queryParams.put("password", String.valueOf(password));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (AuthenticationToken) ApiInvoker.deserialize(response, "", AuthenticationToken.class);
}
@ -68,11 +74,15 @@ public class AccountApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, formParams, contentType);
if(response != null){
return (AuthenticationToken) ApiInvoker.deserialize(response, "", AuthenticationToken.class);
}
@ -99,16 +109,20 @@ public class AccountApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(skip)))
queryParams.put("skip", String.valueOf(skip));
if(!"null".equals(String.valueOf(limit)))
queryParams.put("limit", String.valueOf(limit));
headerParams.put("auth_token", auth_token);
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (List<WordList>) ApiInvoker.deserialize(response, "List", WordList.class);
}
@ -131,12 +145,16 @@ public class AccountApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
headerParams.put("api_key", api_key);
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (ApiTokenStatus) ApiInvoker.deserialize(response, "", ApiTokenStatus.class);
}
@ -163,12 +181,16 @@ public class AccountApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
headerParams.put("auth_token", auth_token);
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (User) ApiInvoker.deserialize(response, "", User.class);
}

View File

@ -2,6 +2,7 @@ package com.wordnik.client.api;
import com.wordnik.client.common.ApiException;
import com.wordnik.client.common.ApiInvoker;
import com.wordnik.client.model.FrequencySummary;
import com.wordnik.client.model.Bigram;
import com.wordnik.client.model.WordObject;
@ -13,6 +14,7 @@ import com.wordnik.client.model.Syllable;
import com.wordnik.client.model.Related;
import com.wordnik.client.model.Definition;
import com.wordnik.client.model.AudioFile;
import java.io.File;
import java.util.*;
public class WordApi {
@ -42,6 +44,7 @@ public class WordApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(includeDuplicates)))
queryParams.put("includeDuplicates", String.valueOf(includeDuplicates));
@ -51,10 +54,13 @@ public class WordApi {
queryParams.put("skip", String.valueOf(skip));
if(!"null".equals(String.valueOf(limit)))
queryParams.put("limit", String.valueOf(limit));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (ExampleSearchResults) ApiInvoker.deserialize(response, "", ExampleSearchResults.class);
}
@ -81,15 +87,19 @@ public class WordApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(useCanonical)))
queryParams.put("useCanonical", String.valueOf(useCanonical));
if(!"null".equals(String.valueOf(includeSuggestions)))
queryParams.put("includeSuggestions", String.valueOf(includeSuggestions));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (WordObject) ApiInvoker.deserialize(response, "", WordObject.class);
}
@ -116,6 +126,7 @@ public class WordApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(limit)))
queryParams.put("limit", String.valueOf(limit));
@ -129,10 +140,13 @@ public class WordApi {
queryParams.put("useCanonical", String.valueOf(useCanonical));
if(!"null".equals(String.valueOf(includeTags)))
queryParams.put("includeTags", String.valueOf(includeTags));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (List<Definition>) ApiInvoker.deserialize(response, "List", Definition.class);
}
@ -159,13 +173,17 @@ public class WordApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(useCanonical)))
queryParams.put("useCanonical", String.valueOf(useCanonical));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (Example) ApiInvoker.deserialize(response, "", Example.class);
}
@ -192,6 +210,7 @@ public class WordApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(useCanonical)))
queryParams.put("useCanonical", String.valueOf(useCanonical));
@ -199,10 +218,13 @@ public class WordApi {
queryParams.put("relationshipTypes", String.valueOf(relationshipTypes));
if(!"null".equals(String.valueOf(limitPerRelationshipType)))
queryParams.put("limitPerRelationshipType", String.valueOf(limitPerRelationshipType));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (List<Related>) ApiInvoker.deserialize(response, "List", Related.class);
}
@ -229,6 +251,7 @@ public class WordApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(useCanonical)))
queryParams.put("useCanonical", String.valueOf(useCanonical));
@ -238,10 +261,13 @@ public class WordApi {
queryParams.put("typeFormat", String.valueOf(typeFormat));
if(!"null".equals(String.valueOf(limit)))
queryParams.put("limit", String.valueOf(limit));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (List<TextPron>) ApiInvoker.deserialize(response, "List", TextPron.class);
}
@ -268,6 +294,7 @@ public class WordApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(useCanonical)))
queryParams.put("useCanonical", String.valueOf(useCanonical));
@ -275,10 +302,13 @@ public class WordApi {
queryParams.put("sourceDictionary", String.valueOf(sourceDictionary));
if(!"null".equals(String.valueOf(limit)))
queryParams.put("limit", String.valueOf(limit));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (List<Syllable>) ApiInvoker.deserialize(response, "List", Syllable.class);
}
@ -305,6 +335,7 @@ public class WordApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(useCanonical)))
queryParams.put("useCanonical", String.valueOf(useCanonical));
@ -312,10 +343,13 @@ public class WordApi {
queryParams.put("startYear", String.valueOf(startYear));
if(!"null".equals(String.valueOf(endYear)))
queryParams.put("endYear", String.valueOf(endYear));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (FrequencySummary) ApiInvoker.deserialize(response, "", FrequencySummary.class);
}
@ -342,6 +376,7 @@ public class WordApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(limit)))
queryParams.put("limit", String.valueOf(limit));
@ -349,10 +384,13 @@ public class WordApi {
queryParams.put("wlmi", String.valueOf(wlmi));
if(!"null".equals(String.valueOf(useCanonical)))
queryParams.put("useCanonical", String.valueOf(useCanonical));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (List<Bigram>) ApiInvoker.deserialize(response, "List", Bigram.class);
}
@ -379,13 +417,17 @@ public class WordApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(useCanonical)))
queryParams.put("useCanonical", String.valueOf(useCanonical));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (List<String>) ApiInvoker.deserialize(response, "List", String.class);
}
@ -412,15 +454,19 @@ public class WordApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(useCanonical)))
queryParams.put("useCanonical", String.valueOf(useCanonical));
if(!"null".equals(String.valueOf(limit)))
queryParams.put("limit", String.valueOf(limit));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (List<AudioFile>) ApiInvoker.deserialize(response, "List", AudioFile.class);
}
@ -447,11 +493,15 @@ public class WordApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (ScrabbleScoreResult) ApiInvoker.deserialize(response, "", ScrabbleScoreResult.class);
}

View File

@ -2,9 +2,11 @@ package com.wordnik.client.api;
import com.wordnik.client.common.ApiException;
import com.wordnik.client.common.ApiInvoker;
import com.wordnik.client.model.WordListWord;
import com.wordnik.client.model.WordList;
import com.wordnik.client.model.StringValue;
import java.io.File;
import java.util.*;
public class WordListApi {
@ -34,12 +36,16 @@ public class WordListApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
headerParams.put("auth_token", auth_token);
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "PUT", queryParams, body, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "PUT", queryParams, body, headerParams, formParams, contentType);
if(response != null){
return ;
}
@ -66,12 +72,16 @@ public class WordListApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
headerParams.put("auth_token", auth_token);
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "DELETE", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return ;
}
@ -98,12 +108,16 @@ public class WordListApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
headerParams.put("auth_token", auth_token);
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (WordList) ApiInvoker.deserialize(response, "", WordList.class);
}
@ -130,12 +144,16 @@ public class WordListApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
headerParams.put("auth_token", auth_token);
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, formParams, contentType);
if(response != null){
return ;
}
@ -162,6 +180,7 @@ public class WordListApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(sortBy)))
queryParams.put("sortBy", String.valueOf(sortBy));
@ -172,10 +191,13 @@ public class WordListApi {
if(!"null".equals(String.valueOf(limit)))
queryParams.put("limit", String.valueOf(limit));
headerParams.put("auth_token", auth_token);
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (List<WordListWord>) ApiInvoker.deserialize(response, "List", WordListWord.class);
}
@ -202,12 +224,16 @@ public class WordListApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
headerParams.put("auth_token", auth_token);
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, formParams, contentType);
if(response != null){
return ;
}

View File

@ -2,7 +2,9 @@ package com.wordnik.client.api;
import com.wordnik.client.common.ApiException;
import com.wordnik.client.common.ApiInvoker;
import com.wordnik.client.model.WordList;
import java.io.File;
import java.util.*;
public class WordListsApi {
@ -32,12 +34,16 @@ public class WordListsApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
headerParams.put("auth_token", auth_token);
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "POST", queryParams, body, headerParams, formParams, contentType);
if(response != null){
return (WordList) ApiInvoker.deserialize(response, "", WordList.class);
}

View File

@ -2,10 +2,12 @@ package com.wordnik.client.api;
import com.wordnik.client.common.ApiException;
import com.wordnik.client.common.ApiInvoker;
import com.wordnik.client.model.DefinitionSearchResults;
import com.wordnik.client.model.WordObject;
import com.wordnik.client.model.WordOfTheDay;
import com.wordnik.client.model.WordSearchResults;
import java.io.File;
import java.util.*;
public class WordsApi {
@ -35,6 +37,7 @@ public class WordsApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(caseSensitive)))
queryParams.put("caseSensitive", String.valueOf(caseSensitive));
@ -58,10 +61,13 @@ public class WordsApi {
queryParams.put("skip", String.valueOf(skip));
if(!"null".equals(String.valueOf(limit)))
queryParams.put("limit", String.valueOf(limit));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (WordSearchResults) ApiInvoker.deserialize(response, "", WordSearchResults.class);
}
@ -84,13 +90,17 @@ public class WordsApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(date)))
queryParams.put("date", String.valueOf(date));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (WordOfTheDay) ApiInvoker.deserialize(response, "", WordOfTheDay.class);
}
@ -117,6 +127,7 @@ public class WordsApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(query)))
queryParams.put("query", String.valueOf(query));
@ -150,10 +161,13 @@ public class WordsApi {
queryParams.put("skip", String.valueOf(skip));
if(!"null".equals(String.valueOf(limit)))
queryParams.put("limit", String.valueOf(limit));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (DefinitionSearchResults) ApiInvoker.deserialize(response, "", DefinitionSearchResults.class);
}
@ -176,6 +190,7 @@ public class WordsApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(hasDictionaryDef)))
queryParams.put("hasDictionaryDef", String.valueOf(hasDictionaryDef));
@ -201,10 +216,13 @@ public class WordsApi {
queryParams.put("sortOrder", String.valueOf(sortOrder));
if(!"null".equals(String.valueOf(limit)))
queryParams.put("limit", String.valueOf(limit));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (List<WordObject>) ApiInvoker.deserialize(response, "List", WordObject.class);
}
@ -227,6 +245,7 @@ public class WordsApi {
// query params
Map<String, String> queryParams = new HashMap<String, String>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();
if(!"null".equals(String.valueOf(hasDictionaryDef)))
queryParams.put("hasDictionaryDef", String.valueOf(hasDictionaryDef));
@ -246,10 +265,13 @@ public class WordsApi {
queryParams.put("minLength", String.valueOf(minLength));
if(!"null".equals(String.valueOf(maxLength)))
queryParams.put("maxLength", String.valueOf(maxLength));
String contentType = "application/json";
String[] contentTypes = {
"application/json"};
String contentType = contentTypes.length > 0 ? contentTypes[0] : "application/json";
try {
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, contentType);
String response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams, contentType);
if(response != null){
return (WordObject) ApiInvoker.deserialize(response, "", WordObject.class);
}

View File

@ -19,22 +19,34 @@ import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import java.net.URLEncoder;
import java.io.UnsupportedEncodingException;
public class ApiInvoker {
private static ApiInvoker INSTANCE = new ApiInvoker();
private Map<String, Client> hostMap = new HashMap<String, Client>();
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
private boolean isDebug = false;
public void enableDebug() {
isDebug = true;
}
public static ApiInvoker getInstance() {
return INSTANCE;
}
public void addDefaultHeader(String key, String value) {
defaultHeaderMap.put(key, value);
}
public String escapeString(String str) {
return str;
try{
return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20");
}
catch(UnsupportedEncodingException e) {
return str;
}
}
public static Object deserialize(String json, String containerType, Class cls) throws ApiException {
@ -47,7 +59,7 @@ public class ApiInvoker {
else if(String.class.equals(cls)) {
if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
return json.substring(1, json.length() - 2);
else
else
return json;
}
else {
@ -61,9 +73,9 @@ public class ApiInvoker {
public static String serialize(Object obj) throws ApiException {
try {
if (obj != null)
if (obj != null)
return JsonUtil.getJsonMapper().writeValueAsString(obj);
else
else
return null;
}
catch (Exception e) {
@ -71,11 +83,11 @@ public class ApiInvoker {
}
}
public String invokeAPI(String host, String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, String contentType) throws ApiException {
public String invokeAPI(String host, String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType) throws ApiException {
Client client = getClient(host);
StringBuilder b = new StringBuilder();
for(String key : queryParams.keySet()) {
String value = queryParams.get(key);
if (value != null){
@ -92,7 +104,7 @@ public class ApiInvoker {
for(String key : headerParams.keySet()) {
builder.header(key, headerParams.get(key));
}
for(String key : defaultHeaderMap.keySet()) {
if(!headerParams.containsKey(key)) {
builder.header(key, defaultHeaderMap.get(key));
@ -107,37 +119,63 @@ public class ApiInvoker {
if(body == null)
response = builder.post(ClientResponse.class, serialize(body));
else
response = builder.type("application/json").post(ClientResponse.class, serialize(body));
response = builder.type(contentType).post(ClientResponse.class, serialize(body));
}
else if ("PUT".equals(method)) {
if(body == null)
response = builder.put(ClientResponse.class, serialize(body));
else
response = builder.type("application/json").put(ClientResponse.class, serialize(body));
else {
if("application/x-www-form-urlencoded".equals(contentType)) {
StringBuilder formParamBuilder = new StringBuilder();
// encode the form params
for(String key : formParams.keySet()) {
String value = formParams.get(key);
if(value != null && !"".equals(value.trim())) {
if(formParamBuilder.length() > 0) {
formParamBuilder.append("&");
}
try {
formParamBuilder.append(URLEncoder.encode(key, "utf8")).append("=").append(URLEncoder.encode(value, "utf8"));
}
catch (Exception e) {
// move on to next
}
}
}
response = builder.type(contentType).put(ClientResponse.class, formParamBuilder.toString());
}
else
response = builder.type(contentType).put(ClientResponse.class, serialize(body));
}
}
else if ("DELETE".equals(method)) {
if(body == null)
response = builder.delete(ClientResponse.class, serialize(body));
else
response = builder.type("application/json").delete(ClientResponse.class, serialize(body));
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
}
else {
throw new ApiException(500, "unknown method type " + method);
}
if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) {
return null;
}
else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
return (String) response.getEntity(String.class);
}
else {
throw new ApiException(
response.getClientResponseStatus().getStatusCode(),
response.getEntity(String.class));
response.getEntity(String.class));
}
}
private Client getClient(String host) {
if(!hostMap.containsKey(host)) {
Client client = Client.create();
client.addFilter(new LoggingFilter());
if(isDebug)
client.addFilter(new LoggingFilter());
hostMap.put(host, client);
}
return hostMap.get(host);

View File

@ -5,6 +5,8 @@ import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.core.JsonGenerator.Feature;
import com.fasterxml.jackson.datatype.joda.*;
public class JsonUtil {
public static ObjectMapper mapper;
@ -12,6 +14,7 @@ public class JsonUtil {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.registerModule(new JodaModule());
}
public static ObjectMapper getJsonMapper() {