-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
32 lines (28 loc) · 988 Bytes
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(ns democracyworks.smartystreets.core
(:require
[clj-http.client :as http]))
(defrecord Client [auth-id auth-token http-params])
(defn client
"Returns a SmartyStreets client."
([auth-id auth-token]
(client auth-id auth-token {}))
([auth-id auth-token http-params]
{:pre [(string? auth-id)
(string? auth-token)
(map? http-params)]}
(->Client auth-id auth-token http-params)))
(defn http-get
"Make an HTTP GET call to SmartyStreets."
[c url query-params]
(let [opts {:as :json
:query-params (merge (select-keys c [:auth-id :auth-token])
query-params)}]
(http/get url (merge opts (:http-params c)))))
(defn http-post
"Make an HTTP POST call to SmartyStreets."
[c url body]
(let [opts {:as :json
:content-type :json
:query-params (select-keys c [:auth-id :auth-token])
:form-params body}]
(http/post url (merge opts (:http-params c)))))