emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/srht 4d8d740299 1/5: Replace all the words "domain" in


From: ELPA Syncer
Subject: [elpa] externals/srht 4d8d740299 1/5: Replace all the words "domain" in the arguments with "instance".
Date: Sat, 11 Nov 2023 18:58:29 -0500 (EST)

branch: externals/srht
commit 4d8d740299b163104ccc50d08293aa6344dbc955
Author: Aleksandr Vityazev <avityazev@posteo.org>
Commit: Aleksandr Vityazev <avityazev@posteo.org>

    Replace all the words "domain" in the arguments with "instance".
---
 lisp/srht-builds.el |  42 +++++++-------
 lisp/srht-git.el    | 164 ++++++++++++++++++++++++++--------------------------
 lisp/srht-paste.el  |  92 ++++++++++++++---------------
 lisp/srht.el        |  55 +++++++++---------
 4 files changed, 177 insertions(+), 176 deletions(-)

diff --git a/lisp/srht-builds.el b/lisp/srht-builds.el
index dea0d46353..4d78d7531d 100644
--- a/lisp/srht-builds.el
+++ b/lisp/srht-builds.el
@@ -25,21 +25,21 @@
 
 (require 'srht)
 
-(defun srht-builds--make-crud (domain path &optional query body)
-  "Make a crud for the builds service for the DOMAIN of the Sourcehut instance.
+(defun srht-builds--make-crud (instance path &optional query body)
+  "Make a crud for the builds service for the INSTANCE of the Sourcehut 
instance.
 PATH is the path for the URI.  BODY is the body sent to the URI.
 QUERY is the query for the URI.  To retrieve the next page of results,
 add start=:id to your QUERY, using the :id given by \"next\"."
   (declare (indent 1))
-  (srht-generic-crud domain 'builds path query body))
+  (srht-generic-crud instance 'builds path query body))
 
-(defun srht-builds-jobs (domain &optional query details)
-  "Return a paginated list of job resources from the DOMAIN instance.
+(defun srht-builds-jobs (instance &optional query details)
+  "Return a paginated list of job resources from the INSTANCE instance.
 Or inserts a new job into the job queue with POST request.
 To retrieve the next page of results, add start=:id to your QUERY,
 using the :id given by \"next\". When insert a new job, you must specify
 DETAILS (see `srht-builds-make') and omit query."
-  (srht-builds--make-crud domain "/api/jobs" query details))
+  (srht-builds--make-crud instance "/api/jobs" query details))
 
 (cl-defun srht-builds-make (&key manifest note tags
                                  (execute "true")
@@ -57,35 +57,35 @@ build immediately.  SECRTETS - true to provide secrets 
during the build."
     (execute . ,execute)
     (secrtets . ,secrtets)))
 
-(defun srht-builds-job (domain id)
-  "Retrieve information about a job by its ID from the DOMAIN instance."
-  (srht-builds--make-crud domain (format "/api/jobs/%d" id)))
+(defun srht-builds-job (instance id)
+  "Retrieve information about a job by its ID from the INSTANCE instance."
+  (srht-builds--make-crud instance (format "/api/jobs/%d" id)))
 
-(defun srht-builds-job-artifacts (domain id &optional query)
+(defun srht-builds-job-artifacts (instance id &optional query)
   "Retrieve a paginated list of artifact resources created by job with ID.
 To retrieve the next page of results, add start=:id to your QUERY, using
-the :id given by \"next\".  DOMAIN is the domain name of the Sourcehut
+the :id given by \"next\".  INSTANCE is the instance name of the Sourcehut
 instance."
-  (srht-builds--make-crud domain
+  (srht-builds--make-crud instance
     (format "/api/jobs/%d/artifacts" id) query))
 
-(defun srht-builds-job-manifest (domain id)
+(defun srht-builds-job-manifest (instance id)
   "Retrieve a build manifest as plain text for a job with ID.
-DOMAIN is the domain name of the Sourcehut instance."
-  (srht-builds--make-crud domain
+INSTANCE is the instance name of the Sourcehut instance."
+  (srht-builds--make-crud instance
     (format "/api/jobs/%d/manifest" id)))
 
-(defun srht-builds-job-start (domain id)
+(defun srht-builds-job-start (instance id)
   "Start a job with ID that was created with execute=false.
 Returns an empty JSON object when successful.
-DOMAIN is the domain name of the Sourcehut instance."
-  (srht-builds--make-crud domain
+INSTANCE is the instance name of the Sourcehut instance."
+  (srht-builds--make-crud instance
     (format "/api/jobs/%d/start" id) nil "{}"))
 
-(defun srht-builds-job-cancel (domain id)
+(defun srht-builds-job-cancel (instance id)
   "Cancels a running job with ID.  Return an empty JSON object when successful.
-DOMAIN is the domain name of the Sourcehut instance."
-  (srht-builds--make-crud domain
+INSTANCE is the instance name of the Sourcehut instance."
+  (srht-builds--make-crud instance
     (format "/api/jobs/%d/cancel" id) nil "{}"))
 
 (provide 'srht-builds)
diff --git a/lisp/srht-git.el b/lisp/srht-git.el
index 83f707f532..301b20bacf 100644
--- a/lisp/srht-git.el
+++ b/lisp/srht-git.el
@@ -28,32 +28,32 @@
 (require 'srht)
 
 (defvar srht-git-repos nil
-  "Authenticated user repos plist of the form (:domain repos ...).")
+  "Authenticated user repos plist of the form (:instance repos ...).")
 
-(defun srht-git--make-crud (domain path &optional query body form)
-  "Make a crud for the git service for the DOMAIN of the Sourcehut instance.
+(defun srht-git--make-crud (instance path &optional query body form)
+  "Make a crud for the git service for the INSTANCE of the Sourcehut instance.
 PATH is the path for the URI.  BODY is the body sent to the URI.
 FORM is a content type.  QUERY is the query for the URI."
   (declare (indent 1))
-  (srht-generic-crud domain 'git path query body form))
+  (srht-generic-crud instance 'git path query body form))
 
-(defun srht-git-user (domain &optional username)
-  "Retrieves a user resource from DOMAIN.
+(defun srht-git-user (instance &optional username)
+  "Retrieves a user resource from INSTANCE.
 If USERNAME is nil, the authenticated user is assumed."
   (let ((path (if username
                   (concat "/api/user/~" (string-trim-left username "~"))
                 "/api/user")))
-    (srht-git--make-crud domain path)))
+    (srht-git--make-crud instance path)))
 
-(defun srht-git-repos (domain &optional username query)
-  "Retrive list of repository resources owned by this USERNAME from DOMAIN.
+(defun srht-git-repos (instance &optional username query)
+  "Retrive list of repository resources owned by this USERNAME from INSTANCE.
 If USERNAME is nil the authenticated user is assumed.
 QUERY is the query for the URI.  To retrieve the next page of results,
 add start=:id to your QUERY, using the :id given by \"next\"."
   (let ((path (if username
                   (format "/api/~%s/repos" (string-trim-left username "~"))
                 "/api/repos")))
-    (srht-git--make-crud domain path query)))
+    (srht-git--make-crud instance path query)))
 
 (cl-defun srht-git-make (&key visibility description name)
   "Make paste parameters.
@@ -66,8 +66,8 @@ NAME is repository name."
     (description . ,description)
     (visibility . ,visibility)))
 
-(defun srht-git-repo (domain repo-name &optional username &rest details)
-  "Create, retrieve, delete or update a git repository from DOMAIN.
+(defun srht-git-repo (instance repo-name &optional username &rest details)
+  "Create, retrieve, delete or update a git repository from INSTANCE.
 
 When retrieving, deleting or updating a repository, REPO-NAME must be
 the name of an existing repository.
@@ -81,17 +81,17 @@ When creating repository omit REPO-NAME and specify DETAILS
 \(see `srht-git-make'\)."
   (cond
    ((and (stringp repo-name) (stringp username))
-    (srht-git--make-crud domain
+    (srht-git--make-crud instance
       (format "/api/~%s/repos/%s" (string-trim-left username "~") repo-name)))
    ((and (stringp repo-name) details)
-    (srht-git--make-crud domain
+    (srht-git--make-crud instance
       (format "/api/repos/%s" repo-name) nil (apply #'srht-git-make details)))
    ((stringp repo-name)
-    (srht-git--make-crud domain (format "/api/repos/%s" repo-name)))
-   (t (srht-git--make-crud domain "/api/repos" nil (apply #'srht-git-make 
details)))))
+    (srht-git--make-crud instance (format "/api/repos/%s" repo-name)))
+   (t (srht-git--make-crud instance "/api/repos" nil (apply #'srht-git-make 
details)))))
 
-(defmacro srht-git--endpoint (domain endpoint name username &optional query 
body form)
-  "Generate crud for ENDPOINT and repository NAME for DOMAIN.
+(defmacro srht-git--endpoint (instance endpoint name username &optional query 
body form)
+  "Generate crud for ENDPOINT and repository NAME for INSTANCE.
 If USERNAME is nil the authenticated user is assumed.
 QUERY is the query for the URI.  To retrieve the next page of results,
 add start=:id to your QUERY, using the :id given by \"next\".
@@ -102,115 +102,115 @@ FORM is a content type."
                       (format "/api/~%s/repos/%s/%s"
                               (string-trim-left ,username "~") ,name ,endpoint)
                     (format "/api/repos/%s/%s" ,name ,endpoint))))
-       (srht-git--make-crud ,domain ,path ,query ,body ,form))))
+       (srht-git--make-crud ,instance ,path ,query ,body ,form))))
 
-(defun srht-git--endpoint-widen (endpoint domain name end &optional username 
body-or-query)
-  "Extend the ENDPOINT for the repository NAME from DOMAIN to include END.
+(defun srht-git--endpoint-widen (endpoint instance name end &optional username 
body-or-query)
+  "Extend the ENDPOINT for the repository NAME from INSTANCE to include END.
 If USERNAME is nil the authenticated user is assumed.
 BODY-OR-QUERY is the body or query sent to the URI."
   (let* ((plist (if body-or-query
-                    (funcall domain endpoint name username body-or-query)
-                  (funcall domain endpoint name username)))
+                    (funcall instance endpoint name username body-or-query)
+                  (funcall instance endpoint name username)))
          (path (plist-get plist :path)))
     (setf (plist-get plist :path)
           (concat path "/" end))
     plist))
 
-(defun srht-git--artifact (domain name username body)
+(defun srht-git--artifact (instance name username body)
   "Helper function for `srht-git-repo-artifact'."
-  (srht-git--endpoint domain "artifacts" name username body 
"multipart/form-data"))
+  (srht-git--endpoint instance "artifacts" name username body 
"multipart/form-data"))
 
-(defun srht-git-repo-readme (domain name &optional username body form)
-  "Retrieve, update or delete README override for repository NAME from DOMAIN.
+(defun srht-git-repo-readme (instance name &optional username body form)
+  "Retrieve, update or delete README override for repository NAME from 
INSTANCE.
 
 If USERNAME is nil the authenticated user is assumed.
 BODY is the body sent to the URI.  FORM is a content type."
-  (srht-git--endpoint domain "readme" name username body form))
+  (srht-git--endpoint instance "readme" name username body form))
 
-(defun srht-git-repo-refs (domain name &optional username query)
-  "Endpoints for fetching git data from repository NAME from DOMAIN.
+(defun srht-git-repo-refs (instance name &optional username query)
+  "Endpoints for fetching git data from repository NAME from INSTANCE.
 If USERNAME is nil the authenticated user is assumed.
 QUERY is the query for the URI."
-  (srht-git--endpoint domain "refs" name username query))
+  (srht-git--endpoint instance "refs" name username query))
 
-(defun srht-git-repo-log (domain name &optional username query)
-  "List of the latest commit log for repository NAME from DOMAIN.
+(defun srht-git-repo-log (instance name &optional username query)
+  "List of the latest commit log for repository NAME from INSTANCE.
 If USERNAME is nil the authenticated user is assumed.
 QUERY is the query for the URI."
-  (srht-git--endpoint domain "log" name username query))
+  (srht-git--endpoint instance "log" name username query))
 
-(defun srht-git-repo-artifact (domain name ref body &optional username)
-  "Attaches a file artifact to the specified REF and repository NAME from 
DOMAIN.
+(defun srht-git-repo-artifact (instance name ref body &optional username)
+  "Attaches a file artifact to the specified REF and repository NAME from 
INSTANCE.
 Note: this endpoint does not accept JSON.  Submit your request
 as `multipart/form-data', with a single field: file in BODY."
-  (srht-git--endpoint-widen #'srht-git--artifact domain name ref username 
body))
+  (srht-git--endpoint-widen #'srht-git--artifact instance name ref username 
body))
 
-(defun srht-git-repo-log-ref (domain name ref &optional username query)
-  "List of the latest commit resources starting from the given REF and DOMAIN.
+(defun srht-git-repo-log-ref (instance name ref &optional username query)
+  "List of the latest commit resources starting from the given REF and 
INSTANCE.
 NAME is a repository name.  If USERNAME is nil the authenticated user
 is assumed.  QUERY is the query for the URI."
-  (srht-git--endpoint-widen #'srht-git-repo-log domain name ref username 
query))
+  (srht-git--endpoint-widen #'srht-git-repo-log instance name ref username 
query))
 
-(defun srht-git-repo-tree-ref (domain name ref &optional username query)
-  "Return the tree resource for the given REF from DOMAIN.
+(defun srht-git-repo-tree-ref (instance name ref &optional username query)
+  "Return the tree resource for the given REF from INSTANCE.
 Following the parent trees until the requested tree is found.
 In other words, this lists the contents of a subdirectory by path.
 NAME is a repository name.  If USERNAME is nil the authenticated user
 is assumed.  QUERY is the query for the URI."
-  (srht-git--endpoint-widen #'srht-git-repo-tree domain name ref username 
query))
+  (srht-git--endpoint-widen #'srht-git-repo-tree instance name ref username 
query))
 
-(defun srht-git-repo-tree-id (domain name id &optional username query)
-  "Return the tree resource with the given ID from DOMAIN.
+(defun srht-git-repo-tree-id (instance name id &optional username query)
+  "Return the tree resource with the given ID from INSTANCE.
 NAME is a repository name.  If USERNAME is nil the authenticated user
 is assumed.  QUERY is the query for the URI."
-  (srht-git--endpoint-widen #'srht-git-repo-tree domain name id username 
query))
+  (srht-git--endpoint-widen #'srht-git-repo-tree instance name id username 
query))
 
-(defun srht-git-repo-tree (domain name &optional username)
+(defun srht-git-repo-tree (instance name &optional username)
   "Return the tree resource for the latest commit to the default branch.
-DOMAIN is the domain name of the Sourcehut instance.
+INSTANCE is the instance name of the Sourcehut instance.
 NAME is a repository name.  If USERNAME is nil the authenticated user
 is assumed."
-  (srht-git--endpoint domain "tree" name username))
+  (srht-git--endpoint instance "tree" name username))
 
-(defun srht-git--candidates (domain)
-  "Return completion candidates for DOMAIN."
+(defun srht-git--candidates (instance)
+  "Return completion candidates for INSTANCE."
   (seq-map (pcase-lambda ((map (:created c)
                                (:visibility v)
                                (:name n)))
              (list n c v))
-           (srht-results-get domain
+           (srht-results-get instance
              (or srht-git-repos
                  (srht-put srht-git-repos
-                   domain (srht-retrive (srht-git-repos domain)))))))
+                   instance (srht-retrive (srht-git-repos instance)))))))
 
-(defun srht-git--annot (domain str)
-  "Function to add annotations in the completions buffer for STR and DOMAIN."
+(defun srht-git--annot (instance str)
+  "Function to add annotations in the completions buffer for STR and INSTANCE."
   (pcase-let (((seq _n created visibility)
-               (assoc str (srht-git--candidates domain))))
+               (assoc str (srht-git--candidates instance))))
     (srht-annotation str visibility created)))
 
-(defun srht-git--repo-name-read (domain)
+(defun srht-git--repo-name-read (instance)
   "Read a repository name in the minibuffer, with completion.
-DOMAIN is the domain name of the Sourcehut instance."
+INSTANCE is the instance name of the Sourcehut instance."
   (srht-read-with-annotaion "Select repository: "
-    (srht-git--candidates domain)
-    (lambda (str) (srht-git--annot domain str))
+    (srht-git--candidates instance)
+    (lambda (str) (srht-git--annot instance str))
     'sourcehut-git-repository))
 
 (defvar srht-git-repo-name-history nil
   "History variable.")
 
 ;;;###autoload
-(defun srht-git-repo-create (domain visibility name description)
-  "Create the NAME repository on an instance with the domain name DOMAIN.
+(defun srht-git-repo-create (instance visibility name description)
+  "Create the NAME repository on an instance with the instance name INSTANCE.
 Set VISIBILITY and DESCRIPTION."
   (interactive
-   (list (srht-read-domain "Instance: ")
+   (list (srht-read-instance "Instance: ")
          (srht-read-visibility "Visibility: ")
         (read-string "New git repository name: " nil
                       'srht-git-repo-name-history)
          (read-string "Repository description (markdown): ")))
-  (srht-create (srht-git-repo domain nil nil
+  (srht-create (srht-git-repo instance nil nil
                               :visibility visibility
                               :name name
                               :description description)
@@ -219,27 +219,27 @@ Set VISIBILITY and DESCRIPTION."
                                           (:owner (map (:canonical_name 
username))))
                                      results)
                                     (url (srht--make-uri
-                                          domain 'git
+                                          instance 'git
                                           (format "/%s/%s" username repo-name) 
nil)))
                          (srht-copy-url url)
                          (srht-browse-url url)
-                         (srht-retrive (srht-git-repos domain)
+                         (srht-retrive (srht-git-repos instance)
                                        :then (lambda (resp)
-                                               (srht-put srht-git-repos domain 
resp)))))))
+                                               (srht-put srht-git-repos 
instance resp)))))))
 
-(defun srht-git--find-info (domain repo-name)
-  "Find repository information by REPO-NAME from the DOMAIN instance."
+(defun srht-git--find-info (instance repo-name)
+  "Find repository information by REPO-NAME from the INSTANCE instance."
   (catch 'found
-    (seq-doseq (repo (plist-get (plist-get srht-git-repos domain) :results))
+    (seq-doseq (repo (plist-get (plist-get srht-git-repos instance) :results))
       (when (equal (cl-getf repo :name) repo-name)
         (throw 'found repo)))))
 
 ;;;###autoload
-(defun srht-git-repo-update (domain repo-name visibility new-name description)
-  "Update the REPO-NAME repository from the DOMAIN instance.
+(defun srht-git-repo-update (instance repo-name visibility new-name 
description)
+  "Update the REPO-NAME repository from the INSTANCE instance.
 Set VISIBILITY, NEW-NAME and DESCRIPTION."
   (interactive
-   (pcase-let* ((instance (srht-read-domain "Instance: "))
+   (pcase-let* ((instance (srht-read-instance "Instance: "))
                 (name (srht-git--repo-name-read instance))
                 ((map (:visibility v)
                       (:description d))
@@ -251,7 +251,7 @@ Set VISIBILITY, NEW-NAME and DESCRIPTION."
                         'srht-git-repo-name-history)
            (read-string "Repository description (markdown): " d))))
   (when (yes-or-no-p (format "Update %s repository?" repo-name))
-    (srht-update (srht-git-repo domain repo-name nil
+    (srht-update (srht-git-repo instance repo-name nil
                                 :visibility visibility
                                 :name new-name
                                 :description description)
@@ -265,27 +265,27 @@ Set VISIBILITY, NEW-NAME and DESCRIPTION."
                          ;;  :description nil
                          ;;  :visibility unlisted)
                          (message "Updated!")
-                         (srht-retrive (srht-git-repos domain)
+                         (srht-retrive (srht-git-repos instance)
                                        :then (lambda (resp)
-                                               (srht-put srht-git-repos domain 
resp)
+                                               (srht-put srht-git-repos 
instance resp)
                                                ))))))
 
 ;;;###autoload
-(defun srht-git-repo-delete (domain repo-name)
-  "Delete the REPO-NAME repository from the DOMAIN instance."
+(defun srht-git-repo-delete (instance repo-name)
+  "Delete the REPO-NAME repository from the INSTANCE instance."
   (interactive
-   (let ((instance (srht-read-domain "Instance: ")))
+   (let ((instance (srht-read-instance "Instance: ")))
      (list instance (srht-git--repo-name-read instance))))
   (when (yes-or-no-p
          (format "This action cannot be undone.\n Delete %s repository?" 
repo-name))
     (srht-delete
-     (srht-git-repo domain repo-name)
+     (srht-git-repo instance repo-name)
      :as 'string
      :then (lambda (_r)
              (srht-retrive
-              (srht-git-repos domain)
+              (srht-git-repos instance)
               :then (lambda (resp)
-                      (srht-put srht-git-repos domain resp)
+                      (srht-put srht-git-repos instance resp)
                       (message (format "Sourcehut %s git repository deleted!" 
repo-name)
                                )))))))
 
diff --git a/lisp/srht-paste.el b/lisp/srht-paste.el
index 5b5f3f390a..1dc6867ed4 100644
--- a/lisp/srht-paste.el
+++ b/lisp/srht-paste.el
@@ -26,13 +26,13 @@
 (require 'srht)
 
 (defvar srht-paste-all-pastes nil
-  "Stores pastes plist of the form (:domain pastes ...).")
+  "Stores pastes plist of the form (:instance pastes ...).")
 
-(defun srht-paste--make-crud (domain path &optional query body)
-  "Make crud for paste service for the DOMAIN of the Sourcehut instance.
+(defun srht-paste--make-crud (instance path &optional query body)
+  "Make crud for paste service for the INSTANCE of the Sourcehut instance.
 PATH is the path for the URI.  BODY is the body sent to the URI.
 QUERY is the query for the URI."
-  (srht-generic-crud domain 'paste path query body))
+  (srht-generic-crud instance 'paste path query body))
 
 (cl-defun srht-paste-make (&key (visibility "unlisted") (filename 'null) 
contents)
   "Make paste parameters.
@@ -44,52 +44,52 @@ CONTENTS must be a UTF-8 encoded string; binary files are 
not allowed."
     (files . [((filename . ,filename)
                (contents . ,contents))])))
 
-(defun srht-pastes (domain &optional query)
-  "Get all pastes owned by the authenticated user and instance with DOMAIN.
+(defun srht-pastes (instance &optional query)
+  "Get all pastes owned by the authenticated user and instance with INSTANCE.
 QUERY is the query for the URI."
-  (srht-paste--make-crud domain "/api/pastes" query))
+  (srht-paste--make-crud instance "/api/pastes" query))
 
-(defun srht-paste-blob (domain sha)
-  "Retrieve a blob resource with the hash SHA from the DOMAIN instance."
-  (srht-paste--make-crud domain (format "/api/blobs/%s" sha)))
+(defun srht-paste-blob (instance sha)
+  "Retrieve a blob resource with the hash SHA from the INSTANCE instance."
+  (srht-paste--make-crud instance (format "/api/blobs/%s" sha)))
 
-(defun srht-paste--domain-results-get (domain pastes)
+(defun srht-paste--instance-results-get (instance pastes)
   "Extract the value for the :results property.
-For the existing PASTES for the DOMAIN domain name."
+For the existing PASTES for the INSTANCE instance name."
   (declare (indent 1))
-  (plist-get (plist-get pastes (intern domain)) :results))
+  (plist-get (plist-get pastes (intern instance)) :results))
 
-(defun srht-paste--candidates (domain)
-  "Return completion candidates for DOMAIN."
+(defun srht-paste--candidates (instance)
+  "Return completion candidates for INSTANCE."
   (seq-map (pcase-lambda ((map (:created c)
                                (:visibility v)
                                (:sha sha)
                                (:files (seq (map (:filename fn))))))
              (list fn c v sha))
-           (srht-results-get domain
+           (srht-results-get instance
              (or srht-paste-all-pastes
                  (srht-put srht-paste-all-pastes
-                   domain (srht-retrive (srht-pastes domain)))))))
+                   instance (srht-retrive (srht-pastes instance)))))))
 
-(defun srht-paste--annot (domain str)
-  "Function to add annotations in the completions buffer for STR and DOMAIN."
+(defun srht-paste--annot (instance str)
+  "Function to add annotations in the completions buffer for STR and INSTANCE."
   (pcase-let (((seq _f created visibility)
-               (assoc str (srht-paste--candidates domain))))
+               (assoc str (srht-paste--candidates instance))))
     (srht-annotation str visibility created)))
 
-(defun srht-paste--sha (domain)
+(defun srht-paste--sha (instance)
   "Read a FILENAME in the minibuffer, with completion and return SHA.
-DOMAIN is the domain name of the Sourcehut instance."
-  (let ((cand (srht-paste--candidates domain)))
+INSTANCE is the instance name of the Sourcehut instance."
+  (let ((cand (srht-paste--candidates instance)))
     (car (last (assoc
                 (srht-read-with-annotaion
                     "Select paste: " cand
-                    (lambda (str) (srht-paste--annot domain str))
+                    (lambda (str) (srht-paste--annot instance str))
                     'sourcehut-paste)
                 cand)))))
 
-(defun srht-paste (domain &optional sha &rest details)
-  "Create, retrieve or delete a paste from DOMAIN.
+(defun srht-paste (instance &optional sha &rest details)
+  "Create, retrieve or delete a paste from INSTANCE.
 
 When retrieving or deleting a paste SHA must the the hash
 corresponding to the paste.
@@ -98,9 +98,9 @@ When creating a new paste, SHA must be nil and one has to
 specify the DETAILS (see `srht-paste-make') of the paste."
   (cond
    ((stringp sha)
-    (srht-paste--make-crud domain (format "/api/pastes/%s" sha)))
+    (srht-paste--make-crud instance (format "/api/pastes/%s" sha)))
    ((stringp (plist-get details :contents))
-    (srht-paste--make-crud domain "/api/pastes" nil (apply #'srht-paste-make 
details)))))
+    (srht-paste--make-crud instance "/api/pastes" nil (apply #'srht-paste-make 
details)))))
 
 (defun srht-paste--get-content ()
   "Extract the content we want to paste.
@@ -111,17 +111,17 @@ the whole buffer."
     (buffer-string)))
 
 ;;;###autoload
