Skip to content
Browse files

Merge pull request #20 from brandonbloom/defaults

Add support for default options
  • Loading branch information...
2 parents e8874ba + f1376e5 commit 555f70497f41f78902bb06b18298441a2cb0910d @Raynes committed Dec 19, 2012
Showing with 11 additions and 4 deletions.
  1. +2 −0 README.md
  2. +7 −2 src/tentacles/core.clj
  3. +2 −2 src/tentacles/users.clj
View
2 README.md
@@ -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 "https://github.com/Raynes/lein-marginalia.git", :watchers 1, :updated_at "2011-11-23T03:27:47Z", :html_url "https://github.com/Raynes/lein-marginalia", :owner {:login "Raynes", :avatar_url "https://secure.gravatar.com/avatar/54222b6321f0504e0a312c24e97adfc1?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png", :url "https://api.github.com/users/Raynes", :gravatar_id "54222b6321f0504e0a312c24e97adfc1", :id 54435}, :language "Clojure", :size 180, :created_at "2011-11-23T03:27:47Z", :private false, :homepage "", :git_url "git://github.com/Raynes/lein-marginalia.git", :url "https://api.github.com/repos/Raynes/lein-marginalia", :master_branch nil, :ssh_url "git@github.com:Raynes/lein-marginalia.git", :open_issues 0, :id 2832999, :forks 0, :svn_url "https://svn.github.com/Raynes/lein-marginalia", :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.
View
9 src/tentacles/core.clj
@@ -6,12 +6,13 @@
(:import java.net.URLEncoder))
(def ^:dynamic url "https://api.github.com/")
+(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."
[entries]
(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]
~@body))
+
+(defmacro with-defaults [options & body]
+ `(binding [defaults ~options]
+ ~@body))
View
4 src/tentacles/users.clj
@@ -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.
Something went wrong with that request. Please try again.