From c8fdf4bbd2119f4404c607b9b672f894b5aec54a Mon Sep 17 00:00:00 2001 From: gered Date: Fri, 4 Jul 2014 13:40:03 -0400 Subject: [PATCH] refactor --- src/clj_hl7_fhir/core.clj | 9 ++------- src/clj_hl7_fhir/util.clj | 9 ++++++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/clj_hl7_fhir/core.clj b/src/clj_hl7_fhir/core.clj index 0e7d691..9d07121 100644 --- a/src/clj_hl7_fhir/core.clj +++ b/src/clj_hl7_fhir/core.clj @@ -1,9 +1,7 @@ (ns clj-hl7-fhir.core (:import (java.util Date) (clojure.lang ExceptionInfo)) - (:require [clojure.string :as str] - [clj-http.client :as http] - [cheshire.core :as json]) + (:require [clojure.string :as str]) (:use [camel-snake-kebab] [clj-hl7-fhir.util])) @@ -14,10 +12,7 @@ (let [query (cond (sequential? params) (->> params (concat [:_format "json"]) (kv-vector->query)) :else (merge {:_format "json"} params))] - (-> (build-url base-url resource-url query) - (http/get) - :body - (json/parse-string true)))) + (http-get-json (build-url base-url resource-url query)))) (defn- ->search-param-name [parameter & [modifier]] (keyword diff --git a/src/clj_hl7_fhir/util.clj b/src/clj_hl7_fhir/util.clj index 1c320fc..75a7a7c 100644 --- a/src/clj_hl7_fhir/util.clj +++ b/src/clj_hl7_fhir/util.clj @@ -2,7 +2,9 @@ (:import (java.util TimeZone Date) (java.text SimpleDateFormat)) (:require [clojure.string :as str] - [cemerick.url :refer [url url-encode]])) + [clj-http.client :as http] + [cemerick.url :refer [url url-encode]] + [cheshire.core :as json])) (def tz (TimeZone/getDefault)) (def iso8601 "yyyy-MM-dd'T'HH:mm:ssZZ") @@ -41,3 +43,8 @@ (join-paths existing-path path))) (assoc :query params) (str))) + +(defn http-get-json [url] + (-> (http/get url) + :body + (json/parse-string true))) \ No newline at end of file