-(defun srht-paste-region (domain visibility filename)
-  "Paste region or buffer to Sourcehut instance with DOMAIN.
+(defun srht-paste-region (instance visibility filename)
+  "Paste region or buffer to Sourcehut instance with INSTANCE.
 Set FILENAME and VISIBILITY."
   (interactive
-   (list (srht-read-domain "Instance: ")
+   (list (srht-read-instance "Instance: ")
          (srht-read-visibility "Visibility: ")
         (read-string (format "Filename (default: %s): " (buffer-name))
                      nil nil (buffer-name))))
   (let ((content (srht-paste--get-content)))
     (srht-create
-     (srht-paste domain nil
+     (srht-paste instance nil
                  :visibility visibility
                  :filename filename
                  :contents content)
@@ -131,40 +131,40 @@ Set FILENAME and VISIBILITY."
                           (:user (map (:canonical_name username))))
                      results)
                     (url (srht--make-uri
-                          domain 'paste (format "/%s/%s" username sha) nil)))
+                          instance 'paste (format "/%s/%s" username sha) nil)))
          (srht-copy-url url)
          (srht-browse-url url)
-         (srht-retrive (srht-pastes domain)
+         (srht-retrive (srht-pastes instance)
                        :then (lambda (resp)
-                               (srht-put srht-paste-all-pastes domain 
resp))))))))
+                               (srht-put srht-paste-all-pastes instance 
resp))))))))
 
 ;;;###autoload
