Starting a Scheme SDK for Equinix Metal

This commit is contained in:
2024-06-07 22:09:24 -04:00
commit 155e15e9f5
5 changed files with 247 additions and 0 deletions

20
metalapi/project.scm Normal file
View File

@@ -0,0 +1,20 @@
(define-module (metalapi project)
#:use-module (metalapi requests)
#:export (list-all-projects
build-project
project->id
project->organization))
(define (list-all-projects)
(handle-pagination "/projects?exclude=devices,memberships,members" "projects" build-project))
(define (build-project project-alist)
(extract-attrs project-alist "id" "name"))
(define (project->id project)
(assoc-ref project "id"))
(define (project->organization project)
(let ((project (GET (format #f "/projects/~a" (project->id project)) (headers))))
(let ((org (GET (assoc-ref (assoc-ref project "organization") "href") (headers))))
(list (assoc "id" org) (assoc "name" org)))))