Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
clj-facebook-graph now uses the clojure.contrib.json/Read-JSON-From p…
Browse files Browse the repository at this point in the history
…rotocol to parse JSON, which resides inside a byte array. Before there was an explicit function for this purpose, which is now unnecessary.
  • Loading branch information
maxweber committed Feb 28, 2011
1 parent 137896f commit c54795d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/clj_facebook_graph/error_handling.clj
Expand Up @@ -7,7 +7,7 @@
; You must not remove this notice, or any other, from this software.

(ns clj-facebook-graph.error-handling
(:use [clj-facebook-graph.helper :only [read-json-body]])
(:use [clojure.contrib.json])
(:import clj_facebook_graph.FacebookGraphException))

(def
Expand Down Expand Up @@ -47,6 +47,6 @@
(if (or (not (clojure.core/get req :throw-exceptions true))
(not= status 400))
resp
(throw (let [resp (assoc resp :body (read-json-body resp))]
(throw (let [resp (assoc resp :body (read-json (:body resp)))]
(FacebookGraphException. (identify-facebook-error resp))))))))

19 changes: 11 additions & 8 deletions src/clj_facebook_graph/helper.clj
Expand Up @@ -8,12 +8,14 @@

(ns clj-facebook-graph.helper
"Some helper functions."
(:use [clojure.contrib.json :only [read-json]]
(:use [clojure.contrib.json :only [read-json read-json-from Read-JSON-From]]
[clojure.java.io :only [reader]]
[clj-http.client :only [generate-query-string]]
[clj-http.client :only [unexceptional-status?]]
[clojure.string :only [blank?]])
(:use ring.middleware.params))
[clojure.string :only [blank?]]
ring.middleware.params)
(:import
(java.io PushbackReader ByteArrayInputStream InputStreamReader)))

(def facebook-base-url "https://graph.facebook.com")

Expand All @@ -23,11 +25,12 @@
(let [f (ns-resolve 'ring.middleware.params 'parse-params)]
(f params "UTF-8")))

(defn read-json-body
"Reads a JSON document from a request body."
[request]
(let [body (:body request)]
(read-json (if (string? body) body (reader body)))))
(extend-type (Class/forName "[B")
Read-JSON-From
(read-json-from [input keywordize? eof-error? eof-value]
(read-json-from (PushbackReader. (InputStreamReader.
(ByteArrayInputStream. input)))
keywordize? eof-error? eof-value)))

(defn build-url [request]
"Builds a URL string which corresponds to the information of the request."
Expand Down

0 comments on commit c54795d

Please sign in to comment.