summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rt-liberation-rest.el38
-rw-r--r--rt-liberation.el45
2 files changed, 70 insertions, 13 deletions
diff --git a/rt-liberation-rest.el b/rt-liberation-rest.el
index 85cabf4..af8c1a5 100644
--- a/rt-liberation-rest.el
+++ b/rt-liberation-rest.el
@@ -104,6 +104,18 @@
"user=" user "&"
"pass=" pass)))
+(defun rt-liber-rest-command-edit-string (scheme url ticket-id username password)
+ "Return the ticket edit string."
+ (let ((user (url-encode-url username))
+ (pass (url-encode-url password)))
+ (concat scheme
+ "://"
+ url
+ "/REST/1.0/ticket/" ticket-id
+ "/edit" "?"
+ "user=" user "&"
+ "pass=" pass)))
+
(defun rt-liber-rest-call (url)
"Perform a REST call with URL."
(let ((url-request-method "POST"))
@@ -224,6 +236,32 @@
(rt-liber-rest-parse-http-header)
(buffer-substring (point) (point-max)))))
+(defun rt-liber-rest-handle-response (buffer)
+ "Handle the response provided in BUFFER."
+ (with-current-buffer response-buffer
+ (rt-liber-rest-write-debug (buffer-string))))
+
+(defun rt-liber-rest-edit-runner (ticket-id field value)
+ "Run edit comment to set FIELD to VALUE."
+ (message "started edit command at %s..." (current-time-string))
+ (let ((request-data
+ (format "content=%s: %s"
+ (url-hexify-string field)
+ (url-hexify-string value))))
+ (let ((url-request-method "POST")
+ (url-request-data request-data)
+ response-buffer)
+ (setq response-buffer
+ (url-retrieve-synchronously
+ (rt-liber-rest-command-edit-string
+ rt-liber-rest-scheme
+ rt-liber-rest-url
+ ticket-id
+ rt-liber-rest-username
+ rt-liber-rest-password)))
+ (rt-liber-rest-handle-response response-buffer)))
+ (message "command ended at %s" (current-time-string)))
+
(provide 'rt-liberation-rest)
diff --git a/rt-liberation.el b/rt-liberation.el
index 1997adc..a266123 100644
--- a/rt-liberation.el
+++ b/rt-liberation.el
@@ -30,6 +30,7 @@
;;
;; Started near the end of 2008.
+
;;; Code:
(require 'browse-url)
@@ -179,6 +180,13 @@ of referring to certain commands. The command strings are the
specific strings which would produce the desired effect in the
server.")
+(defvar rt-liber-field-dictionary
+ '((owner . "Owner"))
+ "Mapping between field symbols and RT field strings.
+
+The field symbols provide the programmer with a consistent way of
+referring to RT fields.")
+
(defvar rt-liber-status-dictionary
'((deleted . "deleted")
(resolved . "resolved")
@@ -215,6 +223,7 @@ This variable is made buffer local for the ticket history")
This variable is made buffer local for the ticket history")
+
;;; --------------------------------------------------------
;;; Debug log
;;; --------------------------------------------------------
@@ -538,6 +547,17 @@ AFTER date after predicate."
nil))
nil))
+(defun rt-liber-get-field-string (field-symbol)
+ (when (not field-symbol)
+ (error "null field symbol"))
+
+ (defun rt-liber-ticket-owner-only (ticket-alist)
+ "Return the string value of the ticket owner."
+ (when (not ticket-alist)
+ (error "null ticket-alist"))
+ (cdr (assoc (rt-liber-get-field-string 'owner))
+ ticket-alist)))
+
(defun rt-liber-viewer-visit-in-browser ()
"Visit this ticket in the RT Web interface."
(interactive)
@@ -748,7 +768,7 @@ ASSOC-BROWSER if non-nil should be a ticket browser."
(resolved (cdr (assoc "Resolved" ticket-alist)))
(requestors (cdr (assoc "Requestors" ticket-alist)))
(creator (cdr (assoc "Creator" ticket-alist)))
- (owner (cdr (assoc "Owner" ticket-alist)))
+ (owner (rt-liber-ticket-owner-only ticket-alist))
(queue (cdr (assoc "Queue" ticket-alist)))
(anc (if rt-liber-anc-p
(rt-liber-get-ancillary-text
@@ -884,7 +904,7 @@ If POINT is nil then called on (point)."
"Return t if TICKET-ALIST is owned by Nobody."
(when (not ticket-alist)
(error "null argument"))
- (let ((owner (cdr (assoc "Owner" ticket-alist))))
+ (let ((owner (rt-liber-ticket-owner-only ticket-alist)))
(if (string= owner "Nobody")
nil
t)))
@@ -969,7 +989,8 @@ If POINT is nil then called on (point)."
(rt-liber-sort-ticket-list
ticket-list
#'(lambda (a b)
- (rt-liber-lex-lessthan-p a b "Owner"))))
+ (rt-liber-lex-lessthan-p
+ a b (rt-liber-get-field-string 'owner)))))
(defun rt-liber-sort-by-time-created (ticket-list)
"Sort TICKET-LIST in reverse chronological order."
@@ -979,6 +1000,7 @@ If POINT is nil then called on (point)."
#'(lambda (a b)
(rt-liber-time-lessthan-p a b "Created")))))
+
;;; --------------------------------------------------------
;;; Ticket browser filtering
;;; --------------------------------------------------------
@@ -992,6 +1014,7 @@ This function is really a placeholder for user custom functions,
and as such always return t."
t)
+
;;; --------------------------------------------------------
;;; Version comparison functions
;;; --------------------------------------------------------
@@ -1204,13 +1227,11 @@ string then that will be the name of the new buffer."
(rt-liber-set-ancillary-text
(read-from-minibuffer "Text: " initial-contents))))
+
;;; --------------------------------------------------------
;;; Command module
;;; --------------------------------------------------------
-;; when this module is stable enough it should be documented in the
-;; manual -- yrk
-
(defun rt-liber-command-get-dictionary-value (sym dic)
"Utility function for retrieving alist values."
(let ((value (cdr (assoc sym dic))))
@@ -1323,13 +1344,11 @@ If FIELD already exists, update to VALUE."
(defun rt-liber-command-set-owner (id owner)
"Set the owner of ticket ID to OWNER."
- (let ((command (rt-liber-command-get-command-string 'edit))
- (args
- (format "ticket/%s set owner=%s" id owner)))
- (rt-liber-handle-response-set-owner
- (rt-liber-parse-answer
- (rt-liber-command-runner command args)
- 'rt-liber-command-runner-parser-f))))
+ (rt-liber-handle-response-set-owner
+ (rt-liber-parse-answer
+ (rt-liber-rest-edit-runner
+ id (rt-liber-get-field-string 'owner) owner)
+ 'rt-liber-command-runner-parser-f)))
(defun rt-liber-command-set-queue (id queue)
"Set the queue of ticket ID to QUEUE."