summaryrefslogtreecommitdiff
path: root/aws
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2021-03-07 13:03:30 +0100
committerRicardo Wurmus <rekado@elephly.net>2021-03-07 13:08:10 +0100
commitb76ae8c42a2198fa206b472c2a6a5dbef257925b (patch)
treec17caaa00eafa37ac15e90c1150eaa34c6a2ef94 /aws
parent54b59f500d4b45a3879b2a7bfc489fb53ba2b3c3 (diff)
base: aws-operation: Pass request arguments to request constructor.
Instead of expecting a single input of the required type, the procedure returned by AWS-OPERATION now accepts keyword arguments intended for the request constructor. This makes for a much less verbose DSL. Compare the explicit style (DeleteFileSystem (DeleteFileSystemRequest #:FileSystemId "fs-cabba9e")) with the new implicit style: (DeleteFileSystem #:FileSystemId "fs-cabba9e") * aws/base.scm (aws-operation): Accept an input-constructor; apply it to a provided list of keyword arguments. * language/aws/spec.scm (compile-operation): Generate code that specifies the input constructor. * README.org: Update examples.
Diffstat (limited to 'aws')
-rw-r--r--aws/base.scm32
1 files changed, 24 insertions, 8 deletions
diff --git a/aws/base.scm b/aws/base.scm
index 21a55b9..676fdd1 100644
--- a/aws/base.scm
+++ b/aws/base.scm
@@ -1,5 +1,5 @@
;;; guile-aws --- Scheme DSL for the AWS APIs
-;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2019, 2021 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; Guile-AWS is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published
@@ -137,14 +137,30 @@
value type))))
-(define* (aws-operation requester #:key name input-type output-type http documentation)
+(define* (aws-operation requester
+ #:key
+ name
+ input-constructor
+ input-type
+ output-type
+ http documentation)
(let ((proc
- (lambda* (#:optional input)
- (unless (eq? (aws-name input) input-type)
- (error (format #f "~a: input must be of type ~a: ~a~%"
- name input-type input)))
- ;; TODO: do something with the response!
- (requester #:http http #:operation-name name #:input input))))
+ (lambda args
+ (let ((input*
+ (match args
+ ;; Accept a keyword list and pass it to the
+ ;; appropriate constructor.
+ (((? keyword?) . rest)
+ (apply input-constructor args))
+ ;; Otherwise type check the input
+ ((input)
+ (unless (eq? (aws-name input) input-type)
+ (error (format #f "~a: input must be of type ~a: ~a~%"
+ name input-type input)))
+ input)
+ (() #false))))
+ ;; TODO: do something with the response!
+ (requester #:http http #:operation-name name #:input input*)))))
(set-procedure-property! proc 'documentation documentation)
(set-procedure-property! proc 'name name)
proc))