Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add method for retrieving the versions clojuredocs knows about.

  • Loading branch information...
commit 1609ea38efd189d56cb33be7c889aac02bfa37cc 1 parent fd47aaa
@dakrone dakrone authored
Showing with 32 additions and 1 deletion.
  1. +5 −0 README.markdown
  2. +27 −1 src/cd_wsapi/core.clj
View
5 README.markdown
@@ -30,6 +30,11 @@ Getting the 'see-also' functions
curl "http://localhost:8080/see-also/clojure.test/are"
+Getting the available versions clojuredocs knows about
+------------------------------------------------------
+
+ curl "http://localhost:8080/versions"
+
License
-------
View
28 src/cd_wsapi/core.clj
@@ -19,7 +19,8 @@
(def db {:classname "com.mysql.jdbc.Driver"
:subprotocol "mysql"
- :subname "//localhost:3306/clojuredocs?user=cd_wsapi&password=cd_wsapi"
+ :subname "//localhost:3306/clojuredocs_development?user=cd_wsapi&password=cd_wsapi"
+; :subname "//localhost:3306/clojuredocs?user=cd_wsapi&password=cd_wsapi"
:create true
:username "cd_wsapi"
:password "cd_wsapi"})
@@ -43,6 +44,30 @@
id))
+(defn get-available-versions
+ "Given nothing, return all available versions clojuredocs knows about.
+
+ Given a namespace and name, return a list of versions for the function."
+ ([]
+ (with-connection
+ db
+ (with-query-results rs ["select distinct version from functions"]
+ (remove nil? (map :version (doall rs))))))
+ ([ns name]
+ (with-connection
+ db
+ (with-query-results rs ["select version from functions where ns = ? and name = ?" ns name]
+ (remove nil? (map :version (doall rs)))))))
+
+
+(defn available-versions
+ []
+ (fn [r]
+ {:status 200
+ :headers {"Content-Type" "application/json"}
+ :body (encode-to-str (get-available-versions))}))
+
+
(defn format-example
"Given an example, format the example for the API JSON output."
[example]
@@ -166,6 +191,7 @@
["search" name] (search name)
["comments" ns name] (get-comments ns name)
["see-also" ns name] (see-also ns name)
+ ["versions"] (available-versions)
[&] default)
request)))
Please sign in to comment.
Something went wrong with that request. Please try again.