added wordnik api sample

This commit is contained in:
Tony Tam 2012-09-25 09:21:11 -07:00
parent 7a379a7b40
commit b0c15d1c9b
52 changed files with 5253 additions and 212 deletions

6
bin/scala-wordnik-api.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export CLASSPATH="$DIR/../target/lib/*:$DIR/../target/*"
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties -DfileMap=samples/client/wordnik-api/spec-files"
scala $WORDNIK_OPTS $JAVA_CONFIG_OPTIONS -cp $CLASSPATH "$@" samples/client/wordnik-api/scala/ScalaWordnikApiCodegen.scala http://api.wordnik.com/v4/resources.json

View File

@ -0,0 +1,26 @@
import com.wordnik.swagger.codegen.BasicScalaGenerator
import com.wordnik.swagger.core._
object ScalaWordnikApiCodegen extends BasicScalaGenerator {
def main(args: Array[String]) = generateClient(args)
def destinationRoot = "samples/client/wordnik-api/scala"
// where to write generated code
override def destinationDir = destinationRoot + "/src/main/scala"
// package for api invoker
override def invokerPackage = Some("com.wordnik.client.common")
// package for models
override def modelPackage = Some("com.wordnik.client.model")
// package for api classes
override def apiPackage = Some("com.wordnik.client.api")
// supporting classes
override def supportingFiles = List(
("apiInvoker.mustache", destinationDir + "/" + invokerPackage.get.replaceAll("\\.", java.io.File.separator), "ApiInvoker.scala"),
("pom.mustache", destinationRoot, "pom.xml"))
}

View File

@ -0,0 +1,200 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wordnik</groupId>
<artifactId>swagger-client</artifactId>
<packaging>jar</packaging>
<name>swagger-client</name>
<version>1.0</version>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
<pluginRepository>
<id>maven-mongodb-plugin-repo</id>
<name>maven mongodb plugin repository</name>
<url>http://maven-mongodb-plugin.googlecode.com/svn/maven/repo</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<forkMode>pertest</forkMode>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- attach test jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add_sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add_test_sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArgs>
<jvmArg>-Xms128m</jvmArg>
<jvmArg>-Xmx1500m</jvmArg>
</jvmArgs>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<configuration>
<scalaVersion>${scala-version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</reporting>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-core_2.9.1</artifactId>
<version>${swagger-core-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.9.1</artifactId>
<version>${scala-test-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<jersey-version>1.7</jersey-version>
<swagger-core-version>1.1.0</swagger-core-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>
<scala-test-version>1.6.1</scala-test-version>
<junit-version>4.8.1</junit-version>
<scala-test-version>1.6.1</scala-test-version>
</properties>
</project>

View File

@ -0,0 +1,133 @@
package com.wordnik.client.api
import com.wordnik.client.model.ApiTokenStatus
import com.wordnik.client.model.WordList
import com.wordnik.client.model.User
import com.wordnik.client.model.AuthenticationToken
import com.wordnik.client.common.ApiInvoker
import com.wordnik.client.common.ApiException
import scala.collection.mutable.HashMap
class AccountApi {
var basePath: String = "http://api.wordnik.com/v4"
var apiInvoker = ApiInvoker
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
def authenticate (username: String, password: String) : Option[AuthenticationToken]= {
// create path and map variables
val path = "/account.{format}/authenticate/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}",apiInvoker.escapeString(username))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(username, password) - null).size match {
case 2 => // all required values set
case _ => throw new Exception("missing required params")
}
if(String.valueOf(password) != "null") queryParams += "password" -> password.toString
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[AuthenticationToken]).asInstanceOf[AuthenticationToken])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def authenticatePost (username: String, body: String) : Option[AuthenticationToken]= {
// create path and map variables
val path = "/account.{format}/authenticate/{username}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "username" + "\\}",apiInvoker.escapeString(username))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(username, body) - null).size match {
case 2 => // all required values set
case _ => throw new Exception("missing required params")
}
try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[AuthenticationToken]).asInstanceOf[AuthenticationToken])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getWordListsForLoggedInUser (auth_token: String, skip: Int, limit: Int) : Option[List[WordList]]= {
// create path and map variables
val path = "/account.{format}/wordLists".replaceAll("\\{format\\}","json")// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(auth_token) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
if(String.valueOf(skip) != "null") queryParams += "skip" -> skip.toString
if(String.valueOf(limit) != "null") queryParams += "limit" -> limit.toString
headerParams += "auth_token" -> auth_token
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "List", classOf[WordList]).asInstanceOf[List[WordList]])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getApiTokenStatus (api_key: String) : Option[ApiTokenStatus]= {
// create path and map variables
val path = "/account.{format}/apiTokenStatus".replaceAll("\\{format\\}","json")// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
headerParams += "api_key" -> api_key
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[ApiTokenStatus]).asInstanceOf[ApiTokenStatus])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getLoggedInUser (auth_token: String) : Option[User]= {
// create path and map variables
val path = "/account.{format}/user".replaceAll("\\{format\\}","json")// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(auth_token) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
headerParams += "auth_token" -> auth_token
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[User]).asInstanceOf[User])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
}

View File

