Permalink
Browse files

Merge remote branch 'raynes/1.3' into develop

  • Loading branch information...
2 parents 2a02420 + f2d99a2 commit bd3df456f7c0a3d185b0eb898bfbb0e504fcb9c8 @dakrone dakrone committed Oct 17, 2011
Showing with 19 additions and 27 deletions.
  1. +3 −4 project.clj
  2. +16 −23 src/cd_client/core.clj
View
@@ -1,7 +1,6 @@
(defproject org.thnetos/cd-client "0.3.0"
:description "A client for the clojuredocs API"
- :dependencies [[org.clojure/clojure "1.2.0"]
- [org.clojure/clojure-contrib "1.2.0"]
- [clj-http "0.1.1"]
- [org.danlarkin/clojure-json "1.1"]]
+ :dependencies [[org.clojure/clojure "1.3.0"]
+ [clj-http "0.2.1"]
+ [org.clojure/data.json "0.1.2"]]
:dev-dependencies [[swank-clojure "1.2.1"]])
View
@@ -1,18 +1,18 @@
(ns cd-client.core
- (:require [org.danlarkin.json :as json]
+ (:require [clojure.data.json :as json]
[clj-http.client :as http]
[clojure.string :as string])
(:use [clojure.java.browse :only [browse-url]]))
; For testing purposes use localhost:8080
-(def *clojuredocs-root* "http://api.clojuredocs.org")
-;(def *clojuredocs-root* "http://localhost:8080")
+(def ^:dynamic *clojuredocs-root* "http://api.clojuredocs.org")
+;(def ^:dynamic *clojuredocs-root* "http://localhost:8080")
-(def *examples-api* (str *clojuredocs-root* "/examples/"))
-(def *search-api* (str *clojuredocs-root* "/search/"))
-(def *comments-api* (str *clojuredocs-root* "/comments/"))
-(def *seealso-api* (str *clojuredocs-root* "/see-also/"))
+(def ^:dynamic *examples-api* (str *clojuredocs-root* "/examples/"))
+(def ^:dynamic *search-api* (str *clojuredocs-root* "/search/"))
+(def ^:dynamic *comments-api* (str *clojuredocs-root* "/comments/"))
+(def ^:dynamic *seealso-api* (str *clojuredocs-root* "/see-also/"))
(defn- fixup-name-url
@@ -51,25 +51,22 @@
(defmacro handle-fns-etc
[name fn]
- (cond
- (special-form-anchor `~name)
- `(~fn "clojure.core" (str '~name))
- (syntax-symbol-anchor `~name)
- `(~fn "clojure.core" (str '~name))
- :else
+ (if (special-symbol? `~name)
+ `(~fn "clojure.core" (str '~name))
(let [nspace (find-ns name)]
(if nspace
`(println "No usage examples for namespaces as a whole like" '~name
"\nTry a particular symbol in a namespace,"
"e.g. clojure.string/join")
`(call-with-ns-and-name ~fn (var ~name))))))
+(defn- get-simple [url]
+ (json/read-json (:body (http/get url {:accept-encoding ""}))))
(defn examples-core
"Return examples from clojuredocs for a given namespace and name (as strings)"
[ns name]
- (json/decode-from-str (:body (http/get (str *examples-api* ns "/"
- (fixup-name-url name))))))
+ (get-simple (str *examples-api* ns "/" (fixup-name-url name))))
(defmacro examples
@@ -109,17 +106,14 @@
(defn search
"Search for a method name within an (optional) namespace"
- ([name]
- (json/decode-from-str (:body (http/get (str *search-api* name)))))
- ([ns name]
- (json/decode-from-str (:body (http/get (str *search-api* ns "/" name))))))
+ ([name] (get-simple (str *search-api* name)))
+ ([ns name] (get-simple (str *search-api* ns "/" name))))
(defn comments-core
"Return comments from clojuredocs for a given namespace and name (as strings)"
[ns name]
- (json/decode-from-str (:body (http/get (str *comments-api* ns "/"
- (fixup-name-url name))))))
+ (get-simple (str *comments-api* ns "/" (fixup-name-url name))))
(defmacro comments
@@ -162,8 +156,7 @@
(defn see-also-core
"Return 'see also' info from clojuredocs for a given namespace and name (as strings)"
([ns name]
- (json/decode-from-str (:body (http/get (str *seealso-api* ns "/"
- (fixup-name-url name)))))))
+ (get-simple (str *seealso-api* ns "/" (fixup-name-url name)))))
(defmacro see-also

0 comments on commit bd3df45

Please sign in to comment.