From f29f7f831d11f2c0f8847f51946b6f8700374fe4 Mon Sep 17 00:00:00 2001 From: Adam Wynne Date: Fri, 11 Jan 2013 15:05:41 +0000 Subject: [PATCH] Changed the 'action' parameter to 'verb' and added a changelog --- CHANGELOG.md | 6 ++++++ README.md | 23 +++++++++++++++++------ project.clj | 2 +- src/twitter/api/restful.clj | 4 ++-- src/twitter/api/search.clj | 4 ++-- src/twitter/api/streaming.clj | 8 ++++---- src/twitter/core.clj | 24 ++++++++++++------------ src/twitter/oauth.clj | 4 ++-- 8 files changed, 46 insertions(+), 29 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..730a20e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +# twitter-api changelog + +## 0.7.0 +* BREAKING CHANGE: changed the REST function naming convention to the one described in the readme +* updated the tests to reflect the new function names +* added this changelog (recursive overload!) diff --git a/README.md b/README.md index 35d664a..9c3ac86 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ This is an up-to-date twitter API wrapper that is based on the clojure http.asyn Just add the following to your project.clj file in the _dependencies_ section: ``` -[twitter-api "0.6.13"] +[twitter-api "0.7.0"] ``` ## Usage @@ -158,17 +158,28 @@ You can use leiningen to test the library using the following snippet ``` $ lein test -Testing twitter.test.api.restful -2719 [main] INFO com.ning.http.client.providers.netty.NettyAsyncHttpProvider - Number of application's worked threads is 4 -Testing twitter.test.api.search -Testing twitter.test.api.streaming + +Testing twitter.api.test.restful + +Testing twitter.api.test.search + +Testing twitter.api.test.streaming + +Testing twitter.test-utils.core + Testing twitter.test.callbacks + Testing twitter.test.core + Testing twitter.test.creds + Testing twitter.test.request + Testing twitter.test.upload + Testing twitter.test.utils -Ran 47 tests containing 117 assertions. + +Ran 48 tests containing 112 assertions. 0 failures, 0 errors. ``` diff --git a/project.clj b/project.clj index b9765a4..71d8924 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject twitter-api/twitter-api "0.6.13" +(defproject twitter-api/twitter-api "0.7.0" :description "full twitter interface" :plugins [[lein-clojars "0.7.0"] [lein-swank "1.4.4"]] diff --git a/src/twitter/api/restful.clj b/src/twitter/api/restful.clj index b0a7c6d..59ae22e 100644 --- a/src/twitter/api/restful.clj +++ b/src/twitter/api/restful.clj @@ -13,12 +13,12 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defmacro def-twitter-restful-method - [default-action resource-path & rest] + [verb resource-path & rest] (let [json-path (str resource-path ".json") ; v1.1 is .json only. dashed-name (clojure.string/replace resource-path #"[^a-zA-Z]+" "-") ; convert group of symbols to a dash clean-name (clojure.string/replace dashed-name #"-$" "") ; drop trailing dashes fn-name (symbol clean-name)] - `(def-twitter-method ~fn-name ~default-action ~json-path :api ~*rest-api* :callbacks (get-default-callbacks :sync :single) ~@rest))) + `(def-twitter-method ~fn-name ~verb ~json-path :api ~*rest-api* :callbacks (get-default-callbacks :sync :single) ~@rest))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/twitter/api/search.clj b/src/twitter/api/search.clj index 9070611..dbaa061 100644 --- a/src/twitter/api/search.clj +++ b/src/twitter/api/search.clj @@ -10,9 +10,9 @@ (defmacro def-twitter-search-method "defines a search method using the search api context and the synchronous comms" - [name action resource-path & rest] + [name verb resource-path & rest] - `(def-twitter-method ~name ~action ~resource-path :api ~*search-api* :callbacks (get-default-callbacks :sync :single) ~@rest)) + `(def-twitter-method ~name ~verb ~resource-path :api ~*search-api* :callbacks (get-default-callbacks :sync :single) ~@rest)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/twitter/api/streaming.clj b/src/twitter/api/streaming.clj index ecb6857..7776945 100644 --- a/src/twitter/api/streaming.clj +++ b/src/twitter/api/streaming.clj @@ -10,9 +10,9 @@ (defmacro def-twitter-streaming-method "defines a streaming API method using the above api context" - [name action resource-path & rest] + [name verb resource-path & rest] - `(def-twitter-method ~name ~action ~resource-path :api ~*streaming-api* :callbacks (get-default-callbacks :async :streaming) ~@rest)) + `(def-twitter-method ~name ~verb ~resource-path :api ~*streaming-api* :callbacks (get-default-callbacks :async :streaming) ~@rest)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -26,9 +26,9 @@ (defmacro def-twitter-user-streaming-method "defines a user streaming method using the above context" - [name action resource-path & rest] + [name verb resource-path & rest] - `(def-twitter-method ~name ~action ~resource-path :api ~*user-stream-api* :callbacks (get-default-callbacks :async :streaming) ~@rest)) + `(def-twitter-method ~name ~verb ~resource-path :api ~*user-stream-api* :callbacks (get-default-callbacks :async :streaming) ~@rest)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/twitter/core.clj b/src/twitter/core.clj index f122a28..77ea09a 100644 --- a/src/twitter/core.clj +++ b/src/twitter/core.clj @@ -48,12 +48,12 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defn- get-request-args - "takes uri, action and optional args and returns the final uri and http parameters for the subsequent call. + "takes uri, verb and optional args and returns the final uri and http parameters for the subsequent call. Note that the params are transformed (from lispy -'s to x-header-style _'s) and added to the query. So :params could be {:screen-name 'blah'} and it be merged into :query as {:screen_name 'blah'}. The uri has the params substituted in (so {:id} in the uri with use the :id in the :params map). Also, the oauth headers are added if required." - [^Keyword action + [^Keyword verb ^String uri ^PersistentArrayMap arg-map] @@ -64,18 +64,18 @@ final-uri (subs-uri uri params) oauth-map (sign-query (:oauth-creds arg-map) - action + verb final-uri :query query) headers (merge (:headers arg-map) (if oauth-map {:Authorization (oauth-header-string oauth-map)})) - my-args (cond (= action :get) (hash-map :query query :headers headers :body body) + my-args (cond (= verb :get) (hash-map :query query :headers headers :body body) (nil? body) (hash-map :headers (add-form-content-type headers) :body query) :else (hash-map :query query :headers headers :body body))] - {:action action + {:verb verb :uri final-uri :processed-args (merge (dissoc arg-map :query :headers :body :params :oauth-creds :client :api :callbacks) my-args)})) @@ -83,19 +83,19 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defn http-request - "calls the action on the resource specified in the uri, signing with oauth in the headers + "calls the verb on the resource specified in the uri, signing with oauth in the headers you can supply args for async.http.client (e.g. :query, :body, :headers etc)." - [^Keyword action + [^Keyword verb ^String uri ^PersistentArrayMap arg-map] (let [client (or (:client arg-map) (default-client)) callbacks (or (:callbacks arg-map) (throw (Exception. "need to specify a callback argument for http-request"))) - request-args (get-request-args action uri arg-map) + request-args (get-request-args verb uri arg-map) request (apply prepare-request-with-multi - (:action request-args) + (:verb request-args) (:uri request-args) (apply concat (:processed-args request-args)))] ;; (println "request-args" request-args) @@ -109,7 +109,7 @@ As part of the specification, it must have an :api and :callbacks member of the 'rest' list. From these it creates a uri, the api context and relative resource path. The default callbacks that are supplied, determine how to make the call (in terms of the sync/async or single/streaming)" - [fn-name default-action resource-path & rest] + [fn-name default-verb resource-path & rest] (let [rest-map (apply sorted-map rest)] ;; (println "Creating" fn-name) `(defn ~fn-name @@ -117,9 +117,9 @@ (let [arg-map# (merge ~rest-map args#) api-context# (assert-throw (:api arg-map#) "must include an ':api' entry in the params") - action# (or (:verb args#) ~default-action) + verb# (or (:verb args#) ~default-verb) uri# (make-uri api-context# ~resource-path)] - (http-request action# uri# arg-map#))))) + (http-request verb# uri# arg-map#))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; \ No newline at end of file diff --git a/src/twitter/oauth.clj b/src/twitter/oauth.clj index ffc6f31..f21581d 100644 --- a/src/twitter/oauth.clj +++ b/src/twitter/oauth.clj @@ -16,7 +16,7 @@ (defn sign-query "takes oauth credentials and returns a map of the signing parameters" - [#^OauthCredentials oauth-creds action uri & {:keys [query]}] + [#^OauthCredentials oauth-creds verb uri & {:keys [query]}] (if oauth-creds (into (sorted-map) @@ -24,7 +24,7 @@ (oa/credentials (:consumer oauth-creds) (:access-token oauth-creds) (:access-token-secret oauth-creds) - action + verb uri query)))))