From b76ae8c42a2198fa206b472c2a6a5dbef257925b Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Sun, 7 Mar 2021 13:03:30 +0100 Subject: 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. --- aws/base.scm | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'aws/base.scm') 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 +;;; Copyright © 2019, 2021 Ricardo Wurmus ;;; ;;; 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)) -- cgit v1.2.3