Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Define :json and :json-string-keys entity-as methods. Bump version to…

… 2.1.0.
  • Loading branch information...
commit 609dc1fd06e8f00db04c3c304657b31a04c75ea3 1 parent 1cca1b9
@rnewman authored
Showing with 14 additions and 3 deletions.
  1. +1 −1  .clojure
  2. +2 −1  project.clj
  3. +11 −1 src/com/twinql/clojure/http.clj
View
2  .clojure
@@ -1 +1 @@
-src:tests:lib/httpclient-4.0.1.jar:lib/httpcore-4.0.1.jar:lib/httpmime-4.0.1.jar:/opt/clojure/clojure.jar:/opt/clojure-contrib/clojure-contrib.jar:lib/commons-logging-1.1.1.jar
+src:tests:lib/ant-1.6.2.jar:lib/apache-mime4j-0.6.jar:lib/classworlds-1.1-alpha-2.jar:lib/clojure-1.2.0-master-20100415.170113-27.jar:lib/clojure-1.2.0-master-20100507.230258-69.jar:lib/clojure-contrib-1.2.0-20100507.230536-107.jar:lib/clojure-contrib-1.2.0-master-20100122.191106-1.jar:lib/commons-codec-1.3.jar:lib/commons-logging-1.1.1.jar:lib/httpclient-4.0.1.jar:lib/httpcore-4.0.1.jar:lib/httpmime-4.0.1.jar:lib/jtidy-4aug2000r7-dev.jar:lib/lein-swank-1.1.0.jar:lib/maven-ant-tasks-2.0.10.jar:lib/maven-artifact-2.0.10.jar:lib/maven-artifact-manager-2.0.10.jar:lib/maven-error-diagnostics-2.0.10.jar:lib/maven-model-2.0.10.jar:lib/maven-plugin-registry-2.0.10.jar:lib/maven-profile-2.0.10.jar:lib/maven-project-2.0.10.jar:lib/maven-repository-metadata-2.0.10.jar:lib/maven-settings-2.0.10.jar:lib/plexus-container-default-1.0-alpha-9-stable-1.jar:lib/plexus-interpolation-1.1.jar:lib/plexus-utils-1.5.5.jar:lib/swank-clojure-1.1.0.jar:lib/wagon-file-1.0-beta-2.jar:lib/wagon-http-lightweight-1.0-beta-2.jar:lib/wagon-http-shared-1.0-beta-2.jar:lib/wagon-provider-api-1.0-beta-2.jar:lib/xml-apis-1.0.b2.jar
View
3  project.clj
@@ -1,5 +1,6 @@
-(defproject com.twinql.clojure/clj-apache-http "2.0.2"
+(defproject com.twinql.clojure/clj-apache-http "2.1.0"
:description "Clojure HTTP library using the Apache HttpClient."
+ :dev-dependencies [[leiningen/lein-swank "1.1.0"]]
:dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"]
[org.clojure/clojure-contrib "1.2.0-SNAPSHOT"]
[org.apache.httpcomponents/httpcore "4.0.1"]
View
12 src/com/twinql/clojure/http.clj
@@ -1,7 +1,9 @@
(ns com.twinql.clojure.http
(:refer-clojure :exclude [get])
(:use clojure.set)
- (:require [clojure.contrib.io :as io])
+ (:require
+ [clojure.contrib.io :as io]
+ [clojure.contrib.json :as json])
(:import
(java.lang Exception)
(java.net URI)
@@ -181,6 +183,14 @@
(defmethod entity-as :string [#^HttpEntity entity as status]
(io/slurp* (.getContent entity)))
+;;; JSON handling.
+;;; We prefer keywordizing.
+(defmethod entity-as :json [#^HttpEntity entity as status]
+ (clojure.contrib.json/read-json (io/reader (.getContent entity)) true))
+
+(defmethod entity-as :json-string-keys [#^HttpEntity entity as status]
+ (clojure.contrib.json/read-json (io/reader (.getContent entity)) false))
+
(defn preemptive-basic-auth-filter
"Returns a function suitable for passing to HTTP
requests. Implements preemptive Basic auth."
Please sign in to comment.
Something went wrong with that request. Please try again.