Created
May 20, 2012 22:08
-
-
Save mattdeboard/2759715 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (defun jira-rest-api-interact (method data &optional path) | |
| "Interact with the API using method 'method' and data 'data'. | |
| Optional arg 'path' may be provided to specify another location further | |
| down the URL structure to send the request." | |
| (if (not jira-rest-auth-info) | |
| (message "You must login first, 'M-x jira-rest-login'.") | |
| (let ((url-request-method method) | |
| (url-request-extra-headers | |
| `(("Content-Type" . "application/json") | |
| ("Authorization" . ,jira-rest-auth-info))) | |
| (url-request-data data) | |
| (target (concat jira-rest-endpoint path))) | |
| (with-current-buffer (current-buffer) | |
| (url-retrieve target 'my-switch-to-url-buffer `(,method)))))) | |
| (defun my-switch-to-url-buffer (status method) | |
| "Callback function to capture the contents of the response." | |
| (with-current-buffer (current-buffer) | |
| ;; Don't try to read the buffer if the method was DELETE, | |
| ;; since we won't get a response back. | |
| (if (not (equal method "DELETE")) | |
| (let ((data (buffer-substring (search-forward-regexp "^$") | |
| (point-max)))) | |
| (setq response (json-read-from-string data)))) | |
| (kill-buffer (current-buffer)))) | |
| (defun jira-rest-get-issue (k &optional fields) | |
| "Fetch the data for a single issue identified by 'k'. Optional | |
| comma-separated fields 'fields' can be passed to limit what fields are returned | |
| in the results." | |
| (interactive (list (read-string "Issue Key or ID: ") | |
| (read-string "Comma-separated Fields to Include: "))) | |
| (jira-rest-api-interact "GET" nil (if fields | |
| (concat k "?fields" fields) | |
| k))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment