/
client.clj
43 lines (36 loc) · 1.04 KB
/
client.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
(ns exoscale.compute.api.client
(:require [exoscale.compute.api.http :as http]
[clojure.string :as str]))
(defn capitalizer
"Capitalize Cloudstack word appropriately"
[input]
(if (contains? #{"lb" "ssh" "vpc" "vm"} input)
(str/upper-case input)
(str/capitalize input)))
(defn api-name
"Given a hyphenated name, yield a camel case one"
[op]
(cond
(or (keyword? op) (symbol? op))
(let [[prelude & rest] (str/split (name op) #"-")]
(apply str prelude (map capitalizer rest)))
(string? op)
op
:else
(throw (IllegalArgumentException. "cannot coerce to opcode"))))
(defn parse-uuid
"Cloudstack only knows string UUIDs, coerce
to real ones"
[u]
(when (some? u)
(java.util.UUID/fromString u)))
(defn api-call
([client opcode]
(http/request!! client (api-name opcode) {}))
([client opcode params]
(http/request!! client (api-name opcode) params)))
(comment
;; Try it out!
(require '[exoscale.compute.api.config :as config])
(def config (config/from-environment))
)