@ -0,0 +1,320 @@
package com.wordnik.client.api
import com.wordnik.client.model.Definition
import com.wordnik.client.model.TextPron
import com.wordnik.client.model.Example
import com.wordnik.client.model.Syllable
import com.wordnik.client.model.AudioFile
import com.wordnik.client.model.ExampleSearchResults
import com.wordnik.client.model.WordObject
import com.wordnik.client.model.Bigram
import com.wordnik.client.model.Related
import com.wordnik.client.model.FrequencySummary
import com.wordnik.client.common.ApiInvoker
import com.wordnik.client.common.ApiException
import scala.collection.mutable.HashMap
class WordApi {
var basePath: String = "http://api.wordnik.com/v4"
var apiInvoker = ApiInvoker
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
def getExamples (word: String, skip: Int, limit: Int, includeDuplicates: String= "false", useCanonical: String= "false") : Option[ExampleSearchResults]= {
// create path and map variables
val path = "/word.{format}/{word}/examples".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}",apiInvoker.escapeString(word))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(word) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
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) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[ExampleSearchResults]).asInstanceOf[ExampleSearchResults])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getWord (word: String, useCanonical: String= "false", includeSuggestions: String= "true") : Option[WordObject]= {
// create path and map variables
val path = "/word.{format}/{word}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}",apiInvoker.escapeString(word))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(word) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
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) 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 getDefinitions (word: String, limit: Int, partOfSpeech: String, sourceDictionaries: String, includeRelated: String= "false", useCanonical: String= "false", includeTags: String= "false") : Option[List[Definition]]= {
// create path and map variables
val path = "/word.{format}/{word}/definitions".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}",apiInvoker.escapeString(word))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(word) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
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) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "List", classOf[Definition]).asInstanceOf[List[Definition]])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getTopExample (word: String, useCanonical: String= "false") : Option[Example]= {
// create path and map variables
val path = "/word.{format}/{word}/topExample".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}",apiInvoker.escapeString(word))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(word) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
if(String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) 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
}
}
def getRelatedWords (word: String, relationshipTypes: String, limitPerRelationshipType: Int, useCanonical: String= "false") : Option[List[Related]]= {
// create path and map variables
val path = "/word.{format}/{word}/relatedWords".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}",apiInvoker.escapeString(word))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(word) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
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) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "List", classOf[Related]).asInstanceOf[List[Related]])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getTextPronunciations (word: String, sourceDictionary: String, typeFormat: String, limit: Int, useCanonical: String= "false") : Option[List[TextPron]]= {
// create path and map variables
val path = "/word.{format}/{word}/pronunciations".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}",apiInvoker.escapeString(word))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(word) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
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) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "List", classOf[TextPron]).asInstanceOf[List[TextPron]])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getHyphenation (word: String, sourceDictionary: String, limit: Int, useCanonical: String= "false") : Option[List[Syllable]]= {
// create path and map variables
val path = "/word.{format}/{word}/hyphenation".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}",apiInvoker.escapeString(word))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(word) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
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) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "List", classOf[Syllable]).asInstanceOf[List[Syllable]])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getWordFrequency (word: String, startYear: Int, endYear: Int, useCanonical: String= "false") : Option[FrequencySummary]= {
// create path and map variables
val path = "/word.{format}/{word}/frequency".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}",apiInvoker.escapeString(word))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(word) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
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) 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 getPhrases (word: String, limit: Int, wlmi: Int, useCanonical: String= "false") : Option[List[Bigram]]= {
// create path and map variables
val path = "/word.{format}/{word}/phrases".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}",apiInvoker.escapeString(word))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(word) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
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) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "List", classOf[Bigram]).asInstanceOf[List[Bigram]])
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.{format}/{word}/etymologies".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}",apiInvoker.escapeString(word))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(word) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
if(String.valueOf(useCanonical) != "null") queryParams += "useCanonical" -> useCanonical.toString
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "List", classOf[String]).asInstanceOf[List[String]])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getAudio (word: String, limit: Int, useCanonical: String= "false") : Option[List[AudioFile]]= {
// create path and map variables
val path = "/word.{format}/{word}/audio".replaceAll("\\{format\\}","json").replaceAll("\\{" + "word" + "\\}",apiInvoker.escapeString(word))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(word) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
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) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "List", classOf[AudioFile]).asInstanceOf[List[AudioFile]])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
}

View File

@ -0,0 +1,167 @@
package com.wordnik.client.api
import com.wordnik.client.model.WordList
import com.wordnik.client.model.StringValue
import com.wordnik.client.model.WordListWord
import com.wordnik.client.common.ApiInvoker
import com.wordnik.client.common.ApiException
import scala.collection.mutable.HashMap
class WordListApi {
var basePath: String = "http://api.wordnik.com/v4"
var apiInvoker = ApiInvoker
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
def updateWordList (permalink: String, body: WordList, auth_token: String) = {
// create path and map variables
val path = "/wordList.{format}/{permalink}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}",apiInvoker.escapeString(permalink))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(permalink, auth_token) - null).size match {
case 2 => // all required values set
case _ => throw new Exception("missing required params")
}
headerParams += "auth_token" -> auth_token
try {
apiInvoker.invokeApi(basePath, path, "PUT", queryParams.toMap, body, headerParams.toMap) match {
case s: String =>
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def deleteWordList (permalink: String, auth_token: String) = {
// create path and map variables
val path = "/wordList.{format}/{permalink}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}",apiInvoker.escapeString(permalink))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(permalink, auth_token) - null).size match {
case 2 => // all required values set
case _ => throw new Exception("missing required params")
}
headerParams += "auth_token" -> auth_token
try {
apiInvoker.invokeApi(basePath, path, "DELETE", queryParams.toMap, None, headerParams.toMap) match {
case s: String =>
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getWordListByPermalink (permalink: String, auth_token: String) : Option[WordList]= {
// create path and map variables
val path = "/wordList.{format}/{permalink}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}",apiInvoker.escapeString(permalink))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(permalink, auth_token) - null).size match {
case 2 => // all required values set
case _ => throw new Exception("missing required params")
}
headerParams += "auth_token" -> auth_token
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[WordList]).asInstanceOf[WordList])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def addWordsToWordList (permalink: String, body: Array[StringValue], auth_token: String) = {
// create path and map variables
val path = "/wordList.{format}/{permalink}/words".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}",apiInvoker.escapeString(permalink))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(permalink, auth_token) - null).size match {
case 2 => // all required values set
case _ => throw new Exception("missing required params")
}
headerParams += "auth_token" -> auth_token
try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap) match {
case s: String =>
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getWordListWords (permalink: String, skip: Int, limit: Int, auth_token: String, sortBy: String= "createDate", sortOrder: String= "desc") : Option[List[WordListWord]]= {
// create path and map variables
val path = "/wordList.{format}/{permalink}/words".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}",apiInvoker.escapeString(permalink))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(permalink, auth_token) - null).size match {
case 2 => // all required values set
case _ => throw new Exception("missing required params")
}
if(String.valueOf(sortBy) != "null") queryParams += "sortBy" -> sortBy.toString
if(String.valueOf(sortOrder) != "null") queryParams += "sortOrder" -> sortOrder.toString
if(String.valueOf(skip) != "null") queryParams += "skip" -> skip.toString
if(String.valueOf(limit) != "null") queryParams += "limit" -> limit.toString
headerParams += "auth_token" -> auth_token
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "List", classOf[WordListWord]).asInstanceOf[List[WordListWord]])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def deleteWordsFromWordList (permalink: String, body: Array[StringValue], auth_token: String) = {
// create path and map variables
val path = "/wordList.{format}/{permalink}/deleteWords".replaceAll("\\{format\\}","json").replaceAll("\\{" + "permalink" + "\\}",apiInvoker.escapeString(permalink))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(permalink, auth_token) - null).size match {
case 2 => // all required values set
case _ => throw new Exception("missing required params")
}
headerParams += "auth_token" -> auth_token
try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap) match {
case s: String =>
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
}

View File

@ -0,0 +1,38 @@
package com.wordnik.client.api
import com.wordnik.client.model.WordList
import com.wordnik.client.common.ApiInvoker
import com.wordnik.client.common.ApiException
import scala.collection.mutable.HashMap
class WordListsApi {
var basePath: String = "http://api.wordnik.com/v4"
var apiInvoker = ApiInvoker
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
def createWordList (body: WordList, auth_token: String) : Option[WordList]= {
// create path and map variables
val path = "/wordLists.{format}".replaceAll("\\{format\\}","json")// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(auth_token) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
headerParams += "auth_token" -> auth_token
try {
apiInvoker.invokeApi(basePath, path, "POST", queryParams.toMap, body, headerParams.toMap) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[WordList]).asInstanceOf[WordList])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
}

