Permalink
Browse files

Dabbled a bit:

Switched `examples` to a multifn to support lookup by passing a var:
(examples map) vs (examples "clojure.core" "map")

Added pretty print function `pr-examples`
  • Loading branch information...
1 parent 3940fa9 commit f8fd4cfd82ebc54c9b4c0b3bf72323c1071aab40 @zk zk committed Sep 27, 2010
Showing with 25 additions and 4 deletions.
  1. +25 −4 src/cd_client/core.clj
View
29 src/cd_client/core.clj
@@ -1,6 +1,7 @@
(ns cd-client.core
(:require [org.danlarkin.json :as json])
- (:require [clj-http.client :as http]))
+ (:require [clj-http.client :as http]
+ [clojure.string :as string]))
; For testing purposes use localhost:8080
@@ -32,9 +33,30 @@
(defn examples
"Return examples for a given namespace and method name."
- [ns name]
- (format-examples (json/decode-from-str (:body (http/get (str *examples-api* ns "/" name))))))
+ ([v]
+ (let [m (meta v)
+ ns (str (.name (:ns m)))
+ name (str (:name m))]
+ (examples ns name)))
+ ([ns name]
+ (format-examples (json/decode-from-str (:body (http/get (str *examples-api* ns "/" name)))))))
+(defn pr-examples [v]
+ (let [res (examples v)
+ m (meta v)
+ ns (str (.name (:ns m)))
+ name (str (:name m))]
+ (println)
+ (println "======================================== vvv")
+ (doseq [ex res]
+ (println "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
+ (println)
+ (println " " (string/replace (:body ex) #"\n" "\n "))
+ (println)
+ (println " *** Last Updated:" (:updated_at ex))
+ (println))
+ (println "======================================== ^^^")
+ (println (count res) "example(s) found for" (str ns "/" name))))
(defn search
"Search for a method name within an (optional) namespace"
@@ -56,4 +78,3 @@
[ns name]
(json/decode-from-str (:body (http/get (str *seealso-api* ns "/" name)))))
-

0 comments on commit f8fd4cf

Please sign in to comment.