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

upgrade to data.json 0.2.6 #9

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ pom.xml
*jar
lib
classes
target

.lein*
*.asc
8 changes: 4 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(defproject clj-facebook-graph "0.4.0"
(defproject yayitswei/clj-facebook-graph "0.4.2"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good so far. But I first have time on the weekend to try out the code. Only seen that the fork specific name is still in there.

:description "A Clojure client for the Facebook Graph API."
:dependencies [[org.clojure/clojure "1.3.0"]
[org.clojure/data.json "0.1.1"]
:dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/data.json "0.2.6"]
[ring/ring-core "1.0.1"]
[clj-http "0.2.6"]
[clj-http "1.1.2"]
[clj-oauth2 "0.1.0"]]
:dev-dependencies [[ring/ring-devel "1.0.1"]
[ring/ring-jetty-adapter "1.0.0"]
Expand Down
6 changes: 3 additions & 3 deletions src/clj_facebook_graph/auth.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns clj-facebook-graph.auth
(:use [clj-facebook-graph.helper :only [facebook-base-url facebook-fql-base-url]]
[clojure.data.json :only [read-json]])
(:use [clj-facebook-graph.helper :only [facebook-base-url facebook-fql-base-url]]
[clojure.data.json :only [read-str]])
(:require [clj-oauth2.client :as oauth2]
[clojure.string :as str])
(:import [org.apache.commons.codec.binary Base64]
Expand Down Expand Up @@ -83,7 +83,7 @@
(let [[signiture payload] (str/split signed-request #"\.")
signiture (str (strtr signiture "-_" "+/") "=")]
(when (= signiture (hmac-sha-256 key payload))
(read-json (base64-decode payload))))))
(read-str (base64-decode payload))))))

(defn extract-facebook-auth [session]
(:facebook-auth (val session)))
Expand Down
18 changes: 8 additions & 10 deletions src/clj_facebook_graph/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
(:use [clj-facebook-graph.helper :only [wrap-exceptions facebook-base-url facebook-fql-base-url]]
[clj-facebook-graph.auth :only [wrap-facebook-access-token]]
[clj-facebook-graph.error-handling :only [wrap-facebook-exceptions]]
[clojure.data.json :only [read-json]]
[clj-oauth2.client :only [wrap-oauth2]])
(:require [clj-http.client :as client]))
(:require [clj-http.client :as client]
[clojure.data.json])
(:refer-clojure :exclude [get]))

(defn wrap-facebook-url-builder [client]
"Offers some convenience by assemble a Facebook Graph API URL from a vector of keywords or strings.
Expand All @@ -23,7 +24,7 @@
(here \"friends\"), you can also provide three or more
keywords (or strings) like in the case of 'https://graph.facebook.com/me/videos/uploaded' for example."
(fn [req]
(let [{:keys [url]} req]
(let [{:keys [url]} req]
(if (vector? url)
(let [url-parts-as-str (map #(if (keyword? %) (name %) (str %)) url)
url (apply str (interpose "/" (conj url-parts-as-str facebook-base-url)))]
Expand All @@ -41,7 +42,7 @@
(or
(.startsWith content-type "text/javascript")
(.startsWith content-type "application/json")))
(assoc resp :body (read-json (:body resp)))
(assoc resp :body (clojure.data.json/read-str (:body resp)))
resp))))

(defn wrap-facebook-data-extractor [client]
Expand Down Expand Up @@ -98,21 +99,18 @@
wrap-request-fn
wrap-oauth2
wrap-facebook-access-token
wrap-json-response-conversion
wrap-facebook-url-builder
wrap-facebook-data-extractor
wrap-fql
))
wrap-fql))
([request] (wrap-request request client/wrap-request)))

(def
request
(def request
(wrap-request #'clj-http.core/request))

(defn get
"Like #'request, but sets the :method and :url as appropriate."
[url & [req]]
(request (merge req {:method :get :url url})))
(request (merge req {:method :get :url url :as :json})))

(defn post
"Like #'request, but sets the :method and :url as appropriate."
Expand Down
7 changes: 4 additions & 3 deletions src/clj_facebook_graph/error_handling.clj
Original file line number Diff line number Diff line change
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 [clojure.data.json])
(:require [clojure.data.json])
(:import clj_facebook_graph.FacebookGraphException))

(def
Expand Down Expand Up @@ -47,6 +47,7 @@
(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
(clojure.data.json/read
(clojure.java.io/reader (:body resp))))]
(FacebookGraphException. (identify-facebook-error resp))))))))

10 changes: 1 addition & 9 deletions src/clj_facebook_graph/helper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

(ns clj-facebook-graph.helper
"Some helper functions."
(:use [clojure.data.json :only [read-json read-json-from Read-JSON-From]]
[clojure.java.io :only [reader]]
(:use [clojure.java.io :only [reader]]
[clj-http.client :only [unexceptional-status?]]
[clj-oauth2.uri :only [make-uri]]
[clojure.string :only [blank?]]
Expand All @@ -21,13 +20,6 @@

(def facebook-fql-base-url "https://api.facebook.com/method/fql.query")

(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."
(let [{:keys [server-port server-name uri query-params scheme]} request]
Expand Down