forked from loafle/openapi-generator-original
Code reformatting
This commit is contained in:
255
modules/swagger-codegen/src/main/resources/flash/ApiInvoker.as
Normal file
255
modules/swagger-codegen/src/main/resources/flash/ApiInvoker.as
Normal file
@@ -0,0 +1,255 @@
|
||||
package io.swagger.common {
|
||||
import io.swagger.event.ApiClientEvent;
|
||||
import io.swagger.event.Response;
|
||||
|
||||
public class ApiInvoker extends EventDispatcher {
|
||||
|
||||
private static const DELETE_DATA_DUMMY:String = "dummyDataRequiredForDeleteOverride";
|
||||
private static const X_HTTP_OVERRIDE_KEY:String = "X-HTTP-Method-Override";
|
||||
private static const CONTENT_TYPE_HEADER_KEY:String = "Content-Type";
|
||||
|
||||
public function ApiInvoker(apiUsageCredentials:ApiUserCredentials, eventNotifier:EventDispatcher, useProxy:Boolean = true) {
|
||||
_apiUsageCredentials = apiUsageCredentials;
|
||||
_useProxyServer = useProxy;
|
||||
if (_apiUsageCredentials.hostName != null) {
|
||||
_proxyHostName = _apiUsageCredentials.hostName;
|
||||
}
|
||||
_apiPath = _apiUsageCredentials.apiPath;
|
||||
_proxyPath = _apiUsageCredentials.proxyPath;
|
||||
_apiProxyServerUrl = _apiUsageCredentials.apiProxyServerUrl;
|
||||
_apiEventNotifier = eventNotifier;
|
||||
}
|
||||
public var _apiEventNotifier:EventDispatcher;
|
||||
internal var _apiProxyServerUrl:String = "";
|
||||
internal var _useProxyServer:Boolean = true;
|
||||
private var _apiUsageCredentials:ApiUserCredentials;
|
||||
private var _baseUrl:String = "";
|
||||
private var _proxyHostName:String = "";
|
||||
private var _apiPath:String = "";
|
||||
private var _proxyPath:String = "";
|
||||
|
||||
public function invokeAPI(resourceURL:String, method:String, queryParams:Dictionary, postObject:Object, headerParams:Dictionary):AsyncToken {
|
||||
//make the communication
|
||||
if (_useProxyServer) {
|
||||
resourceURL = _apiProxyServerUrl + resourceURL;
|
||||
}
|
||||
else {
|
||||
resourceURL = "http://" + _proxyHostName + _apiPath + resourceURL;
|
||||
}
|
||||
|
||||
var counter:int = 0;
|
||||
var symbol:String = "&";
|
||||
var paramValue:Object;
|
||||
for (var paramName:String in queryParams) {
|
||||
paramValue = queryParams[paramName];
|
||||
//var key:String = paramName;
|
||||
// do stuff
|
||||
symbol = "&";
|
||||
if (counter == 0) {
|
||||
symbol = "?";
|
||||
}
|
||||
resourceURL = resourceURL + symbol + paramName + "=" + paramValue.toString();
|
||||
counter++;
|
||||
|
||||
}
|
||||
// trace(resourceURL);
|
||||
//create a httpservice and invoke the rest url waiting for response
|
||||
var requestHeader:Object = new Object();
|
||||
if (headerParams != null) {
|
||||
for (var key:String in headerParams) {
|
||||
requestHeader[key] = headerParams[key];
|
||||
}
|
||||
}
|
||||
|
||||
resourceURL = ApiUrlHelper.appendTokenInfo(resourceURL, requestHeader, _apiUsageCredentials);
|
||||
|
||||
var bodyData:String = marshal(postObject).toString();//restRequest.postData;
|
||||
|
||||
return doRestCall(resourceURL, onApiRequestResult, onApiRequestFault, method, bodyData, requestHeader, "application/xml");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function marshal(source:Object):Object {
|
||||
// trace("marshal got - " + source)
|
||||
if (source is String) {
|
||||
return source;
|
||||
} else if (source is Array && source.length > 0) {
|
||||
var writer:XMLWriter = new XMLWriter();
|
||||
var sourceArray:Array = source as Array;
|
||||
var arrayEnclosure:String = getArrayEnclosure(sourceArray);
|
||||
writer.xml.setName(arrayEnclosure);
|
||||
|
||||
for (var i:int = 0; i < sourceArray.length; i++) {
|
||||
var o:Object = sourceArray[i];
|
||||
writer.xml.appendChild(marshal(o));
|
||||
}
|
||||
return writer.xml;
|
||||
} else
|
||||
return marshalObject(source);
|
||||
}
|
||||
|
||||
public function marshalObject(source:Object):XML {
|
||||
var writer:XMLWriter = new XMLWriter();
|
||||
var objDescriptor:XML = describeType(source);
|
||||
var property:XML;
|
||||
var propertyType:String;
|
||||
var propertyValue:Object;
|
||||
|
||||
var qualifiedClassName:String = objDescriptor.@name;
|
||||
qualifiedClassName = qualifiedClassName.replace("::", ".");
|
||||
var className:String = qualifiedClassName.substring(qualifiedClassName.lastIndexOf(".") + 1);
|
||||
className = className().toLowerCase() + className.substring(1);
|
||||
writer.xml.setName(className);
|
||||
|
||||
for each(property in objDescriptor.elements("variable")) {
|
||||
propertyValue = source[property.@name];
|
||||
if (propertyValue != null) {
|
||||
if (ObjectUtil.isSimple(propertyValue)) {
|
||||
writer.addProperty(property.@name, propertyValue.toString());
|
||||
}
|
||||
else {
|
||||
writer.addProperty(property.@name, marshal(propertyValue).toXMLString());
|
||||
}
|
||||
}
|
||||
}
|
||||
for each(property in objDescriptor.elements("accessor")) {
|
||||
if (property.@access == "readonly") {
|
||||
continue;
|
||||
}
|
||||
propertyValue = source[property.@name];
|
||||
if (source[property.@name] != null) {
|
||||
if (ObjectUtil.isSimple(propertyValue)) {
|
||||
writer.addProperty(property.@name, propertyValue.toString());
|
||||
}
|
||||
else {
|
||||
writer.addProperty(property.@name, marshal(propertyValue).toXMLString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return writer.xml;
|
||||
}
|
||||
|
||||
public function escapeString(str:String):String {
|
||||
return str;
|
||||
}
|
||||
|
||||
private function doRestCall(url:String, resultFunction:Function, faultFunction:Function = null,
|
||||
restMethod:String = "GET",
|
||||
bodyData:Object = null, headers:Object = null, contentType:String = "application/xml"):AsyncToken {
|
||||
var httpService:HTTPService = new HTTPService();
|
||||
|
||||
if (headers == null) {
|
||||
headers = new Object();
|
||||
}
|
||||
httpService.method = restMethod;
|
||||
|
||||
if (restMethod.toUpperCase() != HTTPRequestMessage.GET_METHOD) {
|
||||
//httpService.method = HTTPRequestMessage.POST_METHOD; - not required as we're using the proxy
|
||||
if (bodyData == null) {
|
||||
bodyData = new Object();
|
||||
}
|
||||
|
||||
if (restMethod == HTTPRequestMessage.DELETE_METHOD) {
|
||||
headers[X_HTTP_OVERRIDE_KEY] = HTTPRequestMessage.DELETE_METHOD;
|
||||
bodyData = DELETE_DATA_DUMMY;
|
||||
}
|
||||
else if (restMethod == HTTPRequestMessage.PUT_METHOD) {
|
||||
headers[X_HTTP_OVERRIDE_KEY] = HTTPRequestMessage.PUT_METHOD;
|
||||
}
|
||||
else {
|
||||
headers[CONTENT_TYPE_HEADER_KEY] = contentType;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//if the request type is GET and content type is xml then the Flex HTTPService converts it to a POST ... yeah
|
||||
contentType = null;
|
||||
}
|
||||
|
||||
httpService.url = url;
|
||||
httpService.contentType = contentType;
|
||||
httpService.resultFormat = "e4x";
|
||||
httpService.headers = headers;
|
||||
httpService.addEventListener(ResultEvent.RESULT, resultFunction);
|
||||
if (faultFunction != null) {
|
||||
httpService.addEventListener(FaultEvent.FAULT, faultFunction);
|
||||
}
|
||||
if (_useProxyServer) {
|
||||
httpService.useProxy = true;
|
||||
|
||||
var channelSet:ChannelSet = new ChannelSet();
|
||||
var httpChannel:HTTPChannel = new HTTPChannel();
|
||||
httpChannel.uri = ApiUrlHelper.getProxyUrl(_proxyHostName, _proxyPath);
|
||||
channelSet.addChannel(httpChannel);
|
||||
httpService.channelSet = channelSet;
|
||||
}
|
||||
|
||||
return httpService.send(bodyData);
|
||||
}
|
||||
|
||||
private function onApiRequestResult(event:ResultEvent):void {
|
||||
var completionListener:Function = event.token.completionListener;
|
||||
var result:Object = event.result;
|
||||
var resultType:Class = event.token.returnType;
|
||||
var resultObject:Object;
|
||||
if (resultType != null) {
|
||||
var context:ASAXBContext = ASAXBContext.newInstance(resultType);
|
||||
var unmarshaller:Unmarshaller = context.createUnmarshaller();
|
||||
var resultXML:XML = new XML(event.result);
|
||||
try {
|
||||
resultObject = unmarshaller.unmarshal(resultXML);
|
||||
}
|
||||
catch (error:TypeError) {
|
||||
var errorResponse:Response = new Response(false, null, "Could not unmarshall response");
|
||||
if (_apiEventNotifier != null) { //dispatch event via assigned dispatcher
|
||||
var failureEvent:ApiClientEvent = new ApiClientEvent(event.token.completionEventType);
|
||||
failureEvent.response = errorResponse;
|
||||
_apiEventNotifier.dispatchEvent(failureEvent);
|
||||
}
|
||||
}
|
||||
|
||||
if (resultObject is ListWrapper) {
|
||||
resultObject = ListWrapper(resultObject).getList();
|
||||
}
|
||||
}
|
||||
|
||||
var response:Response = new Response(true, resultObject);
|
||||
response.requestId = event.token.requestId;
|
||||
var successEventType:String = event.token.completionEventType != null ? event.token.completionEventType : ApiClientEvent.SUCCESS_EVENT;
|
||||
|
||||
if (_apiEventNotifier != null) { //dispatch event via assigned dispatcher
|
||||
var successEvent:ApiClientEvent = new ApiClientEvent(successEventType);
|
||||
successEvent.response = response;
|
||||
_apiEventNotifier.dispatchEvent(successEvent);
|
||||
}
|
||||
}
|
||||
|
||||
private function onApiRequestFault(event:FaultEvent):void {
|
||||
var completionListener:Function = event.token.completionListener;
|
||||
if (completionListener != null) {
|
||||
completionListener.call(null, new Response(false, null, event.fault.faultString));
|
||||
}
|
||||
|
||||
var failureEventType:String = event.token.completionEventType != null ? event.token.completionEventType : ApiClientEvent.FAILURE_EVENT;
|
||||
|
||||
if (_apiEventNotifier != null) { //dispatch event via assigned dispatcher
|
||||
var failureEvent:ApiClientEvent = new ApiClientEvent(failureEventType);
|
||||
failureEvent.response = new Response(false, null, event.fault.faultString);
|
||||
_apiEventNotifier.dispatchEvent(failureEvent);
|
||||
}
|
||||
}
|
||||
|
||||
private function getArrayEnclosure(arr:Array):String {
|
||||
if (arr != null && arr.length > 0) {
|
||||
var className:String = flash.utils.getQualifiedClassName(arr[0])
|
||||
if (className.indexOf("::") > 0)
|
||||
className = className.substr(className.indexOf("::") + 2, className.length)
|
||||
|
||||
return className.substring(0, 1).toLowerCase() + className.substring(1, className.length) + "s";
|
||||
} else
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.wordnik.swagger.common {
|
||||
public class XMLWriter {
|
||||
public function XMLWriter() {
|
||||
xml = <obj/>;
|
||||
}
|
||||
public var xml:XML;
|
||||
|
||||
public function reset():void {
|
||||
xml = new XML();
|
||||
}
|
||||
|
||||
public function addProperty(propertyName:String, propertyValue:String):XML {
|
||||
var xmlProperty:XML = <new/>
|
||||
xmlProperty.setName(propertyName);
|
||||
xmlProperty.appendChild(propertyValue);
|
||||
xml.appendChild(xmlProperty);
|
||||
return xmlProperty;
|
||||
}
|
||||
|
||||
public function addAttribute(propertyName:String, attribute:String, attributeValue:String):void {
|
||||
xml.elements(propertyName)[0].@[attribute] = attributeValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,426 @@
|
||||
package io.swagger.client.api
|
||||
|
||||
import scala.collection.mutable.HashMap
|
||||
|
||||
class WordApi(val defBasePath: String = "https://api.wordnik.com/v4",
|
||||
defApiInvoker: ApiInvoker = ApiInvoker) {
|
||||
var basePath = defBasePath
|
||||
var apiInvoker = defApiInvoker
|
||||
|
||||
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
|
||||
|
||||
|
||||
def getWord(word: String, useCanonical: String, includeSuggestions: String): Option[WordObject] = {
|
||||
// create path and map variables
|
||||
val path = "/word.json/{word}".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escape(word))
|
||||
|
||||
|
||||
|
||||
|
||||
val contentType = {
|
||||
|
||||
"application/json"
|
||||
}
|
||||
|
||||
// query params
|
||||
val queryParams = new HashMap[String, String]
|
||||
val headerParams = new HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if (String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
|
||||
if (String.valueOf(includeSuggestions) != "null") queryParams += "includeSuggestions" -> includeSuggestions.toString
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
|
||||
case s: String =>
|
||||
Some(ApiInvoker.deserialize(s, "", classOf[WordObject]).asInstanceOf[WordObject])
|
||||
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
case ex: ApiException if ex.code == 404 => None
|
||||
case ex: ApiException => throw ex
|
||||
}
|
||||
}
|
||||
|
||||
def getAudio(word: String, useCanonical: String, limit: Integer): Option[List[AudioFile]] = {
|
||||
// create path and map variables
|
||||
val path = "/word.json/{word}/audio".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escape(word))
|
||||
|
||||
|
||||
|
||||
|
||||
val contentType = {
|
||||
|
||||
"application/json"
|
||||
}
|
||||
|
||||
// query params
|
||||
val queryParams = new HashMap[String, String]
|
||||
val headerParams = new HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if (String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
|
||||
if (String.valueOf(limit) != "null") queryParams += "limit" -> limit.toString
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
|
||||
case s: String =>
|
||||
Some(ApiInvoker.deserialize(s, "array", classOf[AudioFile]).asInstanceOf[List[AudioFile]])
|
||||
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
case ex: ApiException if ex.code == 404 => None
|
||||
case ex: ApiException => throw ex
|
||||
}
|
||||
}
|
||||
|
||||
def getDefinitions(word: String, limit: Integer, partOfSpeech: String, includeRelated: String, sourceDictionaries: List[String], useCanonical: String, includeTags: String): Option[List[Definition]] = {
|
||||
// create path and map variables
|
||||
val path = "/word.json/{word}/definitions".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escape(word))
|
||||
|
||||
|
||||
|
||||
|
||||
val contentType = {
|
||||
|
||||
"application/json"
|
||||
}
|
||||
|
||||
// query params
|
||||
val queryParams = new HashMap[String, String]
|
||||
val headerParams = new HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if (String.valueOf(limit) != "null") queryParams += "limit" -> limit.toString
|
||||
if (String.valueOf(partOfSpeech) != "null") queryParams += "partOfSpeech" -> partOfSpeech.toString
|
||||
if (String.valueOf(includeRelated) != "null") queryParams += "includeRelated" -> includeRelated.toString
|
||||
if (String.valueOf(sourceDictionaries) != "null") queryParams += "sourceDictionaries" -> sourceDictionaries.toString
|
||||
if (String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
|
||||
if (String.valueOf(includeTags) != "null") queryParams += "includeTags" -> includeTags.toString
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
|
||||
case s: String =>
|
||||
Some(ApiInvoker.deserialize(s, "array", classOf[Definition]).asInstanceOf[List[Definition]])
|
||||
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
case ex: ApiException if ex.code == 404 => None
|
||||
case ex: ApiException => throw ex
|
||||
}
|
||||
}
|
||||
|
||||
def getEtymologies(word: String, useCanonical: String): Option[List[String]] = {
|
||||
// create path and map variables
|
||||
val path = "/word.json/{word}/etymologies".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escape(word))
|
||||
|
||||
|
||||
|
||||
|
||||
val contentType = {
|
||||
|
||||
"application/json"
|
||||
}
|
||||
|
||||
// query params
|
||||
val queryParams = new HashMap[String, String]
|
||||
val headerParams = new HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if (String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
|
||||
case s: String =>
|
||||
Some(ApiInvoker.deserialize(s, "array", classOf[String]).asInstanceOf[List[String]])
|
||||
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
case ex: ApiException if ex.code == 404 => None
|
||||
case ex: ApiException => throw ex
|
||||
}
|
||||
}
|
||||
|
||||
def getExamples(word: String, includeDuplicates: String, useCanonical: String, skip: Integer, limit: Integer) = {
|
||||
// create path and map variables
|
||||
val path = "/word.json/{word}/examples".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escape(word))
|
||||
|
||||
|
||||
|
||||
|
||||
val contentType = {
|
||||
|
||||
"application/json"
|
||||
}
|
||||
|
||||
// query params
|
||||
val queryParams = new HashMap[String, String]
|
||||
val headerParams = new HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if (String.valueOf(includeDuplicates) != "null") queryParams += "includeDuplicates" -> includeDuplicates.toString
|
||||
if (String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
|
||||
if (String.valueOf(skip) != "null") queryParams += "skip" -> skip.toString
|
||||
if (String.valueOf(limit) != "null") queryParams += "limit" -> limit.toString
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
|
||||
case s: String =>
|
||||
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
case ex: ApiException if ex.code == 404 => None
|
||||
case ex: ApiException => throw ex
|
||||
}
|
||||
}
|
||||
|
||||
def getWordFrequency(word: String, useCanonical: String, startYear: Integer, endYear: Integer): Option[FrequencySummary] = {
|
||||
// create path and map variables
|
||||
val path = "/word.json/{word}/frequency".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escape(word))
|
||||
|
||||
|
||||
|
||||
|
||||
val contentType = {
|
||||
|
||||
"application/json"
|
||||
}
|
||||
|
||||
// query params
|
||||
val queryParams = new HashMap[String, String]
|
||||
val headerParams = new HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if (String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
|
||||
if (String.valueOf(startYear) != "null") queryParams += "startYear" -> startYear.toString
|
||||
if (String.valueOf(endYear) != "null") queryParams += "endYear" -> endYear.toString
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
|
||||
case s: String =>
|
||||
Some(ApiInvoker.deserialize(s, "", classOf[FrequencySummary]).asInstanceOf[FrequencySummary])
|
||||
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
case ex: ApiException if ex.code == 404 => None
|
||||
case ex: ApiException => throw ex
|
||||
}
|
||||
}
|
||||
|
||||
def getHyphenation(word: String, useCanonical: String, sourceDictionary: String, limit: Integer) = {
|
||||
// create path and map variables
|
||||
val path = "/word.json/{word}/hyphenation".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escape(word))
|
||||
|
||||
|
||||
|
||||
|
||||
val contentType = {
|
||||
|
||||
"application/json"
|
||||
}
|
||||
|
||||
// query params
|
||||
val queryParams = new HashMap[String, String]
|
||||
val headerParams = new HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if (String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
|
||||
if (String.valueOf(sourceDictionary) != "null") queryParams += "sourceDictionary" -> sourceDictionary.toString
|
||||
if (String.valueOf(limit) != "null") queryParams += "limit" -> limit.toString
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
|
||||
case s: String =>
|
||||
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
case ex: ApiException if ex.code == 404 => None
|
||||
case ex: ApiException => throw ex
|
||||
}
|
||||
}
|
||||
|
||||
def getPhrases(word: String, limit: Integer, wlmi: Integer, useCanonical: String): Option[List[Bigram]] = {
|
||||
// create path and map variables
|
||||
val path = "/word.json/{word}/phrases".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escape(word))
|
||||
|
||||
|
||||
|
||||
|
||||
val contentType = {
|
||||
|
||||
"application/json"
|
||||
}
|
||||
|
||||
// query params
|
||||
val queryParams = new HashMap[String, String]
|
||||
val headerParams = new HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if (String.valueOf(limit) != "null") queryParams += "limit" -> limit.toString
|
||||
if (String.valueOf(wlmi) != "null") queryParams += "wlmi" -> wlmi.toString
|
||||
if (String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
|
||||
case s: String =>
|
||||
Some(ApiInvoker.deserialize(s, "array", classOf[Bigram]).asInstanceOf[List[Bigram]])
|
||||
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
case ex: ApiException if ex.code == 404 => None
|
||||
case ex: ApiException => throw ex
|
||||
}
|
||||
}
|
||||
|
||||
def getTextPronunciations(word: String, useCanonical: String, sourceDictionary: String, typeFormat: String, limit: Integer) = {
|
||||
// create path and map variables
|
||||
val path = "/word.json/{word}/pronunciations".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escape(word))
|
||||
|
||||
|
||||
|
||||
|
||||
val contentType = {
|
||||
|
||||
"application/json"
|
||||
}
|
||||
|
||||
// query params
|
||||
val queryParams = new HashMap[String, String]
|
||||
val headerParams = new HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if (String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
|
||||
if (String.valueOf(sourceDictionary) != "null") queryParams += "sourceDictionary" -> sourceDictionary.toString
|
||||
if (String.valueOf(typeFormat) != "null") queryParams += "typeFormat" -> typeFormat.toString
|
||||
if (String.valueOf(limit) != "null") queryParams += "limit" -> limit.toString
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
|
||||
case s: String =>
|
||||
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
case ex: ApiException if ex.code == 404 => None
|
||||
case ex: ApiException => throw ex
|
||||
}
|
||||
}
|
||||
|
||||
def getRelatedWords(word: String, useCanonical: String, relationshipTypes: String, limitPerRelationshipType: Integer) = {
|
||||
// create path and map variables
|
||||
val path = "/word.json/{word}/relatedWords".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escape(word))
|
||||
|
||||
|
||||
|
||||
|
||||
val contentType = {
|
||||
|
||||
"application/json"
|
||||
}
|
||||
|
||||
// query params
|
||||
val queryParams = new HashMap[String, String]
|
||||
val headerParams = new HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if (String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
|
||||
if (String.valueOf(relationshipTypes) != "null") queryParams += "relationshipTypes" -> relationshipTypes.toString
|
||||
if (String.valueOf(limitPerRelationshipType) != "null") queryParams += "limitPerRelationshipType" -> limitPerRelationshipType.toString
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
|
||||
case s: String =>
|
||||
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
case ex: ApiException if ex.code == 404 => None
|
||||
case ex: ApiException => throw ex
|
||||
}
|
||||
}
|
||||
|
||||
def getTopExample(word: String, useCanonical: String): Option[Example] = {
|
||||
// create path and map variables
|
||||
val path = "/word.json/{word}/topExample".replaceAll("\\{format\\}", "json").replaceAll("\\{" + "word" + "\\}", apiInvoker.escape(word))
|
||||
|
||||
|
||||
|
||||
|
||||
val contentType = {
|
||||
|
||||
"application/json"
|
||||
}
|
||||
|
||||
// query params
|
||||
val queryParams = new HashMap[String, String]
|
||||
val headerParams = new HashMap[String, String]
|
||||
|
||||
|
||||
|
||||
if (String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap, contentType) match {
|
||||
case s: String =>
|
||||
Some(ApiInvoker.deserialize(s, "", classOf[Example]).asInstanceOf[Example])
|
||||
|
||||
case _ => None
|
||||
}
|
||||
} catch {
|
||||
case ex: ApiException if ex.code == 404 => None
|
||||
case ex: ApiException => throw ex
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user