-
Notifications
You must be signed in to change notification settings - Fork 19
/
query-request.lisp
46 lines (43 loc) · 1.58 KB
/
query-request.lisp
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
(defpackage #:aws-sdk/query-request
(:use #:cl)
(:import-from #:aws-sdk/request
#:request
#:request-payload
#:request-headers)
(:import-from #:aws-sdk/session
#:*session*)
(:import-from #:assoc-utils
#:alistp)
(:export #:query-request))
(in-package #:aws-sdk/query-request)
(defclass query-request (request)
())
(defmethod initialize-instance :after ((req query-request) &rest args &key params operation api-version &allow-other-keys)
(declare (ignore args))
(alexandria:appendf (request-headers req)
'(("Content-Type" . "application/x-www-form-urlencoded")))
(setf (request-payload req)
(quri:url-encode-params (append `(("Action" . ,operation)
("Version" . ,api-version))
(loop for (k . v) in params
append (to-query-params k v))))))
(defun to-query-params (key value)
(typecase value
(null)
(cons
(if (alistp value)
(mapcar (lambda (kv)
(cons
(format nil "~A.~A" key (car kv))
(cdr kv)))
(loop for (k . v) in value
append (to-query-params k v)))
(loop for i from 1
for v in value
collect (cons (format nil "~A.member.~A" key i) v))))
(boolean
(list (cons key
(if value
"true"
"false"))))
(otherwise (list (cons key value)))))