package com.wordnik.api; import com.wordnik.common.*; import com.wordnik.common.ext.*; import com.wordnik.exception.APIExceptionCodes; import com.wordnik.exception.APIException; import com.wordnik.model.*; import java.util.*; import com.wordnik.annotations.MethodArgumentNames; import org.codehaus.jackson.map.DeserializationConfig.Feature; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.type.TypeReference; import java.io.IOException; $imports:{ import | import $import$; }$ /** * NOTE: This class is auto generated by the drive code generator program so please do not edit the program manually. * @author ramesh * */ public class $resource$ extends $extends$ { $methods:{ method | /** * $method.description$ $method.arguments:{ argument | * @param $argument.name$ $argument.description$ $if(argument.allowedValues)$ * Allowed values are - $argument.allowedValues$ $endif$ }$ * * @return $method.returnValue$ {@link $method.returnClassName$} * @throws APIException $method.exceptionDescription$ */ $if(method.hasArguments)$ @MethodArgumentNames(value="$method.argumentNames; separator=", "$") $endif$ public static $method.returnValue$ $method.name$($method.argumentDefinitions; separator=", "$) throws APIException { $if(method.authToken)$ if(authToken == null || authToken.length() == 0) { throw new APIException(APIExceptionCodes.AUTH_TOKEN_NOT_VALID); } $endif$ //parse inputs String resourcePath = "$method.resourcePath$"; resourcePath = resourcePath.replace("{format}","json"); String method = "$method.methodType$"; Map queryParams = new HashMap(); $if(!method.inputModel)$ $method.queryParameters:{ argument | if( $argument.name$ != null) { queryParams.put("$argument.name$", $argument.name$); } }$ $method.pathParameters:{ argument | if( $argument.name$ != null) { resourcePath = resourcePath.replace("{$argument.name$}", $argument.name$); } }$ $endif$ $if(method.inputModel)$ $method.queryParameters:{ argument | if( $argument.inputModelClassArgument$ != null && $argument.methodNameFromModelClass$ != null) { queryParams.put("$argument.name$", $argument.methodNameFromModelClass$); } }$ $method.pathParameters:{ argument | if( $argument.inputModelClassArgument$ != null && $argument.methodNameFromModelClass$ != null) { resourcePath = resourcePath.replace("{$argument.name$}", $argument.methodNameFromModelClass$); } }$ $endif$ //make the API Call $if(method.postObject)$ $if(method.authToken)$ String response = invokeAPI(authToken, resourcePath, method, queryParams, postObject); $endif$ $if(!method.authToken)$ String response = invokeAPI(null, resourcePath, method, queryParams, postObject); $endif$ $endif$ $if(!method.postObject)$ $if(method.authToken)$ String response = invokeAPI(authToken, resourcePath, method, queryParams, null); $endif$ $if(!method.authToken)$ String response = invokeAPI(null, resourcePath, method, queryParams, null); $endif$ $endif$ //create output objects if the response has more than one object $if(!method.responseVoid)$ if(response == null || response.length() == 0){ return null; } $if(!method.returnValueList)$ $method.returnValue$ responseObject = ($method.returnValue$)deserialize(response, $method.returnClassName$.class); return responseObject; $endif$ $if(method.returnValueList)$ TypeReference> typeRef = new TypeReference>() { }; try { List<$method.returnClassName$> responseObject = (List<$method.returnClassName$>) mapper.readValue(response, typeRef); return responseObject; } catch (IOException ioe) { String[] args = new String[]{response, typeRef.toString()}; throw new APIException(APIExceptionCodes.ERROR_CONVERTING_JSON_TO_JAVA, args, "Error in converting response json value to java object : " + ioe.getMessage(), ioe); } $endif$ $endif$ } }$ }