View File

@ -0,0 +1,164 @@
package com.wordnik.client.api
import com.wordnik.client.model.WordObject
import com.wordnik.client.model.DefinitionSearchResults
import com.wordnik.client.model.WordOfTheDay
import com.wordnik.client.model.WordSearchResults
import com.wordnik.client.common.ApiInvoker
import com.wordnik.client.common.ApiException
import scala.collection.mutable.HashMap
class WordsApi {
var basePath: String = "http://api.wordnik.com/v4"
var apiInvoker = ApiInvoker
def addHeader(key: String, value: String) = apiInvoker.defaultHeaders += key -> value
def searchWords (query: String, includePartOfSpeech: String, excludePartOfSpeech: String, minCorpusCount: Int, maxCorpusCount: Int, minDictionaryCount: Int, maxDictionaryCount: Int, minLength: Int, maxLength: Int, skip: Int, limit: Int, caseSensitive: String= "true") : Option[WordSearchResults]= {
// create path and map variables
val path = "/words.{format}/search/{query}".replaceAll("\\{format\\}","json").replaceAll("\\{" + "query" + "\\}",apiInvoker.escapeString(query))
// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(query) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
if(String.valueOf(caseSensitive) != "null") queryParams += "caseSensitive" -> caseSensitive.toString
if(String.valueOf(includePartOfSpeech) != "null") queryParams += "includePartOfSpeech" -> includePartOfSpeech.toString
if(String.valueOf(excludePartOfSpeech) != "null") queryParams += "excludePartOfSpeech" -> excludePartOfSpeech.toString
if(String.valueOf(minCorpusCount) != "null") queryParams += "minCorpusCount" -> minCorpusCount.toString
if(String.valueOf(maxCorpusCount) != "null") queryParams += "maxCorpusCount" -> maxCorpusCount.toString
if(String.valueOf(minDictionaryCount) != "null") queryParams += "minDictionaryCount" -> minDictionaryCount.toString
if(String.valueOf(maxDictionaryCount) != "null") queryParams += "maxDictionaryCount" -> maxDictionaryCount.toString
if(String.valueOf(minLength) != "null") queryParams += "minLength" -> minLength.toString
if(String.valueOf(maxLength) != "null") queryParams += "maxLength" -> maxLength.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) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[WordSearchResults]).asInstanceOf[WordSearchResults])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getWordOfTheDay (date: String) : Option[WordOfTheDay]= {
// create path and map variables
val path = "/words.{format}/wordOfTheDay".replaceAll("\\{format\\}","json")// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
if(String.valueOf(date) != "null") queryParams += "date" -> date.toString
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[WordOfTheDay]).asInstanceOf[WordOfTheDay])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def reverseDictionary (query: String, findSenseForWord: String, includeSourceDictionaries: String, excludeSourceDictionaries: String, includePartOfSpeech: String, excludePartOfSpeech: String, minCorpusCount: Int, maxCorpusCount: Int, minLength: Int, maxLength: Int, expandTerms: String, sortBy: String, sortOrder: String, limit: Int, includeTags: String= "false", skip: String= "0") : Option[DefinitionSearchResults]= {
// create path and map variables
val path = "/words.{format}/reverseDictionary".replaceAll("\\{format\\}","json")// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
// verify required params are set
(Set(query) - null).size match {
case 1 => // all required values set
case _ => throw new Exception("missing required params")
}
if(String.valueOf(query) != "null") queryParams += "query" -> query.toString
if(String.valueOf(findSenseForWord) != "null") queryParams += "findSenseForWord" -> findSenseForWord.toString
if(String.valueOf(includeSourceDictionaries) != "null") queryParams += "includeSourceDictionaries" -> includeSourceDictionaries.toString
if(String.valueOf(excludeSourceDictionaries) != "null") queryParams += "excludeSourceDictionaries" -> excludeSourceDictionaries.toString
if(String.valueOf(includePartOfSpeech) != "null") queryParams += "includePartOfSpeech" -> includePartOfSpeech.toString
if(String.valueOf(excludePartOfSpeech) != "null") queryParams += "excludePartOfSpeech" -> excludePartOfSpeech.toString
if(String.valueOf(minCorpusCount) != "null") queryParams += "minCorpusCount" -> minCorpusCount.toString
if(String.valueOf(maxCorpusCount) != "null") queryParams += "maxCorpusCount" -> maxCorpusCount.toString
if(String.valueOf(minLength) != "null") queryParams += "minLength" -> minLength.toString
if(String.valueOf(maxLength) != "null") queryParams += "maxLength" -> maxLength.toString
if(String.valueOf(expandTerms) != "null") queryParams += "expandTerms" -> expandTerms.toString
if(String.valueOf(includeTags) != "null") queryParams += "includeTags" -> includeTags.toString
if(String.valueOf(sortBy) != "null") queryParams += "sortBy" -> sortBy.toString
if(String.valueOf(sortOrder) != "null") queryParams += "sortOrder" -> sortOrder.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) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "", classOf[DefinitionSearchResults]).asInstanceOf[DefinitionSearchResults])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getRandomWords (includePartOfSpeech: String, excludePartOfSpeech: String, minCorpusCount: Int, maxCorpusCount: Int, minDictionaryCount: Int, maxDictionaryCount: Int, minLength: Int, maxLength: Int, sortBy: String, sortOrder: String, limit: Int, hasDictionaryDef: String= "true") : Option[List[WordObject]]= {
// create path and map variables
val path = "/words.{format}/randomWords".replaceAll("\\{format\\}","json")// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
if(String.valueOf(hasDictionaryDef) != "null") queryParams += "hasDictionaryDef" -> hasDictionaryDef.toString
if(String.valueOf(includePartOfSpeech) != "null") queryParams += "includePartOfSpeech" -> includePartOfSpeech.toString
if(String.valueOf(excludePartOfSpeech) != "null") queryParams += "excludePartOfSpeech" -> excludePartOfSpeech.toString
if(String.valueOf(minCorpusCount) != "null") queryParams += "minCorpusCount" -> minCorpusCount.toString
if(String.valueOf(maxCorpusCount) != "null") queryParams += "maxCorpusCount" -> maxCorpusCount.toString
if(String.valueOf(minDictionaryCount) != "null") queryParams += "minDictionaryCount" -> minDictionaryCount.toString
if(String.valueOf(maxDictionaryCount) != "null") queryParams += "maxDictionaryCount" -> maxDictionaryCount.toString
if(String.valueOf(minLength) != "null") queryParams += "minLength" -> minLength.toString
if(String.valueOf(maxLength) != "null") queryParams += "maxLength" -> maxLength.toString
if(String.valueOf(sortBy) != "null") queryParams += "sortBy" -> sortBy.toString
if(String.valueOf(sortOrder) != "null") queryParams += "sortOrder" -> sortOrder.toString
if(String.valueOf(limit) != "null") queryParams += "limit" -> limit.toString
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) match {
case s: String =>
Some(ApiInvoker.deserialize(s, "List", classOf[WordObject]).asInstanceOf[List[WordObject]])
case _ => None
}
} catch {
case ex: ApiException if ex.code == 404 => None
case ex: ApiException => throw ex
}
}
def getRandomWord (includePartOfSpeech: String, excludePartOfSpeech: String, minCorpusCount: Int, maxCorpusCount: Int, minDictionaryCount: Int, maxDictionaryCount: Int, minLength: Int, maxLength: Int, hasDictionaryDef: String= "true") : Option[WordObject]= {
// create path and map variables
val path = "/words.{format}/randomWord".replaceAll("\\{format\\}","json")// query params
val queryParams = new HashMap[String, String]
val headerParams = new HashMap[String, String]
if(String.valueOf(hasDictionaryDef) != "null") queryParams += "hasDictionaryDef" -> hasDictionaryDef.toString
if(String.valueOf(includePartOfSpeech) != "null") queryParams += "includePartOfSpeech" -> includePartOfSpeech.toString
if(String.valueOf(excludePartOfSpeech) != "null") queryParams += "excludePartOfSpeech" -> excludePartOfSpeech.toString
if(String.valueOf(minCorpusCount) != "null") queryParams += "minCorpusCount" -> minCorpusCount.toString
if(String.valueOf(maxCorpusCount) != "null") queryParams += "maxCorpusCount" -> maxCorpusCount.toString
if(String.valueOf(minDictionaryCount) != "null") queryParams += "minDictionaryCount" -> minDictionaryCount.toString
if(String.valueOf(maxDictionaryCount) != "null") queryParams += "maxDictionaryCount" -> maxDictionaryCount.toString
if(String.valueOf(minLength) != "null") queryParams += "minLength" -> minLength.toString
if(String.valueOf(maxLength) != "null") queryParams += "maxLength" -> maxLength.toString
try {
apiInvoker.invokeApi(basePath, path, "GET", queryParams.toMap, None, headerParams.toMap) 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
}
}
}

