Skip to content

Commit

Permalink
taking Raynes suggestion and nuking the api namespace prefix for meth…
Browse files Browse the repository at this point in the history
…ods since that can be done by the user with :as
  • Loading branch information
joshrotenberg committed Oct 22, 2011
1 parent 30a4dd2 commit 46cf23b
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 78 deletions.
10 changes: 5 additions & 5 deletions src/wordnik/api/account.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
(let [resource (str "account.json/" action)]
`(def-wordnik-method ~name ~request-method ~resource ~@rest)))

(def-wordnik-account-method account-authenticate
(def-wordnik-account-method authenticate
:get "authenticate/{:username}")
(def-wordnik-account-method account-authenticate-post
(def-wordnik-account-method authenticate-post
:post "authenticate/{:username}")
(def-wordnik-account-method account-wordlists :get "wordLists")
(def-wordnik-account-method account-api-token-status :get "apiTokenStatus")
(def-wordnik-account-method account-user :get "user")
(def-wordnik-account-method wordlists :get "wordLists")
(def-wordnik-account-method api-token-status :get "apiTokenStatus")
(def-wordnik-account-method user :get "user")
20 changes: 10 additions & 10 deletions src/wordnik/api/word.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
`(def-wordnik-method ~name ~request-method ~resource ~@rest)))

(def-wordnik-word-method word :get "{:word}")
(def-wordnik-word-method word-examples :get "{:word}/examples")
(def-wordnik-word-method word-definitions :get "{:word}/definitions")
(def-wordnik-word-method word-top-examples :get "{:word}/topExamples")
(def-wordnik-word-method word-punctuation-factor
(def-wordnik-word-method examples :get "{:word}/examples")
(def-wordnik-word-method definitions :get "{:word}/definitions")
(def-wordnik-word-method top-examples :get "{:word}/topExamples")
(def-wordnik-word-method punctuation-factor
:get "{:word}/punctuationFactor")
(def-wordnik-word-method word-related :get "{:word}/related")
(def-wordnik-word-method word-pronunciations :get "{:word}/pronunciations")
(def-wordnik-word-method word-hyphenation :get "{:word}/hyphenation")
(def-wordnik-word-method word-frequency :get "{:word}/frequency")
(def-wordnik-word-method word-phrases :get "{:word}/phrases")
(def-wordnik-word-method word-audio :get "{:word}/audio")
(def-wordnik-word-method related :get "{:word}/related")
(def-wordnik-word-method pronunciations :get "{:word}/pronunciations")
(def-wordnik-word-method hyphenation :get "{:word}/hyphenation")
(def-wordnik-word-method frequency :get "{:word}/frequency")
(def-wordnik-word-method phrases :get "{:word}/phrases")
(def-wordnik-word-method audio :get "{:word}/audio")
12 changes: 6 additions & 6 deletions src/wordnik/api/wordlist.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
(let [resource (str "wordList.json/" action)]
`(def-wordnik-method ~name ~request-method ~resource ~@rest)))

(def-wordnik-wordlist-method wordlist-update :put "{:id}")
(def-wordnik-wordlist-method wordlist-delete :delete "{:id}")
(def-wordnik-wordlist-method wordlist-fetch :get "{:id}")
(def-wordnik-wordlist-method wordlist-add-words :post "{:id}/words"
(def-wordnik-wordlist-method update :put "{:id}")
(def-wordnik-wordlist-method delete :delete "{:id}")
(def-wordnik-wordlist-method fetch :get "{:id}")
(def-wordnik-wordlist-method add-words :post "{:id}/words"
:headers { :content-type "application/json"} )
(def-wordnik-wordlist-method wordlist-words :get "{:id}/words")
(def-wordnik-wordlist-method wordlist-delete-words
(def-wordnik-wordlist-method words :get "{:id}/words")
(def-wordnik-wordlist-method delete-words
:post "{:id}/deleteWords"
:headers { :content-type "application/json"} )
8 changes: 4 additions & 4 deletions src/wordnik/api/words.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(let [resource (str "words.json/" action)]
`(def-wordnik-method ~name ~request-method ~resource ~@rest)))

(def-wordnik-words-method words-wotd :get "wordOfTheDay")
(def-wordnik-words-method words-search :get "search/{:word}")
(def-wordnik-words-method words-random-words :get "randomWords")
(def-wordnik-words-method words-random-word :get "randomWord")
(def-wordnik-words-method wotd :get "wordOfTheDay")
(def-wordnik-words-method search :get "search/{:word}")
(def-wordnik-words-method random-words :get "randomWords")
(def-wordnik-words-method random-word :get "randomWord")
14 changes: 7 additions & 7 deletions test/wordnik/test/api/account.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
;; test calls that don't require an auth token
(with-api-key *wordnik-api-key*
(is (= true (contains?
(account-authenticate :username *wordnik-username*
:password *wordnik-password*) :token)))
(authenticate :username *wordnik-username*
:password *wordnik-password*) :token)))
(is (= true (contains?
(account-authenticate-post :username *wordnik-username*
:body *wordnik-password*) :token)))
(is (= true ((account-api-token-status) :valid)))
(authenticate-post :username *wordnik-username*
:body *wordnik-password*) :token)))
(is (= true ((api-token-status) :valid)))
;; and calls that do
(let [*test-token* (:token (account-authenticate-post
(let [*test-token* (:token (authenticate-post
:username *wordnik-username*
:body *wordnik-password*))]
(with-auth-token *test-token*
(is (= *wordnik-username* (:userName (account-user))))))))
(is (= *wordnik-username* (:userName (user))))))))
;; see wordnik.test.api.wordlist for account-wordlists test