-(defun srht-paste-delete (domain sha)
-  "Detete paste with SHA from the DOMAIN instance."
+(defun srht-paste-delete (instance sha)
+  "Detete paste with SHA from the INSTANCE instance."
   (interactive
-   (let ((instance (srht-read-domain "Instance: ")))
+   (let ((instance (srht-read-instance "Instance: ")))
      (list instance (srht-paste--sha instance))))
   (srht-delete
-   (srht-paste domain sha)
+   (srht-paste instance sha)
    :as 'string
    :then (lambda (_r)
            (srht-retrive
-            (srht-pastes domain)
+            (srht-pastes instance)
             :then (lambda (resp)
-                    (srht-put srht-paste-all-pastes domain resp)
+                    (srht-put srht-paste-all-pastes instance resp)
                     (message "Deleted!"))))))
 
 ;;;###autoload
-(defun srht-paste-copy-url (domain)
+(defun srht-paste-copy-url (instance)
   "Copy selected paste URL to clipboard.
-DOMAIN (see `srht-read-domain')."
-  (interactive (list (srht-read-domain "Instance: ")))
+INSTANCE (see `srht-read-instance')."
+  (interactive (list (srht-read-instance "Instance: ")))
   (when (string-empty-p srht-username)
     (error "`srht-username' must be set"))
-  (let* ((sha (srht-paste--sha domain))
+  (let* ((sha (srht-paste--sha instance))
          (username (concat "~" (string-trim-left srht-username "~")))
          (url (srht--make-uri
-               domain 'paste (format "/%s/%s" username sha) nil)))
+               instance 'paste (format "/%s/%s" username sha) nil)))
     (srht-copy-url url)
     (srht-browse-url url)))
 
diff --git a/lisp/srht.el b/lisp/srht.el
index 544accd34a..59ecba333b 100644
--- a/lisp/srht.el
+++ b/lisp/srht.el
@@ -33,6 +33,7 @@
 (require 'cl-lib)
 (require 'plz)
 (require 'rx)
+(require 'srht-gql)
 (require 'auth-source)
 
 (defgroup srht nil
@@ -40,9 +41,9 @@
   :prefix "srht"
   :group 'comm)
 
-(defcustom srht-domains '("sr.ht")
+(defcustom srht-instances '("sr.ht")
   "Sourcehut instance domain names."
-  :type '(list (repeat :tag "Domain"
+  :type '(list (repeat :tag "Instance"
                       :inline t
                       (string :format "%v")))
   :group 'srht)
@@ -63,14 +64,14 @@ It is necessary to use Oauth personal token not Oauth2."
   :type 'boolean
   :group 'srht)
 
-(defun srht-token ()
+(defun srht-token (host)
   "Lookup variable `srht-token' if needed and return it.
 If variable `srht-token' is nil or cannot be looked up or is empty, signal
 an error."
   (if srht-token
       srht-token
     (let ((token (when-let ((f (plist-get
-                                (car (auth-source-search :host "sr.ht"))
+                                (car (auth-source-search :host host))
                                 :secret)))
                    (funcall f))))
       (unless token
@@ -97,13 +98,13 @@ PATH should be strings or nil.  QUERY should be strings or 
nil."
      (_ (error "Expected absolute path starting with \"/\" or empty string: 
%s" path)))
    (if query (concat "?" query) "")))
 
-(defun srht--make-uri (domain service path query)
-  "Construct a URI for making a request to Sourcehut DOMAIN.
+(defun srht--make-uri (instance service path query)
+  "Construct a URI for making a request to Sourcehut INSTANCE.
 SERVICE is name of the service, PATH is the path for the URI, and
 QUERY is the query for the URI."
-  (cl-assert (and (not (string-empty-p domain)) domain)
-             nil "Require domain")
-  (let ((host (format "%s.%s" service domain)))
+  (cl-assert (and (not (string-empty-p instance)) instance)
+             nil "Require instance")
+  (let ((host (format "%s.%s" service instance)))
     (srht--build-uri-string
      'https :host host :path path :query query)))
 
@@ -127,7 +128,7 @@ narrowed to the response body."
     (json-read)))
 
 ;; TODO add body-type to use with `multipart/from-data'
-(cl-defun srht--api-request (method &key domain service path query
+(cl-defun srht--api-request (method &key instance service path query
                                     body (else #'srht--else)
                                     form (then 'sync) (as #'srht--as)
                                     &allow-other-keys)
@@ -135,7 +136,7 @@ narrowed to the response body."
 Return the curl process object or, for a synchronous request, the
 selected result.
 
-DOMAIN is the domain name of the Sourcehut instance.
+INSTANCE is the instance name of the Sourcehut instance.
 
 HEADERS may be an alist of extra headers to send with the
 request.
@@ -151,24 +152,24 @@ THEN (see `plz').
 THEN is a callback function, which is called in the response data.
 ELSE is an optional callback function called when the request
 fails with one argument, a `plz-error' struct."
-  (let ((uri (srht--make-uri domain service path query))
+  (let ((uri (srht--make-uri instance service path query))
         (content-type (or form "application/json")))
     (plz method uri
       :headers `(,(cons "Content-Type" content-type)
-                 ,(cons "Authorization" (concat "token " (srht-token))))
+                 ,(cons "Authorization" (concat "token " (srht-token 
"sr.ht"))))
       :body body
       :then then
       :else else
       :as as)))
 
-(defun srht-generic-crud (domain service path &optional query body form)
+(defun srht-generic-crud (instance service path &optional query body form)
   "Return a list of arguments to pass to `srht--make-crud-request'.
-DOMAIN is the domain name of the Sourcehut instance.
+INSTANCE is the instance name of the Sourcehut instance.
 SERVICE is the service to used, and PATH is the path for the URI.
 BODY is optional, if it is an empty list, the resulting list will not
 contain the body at all.  FORM is optional.  QUERY is the query for the
 URI."
-  (let ((crud `(:domain ,domain :service ,service
+  (let ((crud `(:instance ,instance :service ,service
                 :path ,path :query , query :form ,form)))
     (if body
         (append crud `(:body ,(if form body (json-encode body))))
@@ -234,29 +235,29 @@ Bind it with the ‘pcase’ PATTERN and do BODY."
                 (,pattern (json-read-from-string ,string)))
      ,@body))
 
-(defun srht-read-domain (prompt)
-  "Read domain name of the Sourcehut instance from `srht-domains' collection.
+(defun srht-read-instance (prompt)
+  "Read instance name of the Sourcehut instance from `srht-instances' 
collection.
 If the collection contains only one name, return it without completion.
 PROMPT is a string to prompt with; normally it ends in a colon and a space."
-  (if (eq (length srht-domains) 1)
-      (car srht-domains)
-    (completing-read prompt srht-domains nil t)))
+  (if (eq (length srht-instances) 1)
+      (car srht-instances)
+    (completing-read prompt srht-instances nil t)))
 
 (defun srht-read-visibility (prompt &optional initial-input)
   "Select a visibility through `completing-read'.
 PROMPT, INITIAL-INPUT see `completing-read' doc."
   (completing-read prompt '("private" "public" "unlisted") nil t 
initial-input))
 
-(defun srht-results-get (domain plist)
+(defun srht-results-get (instance plist)
   "Extract the value for the :results property.
-For the existing PLIST for the DOMAIN domain name."
+For the existing PLIST for the INSTANCE instance name."
   (declare (indent 1))
-  (plist-get (plist-get plist (intern domain)) :results))
+  (plist-get (plist-get plist (intern instance)) :results))
 
-(defmacro srht-put (plist domain val)
-  "Change value in PLIST of DOMAIN to VAL if is not nil."
+(defmacro srht-put (plist instance val)
+  "Change value in PLIST of INSTANCE to VAL if is not nil."
   (declare (indent 1))
-  `(when ,val (setq ,plist (plist-put ,plist (intern ,domain) ,val))))
+  `(when ,val (setq ,plist (plist-put ,plist (intern ,instance) ,val))))
 
 (defun srht-annotation (str visibility created)
   "Return an annotation for STR using VISIBILITY and CREATED."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]