View File

@ -0,0 +1,137 @@
package com.wordnik.client.common
import com.sun.jersey.api.client.Client
import com.sun.jersey.api.client.ClientResponse
import com.sun.jersey.api.client.config.ClientConfig
import com.sun.jersey.api.client.config.DefaultClientConfig
import com.sun.jersey.api.client.filter.LoggingFilter
import java.net.URLEncoder
import javax.ws.rs.core.MediaType
import scala.collection.JavaConverters._
import scala.collection.mutable.HashMap
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.core.JsonGenerator.Feature
import com.fasterxml.jackson.databind._
import com.fasterxml.jackson.annotation._
import com.fasterxml.jackson.databind.annotation.JsonSerialize
object ScalaJsonUtil {
def getJsonMapper = {
val mapper = new ObjectMapper()
mapper.registerModule(new DefaultScalaModule())
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT)
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
mapper
}
}
object ApiInvoker {
val mapper = ScalaJsonUtil.getJsonMapper
val defaultHeaders: HashMap[String, String] = HashMap()
val hostMap: HashMap[String, Client] = HashMap()
def escapeString(value: String): String = {
URLEncoder.encode(value, "utf-8").replaceAll("\\+", "%20")
}
def deserialize(json: String, containerType: String, cls: Class[_]) = {
if (cls == classOf[String]) {
json match {
case s: String => {
if (s.startsWith("\"") && s.endsWith("\"") && s.length > 1) s.substring(1, s.length - 2)
else s
}
case _ => null
}
} else {
containerType match {
case "List" => {
val typeInfo = mapper.getTypeFactory().constructCollectionType(classOf[java.util.List[_]], cls)
val response = mapper.readValue(json, typeInfo).asInstanceOf[java.util.List[_]]
response.asScala.toList
}
case _ => {
json match {
case e: String if ("\"\"" == e) => null
case _ => mapper.readValue(json, cls)
}
}
}
}
}
def serialize(obj: AnyRef): String = {
if (obj != null) {
obj match {
case e: List[_] => mapper.writeValueAsString(obj.asInstanceOf[List[_]].asJava)
case _ => mapper.writeValueAsString(obj)
}
} else null
}
def invokeApi(host: String, path: String, method: String, queryParams: Map[String, String], body: AnyRef, headerParams: Map[String, String]) = {
val client = getClient(host)
val querystring = queryParams.filter(k => k._2 != null).map(k => (escapeString(k._1) + "=" + escapeString(k._2))).mkString("?", "&", "")
val builder = client.resource(host + path + querystring).`type`("application/json")
headerParams.map(p => builder.header(p._1, p._2))
defaultHeaders.map(p => {
headerParams.contains(p._1) match {
case true => // override default with supplied header
case false => if (p._2 != null) builder.header(p._1, p._2)
}
})
val response: ClientResponse = method match {
case "GET" => {
builder.get(classOf[ClientResponse]).asInstanceOf[ClientResponse]
}
case "POST" => {
builder.post(classOf[ClientResponse], serialize(body))
}
case "PUT" => {
builder.put(classOf[ClientResponse], serialize(body))
}
case "DELETE" => {
builder.delete(classOf[ClientResponse])
}
case _ => null
}
response.getClientResponseStatus() match {
case ClientResponse.Status.OK => response.getEntity(classOf[String])
case _ => {
throw new ApiException(
response.getClientResponseStatus().getStatusCode(),
response.getEntity(classOf[String]))
}
}
}
def getClient(host: String): Client = {
hostMap.contains(host) match {
case true => hostMap(host)
case false => {
val client = Client.create()
// client.addFilter(new LoggingFilter())
hostMap += host -> client
client
}
}
}
}
class ApiException extends Exception {
var code = 0
def this(code: Int, msg: String) = {
this()
}
}

View File

@ -0,0 +1,10 @@
package com.wordnik.client.model
case class ApiTokenStatus (
valid: Boolean,
token: String,
resetsInMillis: Long,
remainingCalls: Long,
expiresInMillis: Long,
totalRequests: Long)

View File

@ -0,0 +1,19 @@
package com.wordnik.client.model
import java.util.Date
case class AudioFile (
attributionUrl: String,
commentCount: Int,
voteCount: Int,
fileUrl: String,
audioType: String,
id: Long,
duration: Double,
attributionText: String,
createdBy: String,
description: String,
createdAt: Date,
voteWeightedAverage: Float,
voteAverage: Float,
word: String)

