Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Misc cleanup, release 0.2.1, more work needed

  • Loading branch information...
commit 3ff6d6758adf2ddc5b25943eb1c413cfd82d767a 1 parent 9e6c386
Lee Hinman authored

Showing 2 changed files with 48 additions and 47 deletions. Show diff stats Hide diff stats

  1. +3 6 project.clj
  2. +45 41 src/cd_wsapi/core.clj
9 project.clj
... ... @@ -1,13 +1,10 @@
1   -(defproject cd-wsapi "0.2.0"
  1 +(defproject cd-wsapi "0.2.1"
2 2 :description "ClojureDocs External API"
3   - :dependencies [[org.clojure/clojure "1.2.0"]
  3 + :dependencies [[org.clojure/clojure "1.2.1"]
4 4 [org.clojure/clojure-contrib "1.2.0"]
5 5 [mysql/mysql-connector-java "5.1.12"]
6 6 [aleph "0.1.0-SNAPSHOT"]
7 7 [net.cgrand/moustache "1.0.0-SNAPSHOT"]
8 8 [org.danlarkin/clojure-json "1.1"]]
9   - :dev-dependencies [[leiningen/lein-swank "1.2.0-SNAPSHOT"]
10   - [leiningen-init-script "1.2.0-SNAPSHOT"]]
11   - :lis-opts {:properties {:config-clj.env "prod"}
12   - :redirect-output-to "/var/log/cd-wsapi.log"}
  9 + :dev-dependencies []
13 10 :main main)
86 src/cd_wsapi/core.clj
@@ -8,19 +8,19 @@
8 8 (def *default-page* (slurp "resources/index.html"))
9 9
10 10 ;;JSON Encoders
11   -(add-encoder
12   - java.util.Date
13   - (fn [#^java.util.Date date #^java.io.Writer writer
14   - #^String pad #^String current-indent
15   - #^String start-token-indent #^Integer indent-size]
16   - (.append writer (str start-token-indent \" date \"))))
  11 +(add-encoder
  12 + java.util.Date
  13 + (fn [#^java.util.Date date #^java.io.Writer writer
  14 + #^String pad #^String current-indent
  15 + #^String start-token-indent #^Integer indent-size]
  16 + (.append writer (str start-token-indent \" date \"))))
17 17
18 18 ;; Database
19 19
20 20 (def db {:classname "com.mysql.jdbc.Driver"
21 21 :subprotocol "mysql"
22 22 :subname "//localhost:3306/clojuredocs_development?user=cd_wsapi&password=cd_wsapi"
23   -; :subname "//localhost:3306/clojuredocs_production?user=cd_wsapi&password=cd_wsapi"
  23 + ; :subname "//localhost:3306/clojuredocs_production?user=cd_wsapi&password=cd_wsapi"
24 24 :create true
25 25 :username "cd_wsapi"
26 26 :password "cd_wsapi"})
@@ -114,21 +114,21 @@
114 114 {:status 200
115 115 :headers {"Content-Type" "application/json"}
116 116 :body (encode-to-str
117   - (with-connection db
118   - (transaction
119   - (when-let [functions (with-query-results rs queryvec (doall rs))]
120   - (map format-search functions)))))}))
  117 + (with-connection db
  118 + (transaction
  119 + (when-let [functions (with-query-results rs queryvec (doall rs))]
  120 + (map format-search functions)))))}))
121 121
122 122
123 123 (defn search
124 124 "Search for a method by name or namespace & name."
125 125 ([name]
126   - (search nil name))
  126 + (search nil name))
127 127 ([ns name]
128 128 (let [qv (if (nil? ns)
129   - [(str "select id,name,ns from flat_functions_view where name like '%" name "%'")]
130   - [(str "select id,name,ns from flat_functions_view where ns = ? and name like '%" name "%'") ns])]
131   - (perform-search qv))))
  129 + [(str "select id,name,ns from flat_functions_view where name like '%" name "%'")]
  130 + [(str "select id,name,ns from flat_functions_view where ns = ? and name like '%" name "%'") ns])]
  131 + (perform-search qv))))
132 132
133 133
134 134 (defn format-comment
@@ -145,16 +145,20 @@
145 145 (fn [n]
146 146 {:status 200
147 147 :headers {"Content-Type" "application/json"}
148   - :body (encode-to-str
149   - (with-connection db
150   - (transaction
151   - (when-let [comments (with-query-results
152   - rs
153   - (if version
154   - ["select * from flat_comments_view where ns = ? and function = ? and version = ?" ns name version]
155   - ["select * from flat_comments_view where ns = ? and function = ?" ns name])
156   - (doall rs))]
157   - (map format-comment comments)))))})))
  148 + :body (.replaceAll
  149 + (encode-to-str
  150 + (with-connection db
  151 + (transaction
  152 + (when-let
  153 + [comments
  154 + (with-query-results
  155 + rs
  156 + (if version
  157 + ["select * from flat_comments_view where ns = ? and function = ? and version = ?" ns name version]
  158 + ["select * from flat_comments_view where ns = ? and function = ?" ns name])
  159 + (doall rs))]
  160 + (map format-comment comments)))))
  161 + "\\\\r" "")})))
158 162
159 163
160 164 (defn format-see-also-function
@@ -168,12 +172,12 @@
168 172 "Given an id, format the function to see also."
169 173 [id]
170 174 (with-connection db
171   - (transaction
172   - (when-let [functions (with-query-results
173   - rs
174   - ["select * from functions where id = ?" (:to_id id)]
175   - (doall rs))]
176   - (format-see-also-function (first functions)))))) ; should only be 1 function per id
  175 + (transaction
  176 + (when-let [functions (with-query-results
  177 + rs
  178 + ["select * from functions where id = ?" (:to_id id)]
  179 + (doall rs))]
  180 + (format-see-also-function (first functions)))))) ; should only be 1 function per id
177 181
178 182
179 183 (defn see-also
@@ -183,18 +187,18 @@
183 187 {:status 200
184 188 :headers {"Content-Type" "application/json"}
185 189 :body (encode-to-str
186   - (with-connection db
187   - (transaction
188   - (when-let [see-also-ids (with-query-results
189   - rs
190   - ["select to_id from flat_see_alsos_view where ns = ? and function = ?" ns name]
191   - (doall rs))]
192   - (map format-see-also see-also-ids)))))}))
  190 + (with-connection db
  191 + (transaction
  192 + (when-let [see-also-ids (with-query-results
  193 + rs
  194 + ["select to_id from flat_see_alsos_view where ns = ? and function = ?" ns name]
  195 + (doall rs))]
  196 + (map format-see-also see-also-ids)))))}))
193 197
194 198
195 199
196 200 (defn app-handler [channel request]
197   - (enqueue-and-close
  201 + (enqueue-and-close
198 202 channel
199 203 ((app
200 204 ["examples" ns name] (examples ns name)
@@ -219,8 +223,8 @@
219 223
220 224
221 225 (defn restart-server []
222   - (server)
223   - (def server (start-http-server app-wrapper {:port *server-port*})))
  226 + (server)
  227 + (def server (start-http-server app-wrapper {:port *server-port*})))
224 228
225 229 (restart-server))
226 230

0 comments on commit 3ff6d67

Please sign in to comment.
Something went wrong with that request. Please try again.