22 changes: 11 additions & 11 deletions test/wordnik/test/api/word.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
(word :word "cats" :use-canonical false :api-key "key")))
(is (= "funny" (:word (word :word "funny"))))
(is (= "stupid" (:canonicalForm (word :word "stupid"))))
(is (= "ugly" (-> (word-examples :word "ugly")
(is (= "ugly" (-> (examples :word "ugly")
:examples
first
:word)))
(is (= true (let [my-words (-> (word-related :word "big"
:part-of-speech "adjective"
:type "antonym")
(is (= true (let [my-words (-> (related :word "big"
:part-of-speech "adjective"
:type "antonym")
first
:words)]
(seq-contains? my-words "small"))))
(is (= true (contains? (first (word-pronunciations :word "route")) :id)))
(is (= 11 (count (word-hyphenation :word "antidisestablishmentarianism"))))
(is (= 0 (-> (word-frequency :word "software"
:start-year 1806
:end-year 1806)
(is (= true (contains? (first (pronunciations :word "route")) :id)))
(is (= 11 (count (hyphenation :word "antidisestablishmentarianism"))))
(is (= 0 (-> (frequency :word "software"
:start-year 1806
:end-year 1806)
:frequency
first
:count)))
(is (= true (seq-contains? (map #(:gram1 %) (word-phrases :word "lot"))
(is (= true (seq-contains? (map #(:gram1 %) (phrases :word "lot"))
"parking")))
(is (= true (contains? (first (word-audio :word "scout" :limit 1)) :fileUrl)))
(is (= true (contains? (first (audio :word "scout" :limit 1)) :fileUrl)))
))

30 changes: 17 additions & 13 deletions test/wordnik/test/api/wordlist.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
(ns wordnik.test.api.wordlist
(:use wordnik.core
wordnik.util
[wordnik.api account wordlist wordlists]
wordnik.test.properties
re-rand
[clojure.data.json :as json]
clojure.data
clojure.test))
clojure.test)
(:require
[wordnik.api.account :as account]
[wordnik.api.wordlist :as wl]
[wordnik.api.wordlists :as wls]
))

;; wordlist
(def test-wordlist {:name (re-rand #"[A-Za-z0-9]{20}")
Expand All @@ -19,24 +23,24 @@

(deftest wordlist-test
(with-api-key *wordnik-api-key*
(let [token (:token (account-authenticate-post
(let [token (:token (account/authenticate-post
:username *wordnik-username*
:body *wordnik-password*))]
(with-auth-token token
(let [result (wordlists :body (json/json-str test-wordlist))
(let [result (wls/wordlists :body (json/json-str test-wordlist))
wordlist-name (:name result)]
;; test our local object agains the one we created
(is 4 (count (nth (diff test-wordlist result) 2)))
;; now fetch it, and test it again
(is 4 (count (nth (diff result (wordlist-fetch :id wordlist-name)) 2)))
(is 4 (count (nth (diff result (wl/fetch :id wordlist-name)) 2)))

(wordlist-add-words :id wordlist-name
:body (json/json-str test-words))
(is (>= (count (account-wordlists)) 1))
(is 2 (count (wordlist-words :id wordlist-name)))
(wordlist-delete-words :id wordlist-name
:body (json/json-str [{:word "chair"}]))
(is 0 (count (wordlist-words :id wordlist-name)))
(wordlist-delete :id wordlist-name)
(wl/add-words :id wordlist-name
:body (json/json-str test-words))
;;(is (>= (count (account/wordlists)) 1))
(is 2 (count (wl/words :id wordlist-name)))
(wl/delete-words :id wordlist-name
:body (json/json-str [{:word "chair"}]))
(is 0 (count (wl/words :id wordlist-name)))
(wl/delete :id wordlist-name)
)))))

9 changes: 0 additions & 9 deletions test/wordnik/test/api/wordlists.clj

This file was deleted.

8 changes: 4 additions & 4 deletions test/wordnik/test/api/words.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
;; words-random-word
(deftest words-tests
(with-api-key *wordnik-api-key*
(is (= true (contains? (words-wotd) :word)))
(is (= true (contains? (words-search :word "ostracize") :searchResults)))
(is (= 4 (count (words-random-words :limit 4))))
(is (= true (contains? (words-random-word) :word)))
(is (= true (contains? (wotd) :word)))
(is (= true (contains? (search :word "ostracize") :searchResults)))
(is (= 4 (count (random-words :limit 4))))
(is (= true (contains? (random-word) :word)))
))


9 changes: 0 additions & 9 deletions test/wordnik/test/core.clj

This file was deleted.

0 comments on commit 46cf23b

Please sign in to comment.