View File

@ -0,0 +1,7 @@
package com.wordnik.client.model
case class AuthenticationToken (
token: String,
userId: Long,
userSignature: String)

View File

@ -0,0 +1,9 @@
package com.wordnik.client.model
case class Bigram (
count: Long,
gram2: String,
gram1: String,
wlmi: Double,
mi: Double)

View File

@ -0,0 +1,6 @@
package com.wordnik.client.model
case class Citation (
cite: String,
source: String)

View File

@ -0,0 +1,6 @@
package com.wordnik.client.model
case class ContentProvider (
id: Int,
name: String)

View File

@ -0,0 +1,26 @@
package com.wordnik.client.model
import com.wordnik.client.model.ExampleUsage
import com.wordnik.client.model.Note
import com.wordnik.client.model.Citation
import com.wordnik.client.model.TextPron
import com.wordnik.client.model.Label
import com.wordnik.client.model.Related
case class Definition (
extendedText: String,
text: String,
sourceDictionary: String,
citations: List[Citation],
labels: List[Label],
score: Float,
exampleUses: List[ExampleUsage],
attributionUrl: String,
seqString: String,
attributionText: String,
relatedWords: List[Related],
sequence: String,
word: String,
textProns: List[TextPron],
notes: List[Note],
partOfSpeech: String)

View File

@ -0,0 +1,7 @@
package com.wordnik.client.model
import com.wordnik.client.model.Definition
case class DefinitionSearchResults (
results: List[Definition],
totalResults: Int)

View File

@ -0,0 +1,19 @@
package com.wordnik.client.model
import com.wordnik.client.model.Sentence
import com.wordnik.client.model.ScoredWord
import com.wordnik.client.model.ContentProvider
case class Example (
id: Long,
text: String,
title: String,
exampleId: Long,
score: ScoredWord,
sentence: Sentence,
year: Int,
provider: ContentProvider,
word: String,
rating: Float,
url: String,
documentId: Long)

View File

@ -0,0 +1,8 @@
package com.wordnik.client.model
import com.wordnik.client.model.Facet
import com.wordnik.client.model.Example
case class ExampleSearchResults (
facets: List[Facet],
examples: List[Example])

View File

@ -0,0 +1,5 @@
package com.wordnik.client.model
case class ExampleUsage (
text: String)

View File

@ -0,0 +1,7 @@
package com.wordnik.client.model
import com.wordnik.client.model.FacetValue
case class Facet (
facetValues: List[FacetValue],
name: String)

View File

@ -0,0 +1,6 @@
package com.wordnik.client.model
case class FacetValue (
count: Long,
value: String)

View File

@ -0,0 +1,6 @@
package com.wordnik.client.model
case class Frequency (
count: Long,
year: Int)

View File

@ -0,0 +1,10 @@
package com.wordnik.client.model
import com.wordnik.client.model.Frequency
case class FrequencySummary (
unknownYearCount: Int,
totalCount: Long,
frequencyString: String,
word: String,
frequency: List[Frequency])

View File

@ -0,0 +1,6 @@
package com.wordnik.client.model
case class Label (
text: String,
`type`: String)

View File

@ -0,0 +1,8 @@
package com.wordnik.client.model
case class Note (
noteType: String,
appliesTo: List[String],
value: String,
pos: Int)

View File

@ -0,0 +1,11 @@
package com.wordnik.client.model
case class Related (
label1: String,
label2: String,
relationshipType: String,
label3: String,
words: List[String],
label4: String,
gram: String)

View File

@ -0,0 +1,15 @@
package com.wordnik.client.model
case class ScoredWord (
id: Long,
position: Int,
lemma: String,
docTermCount: Int,
wordType: String,
score: Float,
word: String,
sentenceId: Long,
stopword: Boolean,
baseWordScore: Double,
partOfSpeech: String)

View File

@ -0,0 +1,11 @@
package com.wordnik.client.model
import com.wordnik.client.model.ScoredWord
case class Sentence (
id: Long,
hasScoredWords: Boolean,
scoredWords: List[ScoredWord],
display: String,
rating: Int,
documentMetadataId: Long)

View File

@ -0,0 +1,8 @@
package com.wordnik.client.model
case class SimpleDefinition (
text: String,
source: String,
note: String,
partOfSpeech: String)

View File

@ -0,0 +1,8 @@
package com.wordnik.client.model
case class SimpleExample (
id: Long,
text: String,
title: String,
url: String)

View File

@ -0,0 +1,5 @@
package com.wordnik.client.model
case class StringValue (
word: String)

View File

@ -0,0 +1,7 @@
package com.wordnik.client.model
case class Syllable (
text: String,
seq: Int,
`type`: String)

View File

@ -0,0 +1,7 @@
package com.wordnik.client.model
case class TextPron (
raw: String,
seq: Int,
rawType: String)

View File

@ -0,0 +1,12 @@
package com.wordnik.client.model
case class User (
id: Long,
username: String,
status: Int,
email: String,
faceBookId: String,
userName: String,
displayName: String,
password: String)

View File

@ -0,0 +1,16 @@
package com.wordnik.client.model
import java.util.Date
case class WordList (
id: Long,
updatedAt: Date,
username: String,
permalink: String,
description: String,
createdAt: Date,
lastActivityAt: Date,
name: String,
userId: Long,
numberWordsInList: Long,
`type`: String)

View File

@ -0,0 +1,12 @@
package com.wordnik.client.model
import java.util.Date
case class WordListWord (
id: Long,
username: String,
createdAt: Date,
userId: Long,
numberCommentsOnWord: Long,
word: String,
numberLists: Long)

View File

@ -0,0 +1,10 @@
package com.wordnik.client.model
case class WordObject (
id: Long,
originalWord: String,
word: String,
suggestions: List[String],
canonicalForm: String,
vulgar: String)

View File

@ -0,0 +1,20 @@
package com.wordnik.client.model
import java.util.Date
import com.wordnik.client.model.SimpleDefinition
import com.wordnik.client.model.SimpleExample
import com.wordnik.client.model.ContentProvider
case class WordOfTheDay (
id: Long,
parentId: String,
category: String,
createdBy: String,
createdAt: Date,
contentProvider: ContentProvider,
word: String,
htmlExtra: String,
definitions: List[SimpleDefinition],
examples: List[SimpleExample],
publishDate: Date,
note: String)

View File

@ -0,0 +1,7 @@
package com.wordnik.client.model
case class WordSearchResult (
count: Long,
lexicality: Double,
word: String)

View File

@ -0,0 +1,7 @@
package com.wordnik.client.model
import com.wordnik.client.model.WordSearchResult
case class WordSearchResults (
totalResults: Int,
searchResults: List[WordSearchResult])

