Skip to content
Browse files

Updated readme.

  • Loading branch information...
1 parent 876fe87 commit 6cda157f9ec06b7dd9ab431e5815834ec70194cb @jeremybrooks committed Apr 14, 2011
Showing with 50 additions and 13 deletions.
  1. +18 −13 README
  2. +20 −0 src/net/jeremybrooks/knicker/WordApi.java
  3. +12 −0 test/net/jeremybrooks/knicker/WordApiTest.java
View
31 README
@@ -1,5 +1,7 @@
BUGS:
-total reported by Examples is incorrect (reported to Wordnik)
+If the limit parameter is specified when looking for pronunciations, zero
+results are returned. This has been reported to Wordnik.
+
Knicker is a Java interface to the Wordnik API.
@@ -8,30 +10,34 @@ You can use Knicker to add dictionary lookup capabilities to your own Java
programs. Knicker has been designed to be simple and straightforward to use. It
does not require any third party libraries, just Java 1.6 or higher.
-Version 1.1.1 of Knicker adds support for the American Heritage Dictionary. This is the default dictionary that will be used if you do not specify a source, but you can explicity specify it using SourceDictionary.ahd.
+Version 2.x of Knicker supports version 4 of the Wordnik API.
-Version 1.1.0 of Knicker supports version 3.3 of the Wordnik API. You can find
-additional documentation on the Wordnik API here: http://docs.wordnik.com/api/methods
+Version 1.x of Knicker supports version 3 of the Wordnik API.
-To use Knicker, you need a Wordnik API key. You can get one here:
-http://www.wordnik.com/developers
+To use Knicker, you will need to obtain a Wordnik API key. More information
+about the Wordnik API can be found on their developer site at
+http://developer.wordnik.com
Knicker looks for the system property WORDNIK_API_KEY, so you need to set it
before you try to use Knicker:
System.setProperty("WORDNIK_API_KEY", <your API key>);
Then just call the API methods using the Knicker class:
-Knicker.lookup("zebra");
+WordApi.lookup("zebra");
-There are methods in Knicker for each of the Wordnik methods.
+The Wordnik API is divided into different sections based on the API endpoint.
+Knicker, for the most part, follows this logical arrangement. If you want
+to call methods on the account endpoint, use the AccountApi class, for methods
+on the word endpoint, use the WordApi class, and so on.
Here's a quick sample showing how to check the API key status and look up the
definition of a word:
import java.util.List;
-import net.jeremybrooks.knicker.Knicker;
+import net.jeremybrooks.knicker.AccountApi;
+import net.jeremybrooks.knicker.WordApi;
import net.jeremybrooks.knicker.dto.Definition;
import net.jeremybrooks.knicker.dto.TokenStatus;
@@ -40,11 +46,11 @@ public class TestKnicker {
public static void main(String[] args) throws Exception {
// use your API key here
- System.setProperty("WORDNIK_API_KEY", "5458ce49330219f23e0020790810f29b3818096f5fbbf8560");
+ System.setProperty("WORDNIK_API_KEY", "your api key");
// check the status of the API key
- TokenStatus status = Knicker.status();
+ TokenStatus status = AccountApi.apiTokenStatus();
if (status.isValid()) {
System.out.println("API key is valid.");
} else {
@@ -54,7 +60,7 @@ public class TestKnicker {
// get a list of definitions for a word
- List<Definition> def = Knicker.definitions("siren");
+ List<Definition> def = WordApi.definitions("siren");
System.out.println("Found " + def.size() + " definitions.");
int i = 1;
@@ -64,4 +70,3 @@ public class TestKnicker {
}
}
-
View
20 src/net/jeremybrooks/knicker/WordApi.java
@@ -180,6 +180,26 @@ public static SearchResults examples(String word, boolean includeDuplicates,
/**
* Look up definitions for a word.
+ *
+ * This is equivalent to calling <code>definitions(word, 0, null, false, null, false, false);</code>
+ *
+ * @param word the word to return definitions for.
+ * @return list of definitions for the word.
+ * @throws KnickerException if the word is null or empty, or if there are
+ * any errors.
+ */
+ public static List<Definition> definitions(String word) throws
+ KnickerException {
+ if (word == null || word.isEmpty()) {
+ throw new KnickerException("Cannot look up definitions for an empty word.");
+ }
+
+ return definitions(word, 0, null, false, null, false, false);
+ }
+
+
+ /**
+ * Look up definitions for a word.
*
* @param word word to return definitions for.
* @param sourceDictionaries gets from dictionaries in the supplied order of precedence.
View
12 test/net/jeremybrooks/knicker/WordApiTest.java
@@ -170,6 +170,18 @@ public void testExamples_6args() throws Exception {
}
+ /**
+ * Test of definitions method, of class WordApi.
+ */
+ @Test
+ public void testDefinitions() throws Exception {
+ System.out.println("definitions");
+ String word = "cat";
+ List<Definition> result = WordApi.definitions(word);
+ assertNotNull(result);
+ assertTrue(result.size() > 0);
+ }
+
/**
* Test of definitions method, of class WordApi.

0 comments on commit 6cda157

Please sign in to comment.
Something went wrong with that request. Please try again.