-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
51 lines (45 loc) · 2.44 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(ns wc-api-clj.core
"Wrapper functions around [[wc-api-clj.rest]] functions to communicate
with the **WooCommerce** REST API endpoints."
(:require [wc-api-clj.rest :as wp-rest]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GET request wrapper function(s) ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn get-req
"GET request wrapper function with authentication. Must need consumer key/secret."
[{:keys [siteurl uri query username password insecure exception]}]
(if (and siteurl uri username password)
(:body (wp-rest/wp-get {:url (str siteurl uri query)
:options {:accept :json
:throw-exceptions (not (not exception))
:insecure? (not (not insecure))
:basic-auth [username password]}}))
(throw (Exception. "You should supply the function with proper arguments"))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; POST request wrapper function(s) ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn post-req
"POST request wrapper function with authentication. Must need consumer key/secret."
[{:keys [url username password body insecure exception]}]
(if (and url username password body)
(:body (wp-rest/wp-post {:url url :options {:basic-auth [username password]
:body body
:headers {"X-Api-Version" "2"}
:content-type :json
:throw-exceptions (not (not exception))
:insecure? (not (not insecure))
:accept :json}}))
(throw (Exception. "You should supply the function with all the arguments needed."))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DELETE request wrapper function(s) ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn delete-req
"DELETE request wrapper function. Must need consumer key/secret."
[{:keys [siteurl uri query username password insecure exception]}]
(if (and siteurl uri username password)
(:body (wp-rest/wp-delete {:url (str siteurl uri query)
:options {:accept :json
:throw-exceptions (not (not exception))
:insecure? (not (not insecure))
:basic-auth [username password]}}))
(throw (Exception. "You should supply the function with all the arguments needed."))))