View File

@ -0,0 +1,147 @@
import com.wordnik.client.api._
import com.wordnik.client.model._
import com.wordnik.swagger.core._
import com.wordnik.swagger.core.util.JsonUtil
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.FlatSpec
import org.scalatest.matchers.ShouldMatchers
import scala.collection.mutable.{ ListBuffer, HashMap }
import scala.collection.JavaConversions._
import scala.reflect.BeanProperty
import scala.io.Source
@RunWith(classOf[JUnitRunner])
class WordApiTest extends FlatSpec with ShouldMatchers with BaseApiTest {
behavior of "WordApi"
val api = new WordApi
api.addHeader("api_key", API_KEY)
it should "verify the word apis" in {
val json = Source.fromURL("http://api.wordnik.com/v4/word.json").mkString
val doc = JsonUtil.getJsonMapper.readValue(json, classOf[Documentation])
assert(doc.getApis.size === 11)
}
it should "fetch a word" in {
api.getWord("cat") match {
case Some(word) => {
println(word)
word.word should be("cat")
word should not be (null)
}
case None => println("didn't find word cat")
}
}
it should "fetch a word with suggestions" in {
api.getWord("cAt", "false", "true") match {
case Some(word) => {
word.word should be("cAt")
word.suggestions.size should be (1)
word.suggestions(0) should be ("cat")
word should not be (null)
}
case None => fail("didn't find word cAt")
}
}
it should "fetch a word with canonical form" in {
api.getWord("cAt", "true") match {
case Some(word) => {
word.word should be("cat")
word should not be (null)
}
case None => fail("didn't find word cat")
}
}
it should "fetch definitions for a word" in {
api.getDefinitions("cat", 10, null, null) match {
case Some(definitions) => {
definitions.size should be(10)
}
case None => fail("didn't find definitions for cat")
}
}
it should "fetch examples for a word" in {
api.getExamples("cat", 0, 5) match {
case Some(examples) => {
examples.examples.size should be(5)
}
case None => fail("didn't find examples for cat")
}
}
it should "fetch a top example for a word" in {
api.getTopExample("cat") match {
case Some(example) => {
example.word should be("cat")
}
case None => fail("didn't find examples for cat")
}
}
it should "get text pronunciations for a word" in {
api.getTextPronunciations("cat", null, null, 2) match {
case Some(prons) => {
prons.size should be(2)
}
case None => fail("didn't find prons for cat")
}
}
it should "get hyphenation for a word" in {
api.getHyphenation("catalog", null, 1) match {
case Some(hyphenation) => {
hyphenation.size should be(1)
}
case None => fail("didn't find hyphenation for catalog")
}
}
it should "get word frequency for a word" in {
api.getWordFrequency("cat",0, 2012) match {
case Some(frequency) => {
frequency.totalCount should not be (0)
}
case None => fail("didn't find frequency for cat")
}
}
it should "get word phrases for a word" in {
api.getPhrases("money", 10, 0) match {
case Some(phrases) => {
phrases.size should not be (0)
}
case None => fail("didn't find phrases for money")
}
}
it should "get related words" in {
api.getRelatedWords("cat", null, 10) match {
case Some(relateds) => {
var count = 0
relateds.foreach(related =>{
related.words.size should (be <= 10)
})
}
case None => fail("didn't find related words")
}
}
it should "get audio for a word" in {
api.getAudio("cat", 2) match {
case Some(audio) => {
audio.size should be(2)
}
case None => fail("didn't find audio")
}
}
}

View File

@ -0,0 +1,303 @@
{
"resourcePath":"/account",
"apis":[
{
"path":"/account.{format}/authenticate/{username}",
"description":"",
"operations":[
{
"parameters":[
{
"name":"username",
"description":"A confirmed Wordnik username",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"path"
},
{
"name":"password",
"description":"The user's password",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"query"
}
],
"summary":"Authenticates a User",
"httpMethod":"GET",
"errorResponses":[
{
"reason":"Account not available.",
"code":403
},
{
"reason":"User not found.",
"code":404
}
],
"nickname":"authenticate",
"responseClass":"AuthenticationToken"
},
{
"parameters":[
{
"name":"username",
"description":"A confirmed Wordnik username",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"path"
},
{
"description":"The user's password",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"body"
}
],
"summary":"Authenticates a user",
"httpMethod":"POST",
"errorResponses":[
{
"reason":"Account not available.",
"code":403
},
{
"reason":"User not found.",
"code":404
}
],
"nickname":"authenticatePost",
"responseClass":"AuthenticationToken"
}
]
},
{
"path":"/account.{format}/wordLists",
"description":"",
"operations":[
{
"parameters":[
{
"name":"auth_token",
"description":"auth_token of logged-in user",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"header"
},
{
"name":"skip",
"defaultValue":"0",
"description":"Results to skip",
"required":false,
"dataType":"int",
"allowMultiple":false,
"paramType":"query"
},
{
"name":"limit",
"defaultValue":"50",
"description":"Maximum number of results to return",
"required":false,
"dataType":"int",
"allowMultiple":false,
"paramType":"query"
}
],
"summary":"Fetches WordList objects for the logged-in user.",
"httpMethod":"GET",
"errorResponses":[
{
"reason":"Not authenticated.",
"code":403
},
{
"reason":"User account not found.",
"code":404
}
],
"nickname":"getWordListsForLoggedInUser",
"responseClass":"List[WordList]"
}
]
},
{
"path":"/account.{format}/apiTokenStatus",
"description":"",
"operations":[
{
"parameters":[
{
"name":"api_key",
"description":"Wordnik authentication token",
"required":false,
"dataType":"string",
"allowMultiple":false,
"paramType":"header"
}
],
"summary":"Returns usage statistics for the API account.",
"httpMethod":"GET",
"errorResponses":[
{
"reason":"No token supplied.",
"code":400
},
{
"reason":"No API account with supplied token.",
"code":404
}
],
"nickname":"getApiTokenStatus",
"responseClass":"ApiTokenStatus"
}
]
},
{
"path":"/account.{format}/user",
"description":"",
"operations":[
{
"parameters":[
{
"name":"auth_token",
"description":"The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"header"
}
],
"summary":"Returns the logged-in User",
"httpMethod":"GET",
"errorResponses":[
{
"reason":"Not logged in.",
"code":403
},
{
"reason":"User not found.",
"code":404
}
],
"nickname":"getLoggedInUser",
"responseClass":"User",
"notes":"Requires a valid auth_token to be set."
}
]
}
],
"apiVersion":"4.0",
"swaggerVersion":"1.0",
"basePath":"http://api.wordnik.com/v4",
"models":{
"User":{
"properties":{
"id":{
"type":"long"
},
"username":{
"type":"string"
},
"email":{
"type":"string"
},
"status":{
"type":"int"
},
"faceBookId":{
"type":"string"
},
"userName":{
"type":"string"
},
"displayName":{
"type":"string"
},
"password":{
"type":"string"
}
},
"id":"User"
},
"ApiTokenStatus":{
"properties":{
"valid":{
"type":"boolean"
},
"token":{
"type":"string"
},
"resetsInMillis":{
"type":"long"
},
"remainingCalls":{
"type":"long"
},
"expiresInMillis":{
"type":"long"
},
"totalRequests":{
"type":"long"
}
},
"id":"ApiTokenStatus"
},
"AuthenticationToken":{
"properties":{
"token":{
"type":"string"
},
"userId":{
"type":"long"
},
"userSignature":{
"type":"string"
}
},
"id":"AuthenticationToken"
},
"WordList":{
"properties":{
"updatedAt":{
"type":"Date"
},
"id":{
"type":"long",
"required":true
},
"username":{
"type":"string"
},
"permalink":{
"type":"string"
},
"lastActivityAt":{
"type":"Date"
},
"createdAt":{
"type":"Date"
},
"description":{
"type":"string"
},
"userId":{
"type":"long"
},
"name":{
"type":"string"
},
"numberWordsInList":{
"type":"long"
},
"type":{
"type":"string"
}
},
"id":"WordList"
}
}
}

