Last active
February 28, 2019 19:44
-
-
Save noprompt/27798aa1b1549155e3b60e7d0983d5ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns scratch | |
(:require | |
[clojure.data.json :as json] | |
[clojure.string :as string] | |
[meander.strategy.alpha :as r] | |
[meander.match.alpha :as r.match])) | |
(def service-2-json | |
(json/read-str | |
(slurp "https://raw.githubusercontent.com/aws/aws-sdk-java-v2/master/services/batch/src/main/resources/codegen-resources/service-2.json"))) | |
(defn class-case-to-kebab-case [s] | |
(string/join "-" (map string/lower-case (string/split s #"(?=[A-Z])")))) | |
(r.match/search service-2-json | |
{"operations" | |
{?operation | |
{"name" ?name | |
"http" {"method" ?http-method | |
"requestUri" ?request-uri} | |
"input" {"shape" ?input-shape-name} | |
"output" {"shape" ?output-shape-name} | |
"errors" [{"shape" !error-shape-names} ...] | |
"documentation" ?documentation}}} | |
(let [fsym (symbol (class-case-to-kebab-case ?name)) | |
;; If the AWS libs are loaded you can add :tag meta with | |
;; the appropriat class names. | |
isym (symbol (class-case-to-kebab-case ?input-shape-name)) | |
osym (symbol (class-case-to-kebab-case ?output-shape-name)) | |
;; Fill this in. | |
http-fn (case ?http-method | |
"POST" | |
'http/post | |
"GET" | |
'http/get) | |
docstring (string/replace ?documentation #"<.*?>" "")] | |
`(defn ~fsym | |
~docstring | |
[~isym] | |
(try | |
;; This probably needs some more massaging but for | |
;; illustration... | |
(~http-fn ~?request-uri ~isym) | |
~@(map | |
(fn [error-shape-name] | |
`(catch ~(symbol error-shape-name) e# | |
;; Fill this in. | |
)) | |
!error-shape-names))))) | |
;; => | |
((clojure.core/defn cancel-job | |
"Cancels a job in an AWS Batch job queue. Jobs that are in the | |
SUBMITTED, PENDING, or RUNNABLE state are cancelled. Jobs that have | |
progressed to STARTING or RUNNING are not cancelled (but the API | |
operation still succeeds, even if no job is cancelled); these jobs | |
must be terminated with the TerminateJob operation." | |
[cancel-job-request] | |
(try | |
(http/post "/v1/canceljob" cancel-job-request) | |
(catch ClientException e__10590__auto__) | |
(catch ServerException e__10590__auto__))) | |
,,,) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment