git.fiddlerwoaroof.com
api-handler.lisp
19bc25d1
 (in-package #:jira-api)
0db897a4
 
9fbca987
 (defparameter *hostname* "https://atomampd.atlassian.net")
 (defparameter *endpoint* (princ-to-string (puri:merge-uris *hostname* "/rest/api/2/")))
9cc3714b
 (defparameter *agile-endpoint* (princ-to-string (puri:merge-uris *hostname* "/rest/agile/1.0/")))
9fbca987
 
19bc25d1
 (defun update-hostname (base)
   (setf *hostname* (format nil "https://~a" base))
9cc3714b
   (setf *endpoint* (princ-to-string (puri:merge-uris "/rest/api/2/" *hostname*)))
   (setf *agile-endpoint* (princ-to-string (puri:merge-uris *hostname* "/rest/agile/1.0/"))))
 
 (define-condition jira-error ()
   ())
 
 (define-condition auth-call-unauthorized (jira-error)
   ())
 
 (define-condition server-error ()
   ())
0db897a4
 
 (defun api-get-call (auth method &rest parameters)
   "Connect to a GET REST endpoint specified by method and return a stream from
    which the response can be read."
   (let ((drakma:*text-content-types* (acons "application" "json" drakma:*text-content-types*)))
9cc3714b
     (format t "~&~a ~s~%" (puri:merge-uris method *endpoint*) (alexandria:plist-alist parameters))
     (multiple-value-bind (stream retcode)
         (drakma:http-request (puri:merge-uris method *endpoint*)
                              :parameters (alexandria:plist-alist parameters)
                              :basic-authorization auth
                              :want-stream t)
       (case retcode
         (401 (error 'auth-call-unauthorized))
         (500 (error 'server-error))
         (t stream)))))
 
 (defun agile-get-call (auth method &rest parameters)
   "Connect to a GET REST endpoint specified by method and return a stream from
    which the response can be read."
   (let ((drakma:*text-content-types* (acons "application" "json" drakma:*text-content-types*)))
     (format t "~&~a ~s~%" (puri:merge-uris method *agile-endpoint*) (alexandria:plist-alist parameters))
     (multiple-value-bind (stream retcode)
         (drakma:http-request (puri:merge-uris method *agile-endpoint*)
                              :parameters (alexandria:plist-alist parameters)
                              :basic-authorization auth
                              :want-stream t)
       (case retcode
         (401 (error 'auth-call-unauthorized))
         (500 (error 'server-error))
         (t stream)))))
0db897a4
 
 (defun api-post-call (auth method post-data)
   "Connect to a GET REST endpoint specified by method and return a stream from
    which the response can be read."
   (let ((drakma:*text-content-types* (acons "application" "json" drakma:*text-content-types*)))
     (drakma:http-request (puri:merge-uris method *endpoint*)
                          :method :POST
                          :content-type "application/json"
                          :content post-data
                          :basic-authorization auth
                          :want-stream t)))