View File

@ -0,0 +1,27 @@
{
"apis":[
{
"path":"/word.{format}",
"description":""
},
{
"path":"/words.{format}",
"description":""
},
{
"path":"/wordList.{format}",
"description":""
},
{
"path":"/wordLists.{format}",
"description":""
},
{
"path":"/account.{format}",
"description":""
}
],
"apiVersion":"4.0",
"swaggerVersion":"1.1",
"basePath":"http://api.wordnik.com/v4"
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,406 @@
{
"resourcePath":"/wordList",
"apis":[
{
"path":"/wordList.{format}/{permalink}",
"description":"",
"operations":[
{
"parameters":[
{
"name":"permalink",
"description":"permalink of WordList to update",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"path"
},
{
"description":"Updated WordList",
"required":false,
"dataType":"WordList",
"valueTypeInternal":"com.wordnik.community.entity.WordList",
"allowMultiple":false,
"paramType":"body"
},
{
"name":"auth_token",
"description":"The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"header"
}
],
"summary":"Updates an existing WordList",
"httpMethod":"PUT",
"errorResponses":[
{
"reason":"Invalid ID supplied",
"code":400
},
{
"reason":"Not Authorized to update WordList",
"code":403
},
{
"reason":"WordList not found",
"code":404
}
],
"nickname":"updateWordList",
"responseClass":"void"
},
{
"parameters":[
{
"name":"permalink",
"description":"ID of WordList to delete",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"path"
},
{
"name":"auth_token",
"description":"The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"header"
}
],
"summary":"Deletes an existing WordList",
"httpMethod":"DELETE",
"errorResponses":[
{
"reason":"Invalid ID supplied",
"code":400
},
{
"reason":"Not Authorized to delete WordList",
"code":403
},
{
"reason":"WordList not found",
"code":404
}
],
"nickname":"deleteWordList",
"responseClass":"void"
},
{
"parameters":[
{
"name":"permalink",
"description":"permalink of WordList to fetch",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"path"
},
{
"name":"auth_token",
"description":"The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"header"
}
],
"summary":"Fetches a WordList by ID",
"httpMethod":"GET",
"errorResponses":[
{
"reason":"Invalid ID supplied",
"code":400
},
{
"reason":"Not Authorized to access WordList",
"code":403
},
{
"reason":"WordList not found",
"code":404
}
],
"nickname":"getWordListByPermalink",
"responseClass":"WordList"
}
]
},
{
"path":"/wordList.{format}/{permalink}/words",
"description":"",
"operations":[
{
"parameters":[
{
"name":"permalink",
"description":"permalink of WordList to user",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"path"
},
{
"description":"Array of words to add to WordList",
"required":false,
"dataType":"Array[StringValue]",
"valueTypeInternal":"com.wordnik.resource.StringValue",
"allowMultiple":false,
"paramType":"body"
},
{
"name":"auth_token",
"description":"The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"header"
}
],
"summary":"Adds words to a WordList",
"httpMethod":"POST",
"errorResponses":[
{
"reason":"Invalid permalink supplied",
"code":400
},
{
"reason":"Not Authorized to access WordList",
"code":403
},
{
"reason":"WordList not found",
"code":404
}
],
"nickname":"addWordsToWordList",
"responseClass":"void"
},
{
"parameters":[
{
"name":"permalink",
"description":"ID of WordList to use",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"path"
},
{
"name":"sortBy",
"defaultValue":"createDate",
"description":"Field to sort by",
"required":false,
"allowableValues":{
"valueType":"LIST",
"values":[
"createDate",
"alpha"
],
"valueType":"LIST"
},
"dataType":"string",
"allowMultiple":false,
"paramType":"query"
},
{
"name":"sortOrder",
"defaultValue":"desc",
"description":"Direction to sort",
"required":false,
"allowableValues":{
"valueType":"LIST",
"values":[
"asc",
"desc"
],
"valueType":"LIST"
},
"dataType":"string",
"allowMultiple":false,
"paramType":"query"
},
{
"name":"skip",
"defaultValue":"0",
"description":"Results to skip",
"required":false,
"dataType":"int",
"allowMultiple":false,
"paramType":"query"
},
{
"name":"limit",
"defaultValue":"100",
"description":"Maximum number of results to return",
"required":false,
"dataType":"int",
"allowMultiple":false,
"paramType":"query"
},
{
"name":"auth_token",
"description":"The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"header"
}
],
"summary":"Fetches words in a WordList",
"httpMethod":"GET",
"errorResponses":[
{
"reason":"Invalid ID supplied",
"code":400
},
{
"reason":"Not Authorized to access WordList",
"code":403
},
{
"reason":"WordList not found",
"code":404
}
],
"nickname":"getWordListWords",
"responseClass":"List[WordListWord]"
}
]
},
{
"path":"/wordList.{format}/{permalink}/deleteWords",
"description":"",
"operations":[
{
"parameters":[
{
"name":"permalink",
"description":"permalink of WordList to use",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"path"
},
{
"description":"Words to remove from WordList",
"required":false,
"dataType":"Array[StringValue]",
"valueTypeInternal":"com.wordnik.resource.StringValue",
"allowMultiple":false,
"paramType":"body"
},
{
"name":"auth_token",
"description":"The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"header"
}
],
"summary":"Removes words from a WordList",
"httpMethod":"POST",
"errorResponses":[
{
"reason":"Invalid permalink supplied",
"code":400
},
{
"reason":"Not Authorized to modify WordList",
"code":403
},
{
"reason":"WordList not found",
"code":404
}
],
"nickname":"deleteWordsFromWordList",
"responseClass":"void"
}
]
}
],
"apiVersion":"4.0",
"swaggerVersion":"1.0",
"basePath":"http://api.wordnik.com/v4",
"models":{
"WordList":{
"properties":{
"updatedAt":{
"type":"Date"
},
"id":{
"type":"long",
"required":true
},
"username":{
"type":"string"
},
"permalink":{
"type":"string"
},
"lastActivityAt":{
"type":"Date"
},
"createdAt":{
"type":"Date"
},
"description":{
"type":"string"
},
"userId":{
"type":"long"
},
"name":{
"type":"string"
},
"numberWordsInList":{
"type":"long"
},
"type":{
"type":"string"
}
},
"id":"WordList"
},
"WordListWord":{
"properties":{
"id":{
"type":"long",
"required":true
},
"username":{
"type":"string"
},
"createdAt":{
"type":"Date"
},
"numberCommentsOnWord":{
"type":"long"
},
"userId":{
"type":"long"
},
"word":{
"type":"string"
},
"numberLists":{
"type":"long"
}
},
"id":"WordListWord"
},
"StringValue":{
"properties":{
"word":{
"type":"string"
}
},
"id":"StringValue"
}
}
}

View File

@ -0,0 +1,93 @@
{
"resourcePath":"/wordLists",
"apis":[
{
"path":"/wordLists.{format}",
"description":"",
"operations":[
{
"parameters":[
{
"description":"WordList to create",
"required":false,
"dataType":"WordList",
"valueTypeInternal":"com.wordnik.community.entity.WordList",
"allowMultiple":false,
"paramType":"body"
},
{
"name":"auth_token",
"description":"The auth token of the logged-in user, obtained by calling /account.{format}/authenticate/{username} (described above)",
"required":true,
"dataType":"string",
"allowMultiple":false,
"paramType":"header"
}
],
"summary":"Creates a WordList.",
"httpMethod":"POST",
"errorResponses":[
{
"reason":"Invalid WordList supplied or mandatory fields are missing",
"code":400
},
{
"reason":"Not authenticated",
"code":403
},
{
"reason":"WordList owner not found",
"code":404
}
],
"nickname":"createWordList",
"responseClass":"WordList"
}
]
}
],
"apiVersion":"4.0",
"swaggerVersion":"1.0",
"basePath":"http://api.wordnik.com/v4",
"models":{
"WordList":{
"properties":{
"updatedAt":{
"type":"Date"
},
"id":{
"type":"long",
"required":true
},
"username":{
"type":"string"
},
"permalink":{
"type":"string"
},
"lastActivityAt":{
"type":"Date"
},
"createdAt":{
"type":"Date"
},
"description":{
"type":"string"
},
"userId":{
"type":"long"
},
"name":{
"type":"string"
},
"numberWordsInList":{
"type":"long"
},
"type":{
"type":"string"
}
},
"id":"WordList"
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
package {{package}}
package {{invokerPackage}}
import com.sun.jersey.api.client.Client
import com.sun.jersey.api.client.ClientResponse

View File

@ -1,224 +1,199 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wordnik</groupId>
<artifactId>swagger-client</artifactId>
<packaging>jar</packaging>
<name>swagger-client</name>
<version>1.0</version>
<scm>
<connection>scm:git:git@github.com:wordnik/swagger-mustache.git</connection>
<developerConnection>scm:git:git@github.com:wordnik/swagger-mustache.git</developerConnection>
<url>https://github.com/wordnik/swagger-mustache</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wordnik</groupId>
<artifactId>swagger-client</artifactId>
<packaging>jar</packaging>
<name>swagger-client</name>
<version>1.0</version>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
<pluginRepository>
<id>maven-mongodb-plugin-repo</id>
<name>maven mongodb plugin repository</name>
<url>http://maven-mongodb-plugin.googlecode.com/svn/maven/repo</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
<pluginRepository>
<id>maven-mongodb-plugin-repo</id>
<name>maven mongodb plugin repository</name>
<url>http://maven-mongodb-plugin.googlecode.com/svn/maven/repo</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<forkMode>pertest</forkMode>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<forkMode>pertest</forkMode>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!-- attach test jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
<!-- attach test jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add_sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add_test_sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArgs>
<jvmArg>-Xms128m</jvmArg>
<jvmArg>-Xmx1500m</jvmArg>
</jvmArgs>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<configuration>
<scalaVersion>${scala-version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</reporting>
<dependencies>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add_sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add_test_sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmArgs>
<jvmArg>-Xms128m</jvmArg>
<jvmArg>-Xmx1500m</jvmArg>
</jvmArgs>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<configuration>
<scalaVersion>${scala-version}</scalaVersion>
</configuration>
</plugin>
</plugins>
</reporting>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-core_2.9.1</artifactId>
<version>${swagger-core-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.9.1</artifactId>
<version>${scala-test-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-Tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
<repository>
<id>wordnik-ci-aws</id>
<url>https://ci.aws.wordnik.com/artifactory/libs-snapshots/</url>
</repository>
<repository>
<id>wordnik-ci-aws-maven</id>
<url>https://ci.aws.wordnik.com/artifactory/m2-snapshots/</url>
</repository>
<repository>
<id>wordnik-ci-aws-remote</id>
<url>https://ci.aws.wordnik.com/artifactory/remote-repos/</url>
</repository>
</repositories>
<properties>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-core_2.9.1</artifactId>
<version>${swagger-core-version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.9.1</artifactId>
<version>${scala-test-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<jersey-version>1.7</jersey-version>
<swagger-core-version>1.1.0</swagger-core-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>
<scala-test-version>1.6.1</scala-test-version>
<junit-version>4.8.1</junit-version>
<scala-test-version>1.6.1</scala-test-version>
</properties>
</project>
<scala-version>2.9.1-1</scala-version>
<junit-version>4.8.1</junit-version>
<maven-plugin.version>1.0.0</maven-plugin.version>
<scala-test-version>1.6.1</scala-test-version>
<junit-version>4.8.1</junit-version>
<scala-test-version>1.6.1</scala-test-version>
</properties>
</project>

View File

@ -33,6 +33,7 @@ class BasicScalaGenerator extends BasicGenerator {
"Any")
override def typeMapping = Map(
"boolean" -> "Boolean",
"string" -> "String",
"int" -> "Int",
"float" -> "Float",

View File

@ -69,6 +69,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
* types
*/
it should "convert to a declared type" in {
config.toDeclaredType("boolean") should be ("Boolean")
config.toDeclaredType("string") should be ("String")
config.toDeclaredType("int") should be ("Int")
config.toDeclaredType("float") should be ("Float")