summaryrefslogtreecommitdiff
path: root/rt-liberation-rest.el
diff options
context:
space:
mode:
authorYoni Rabkin <yrk@gnu.org>2015-03-24 15:02:31 -0400
committerYoni Rabkin <yrk@gnu.org>2015-03-24 15:02:31 -0400
commit92e78fada9b803195f7380cd38bbb84a355a203f (patch)
treef2f5461369fe47775949d84aaf7a9a325139443a /rt-liberation-rest.el
parent0e6c7ca0c5f3baa7c4e3ffb7019ee4e9a7203200 (diff)
Integrate rt-liber-rest-edit-runner and add fields.
Diffstat (limited to 'rt-liberation-rest.el')
-rw-r--r--rt-liberation-rest.el38
1 files changed, 38 insertions, 0 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)