Browse files

Merge pull request #20 from brandonbloom/defaults

Add support for default options
  • Loading branch information...
Raynes committed Dec 20, 2012
2 parents e8874ba + f1376e5 commit 555f70497f41f78902bb06b18298441a2cb0910d
Showing with 11 additions and 4 deletions.
  1. +2 −0
  2. +7 −2 src/tentacles/core.clj
  3. +2 −2 src/tentacles/users.clj
@@ -35,6 +35,8 @@ user> (repos/repos {:auth "Raynes:REDACTED" :per-page 1})
[{:fork true, :pushed_at "2011-09-21T05:37:17Z", :name "lein-marginalia", :clone_url "", :watchers 1, :updated_at "2011-11-23T03:27:47Z", :html_url "", :owner {:login "Raynes", :avatar_url "", :url "", :gravatar_id "54222b6321f0504e0a312c24e97adfc1", :id 54435}, :language "Clojure", :size 180, :created_at "2011-11-23T03:27:47Z", :private false, :homepage "", :git_url "git://", :url "", :master_branch nil, :ssh_url "", :open_issues 0, :id 2832999, :forks 0, :svn_url "", :description "A Marginalia plugin to Leiningen "}]
+Default options can be specified via `with-defaults`.
If an API function has no options and authentication would have no uses for that particular call, the options map is not a parameter at all. For API calls that can do different things based on whether or not you are authenticated but authentication is not **required**, then the options map will be an optional argument. For API calls that require authentication to function at all, the options map is a required argument. Any data that is required by an API call is a positional argument to the API functions. The options map only ever contains authentication info and/or optional input.
Authentication is supported by Github user authentication `:auth <username:password>` as demonstrated above, or by oauth or oauth2. For oauth add `:oauth-token <token>` to the options map. Likewise, for oauth2, include `:client-id <client_id> :client-token <client_token>` in the options map.
@@ -6,12 +6,13 @@
(def ^:dynamic url "")
+(def ^:dynamic defaults {})
(defn query-map
- "Turn keywords into strings and replace hyphens with underscores."
+ "Merge defaults, turn keywords into strings, and replace hyphens with underscores."
(into {}
- (for [[k v] entries]
+ (for [[k v] (concat defaults entries)]
[(.replace (name k) "-" "_") v])))
(defn parse-json
@@ -96,3 +97,7 @@
(defmacro with-url [new-url & body]
`(binding [url ~new-url]
+(defmacro with-defaults [options & body]
+ `(binding [defaults ~options]
+ ~@body))
@@ -10,7 +10,7 @@
(defn me
"Get info about the currently authenticated user."
- [options]
+ [& [options]]
(api-call :get "user" nil options))
(defn edit-user
@@ -103,4 +103,4 @@
(defn delete-key
"Delete a public key."
[id options]
- (no-content? (api-call :delete "user/keys/%s" [id] options)))
+ (no-content? (api-call :delete "user/keys/%s" [id] options)))

0 comments on commit 555f704

Please sign in to comment.