Created
June 26, 2012 13:43
-
-
Save adam-stokes/2995857 to your computer and use it in GitHub Desktop.
This file contains 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
;;; lp.el --- Launchpad API | |
;; Copyright (C) 2012 Adam Stokes | |
;; Author: Adam Stokes <[email protected]> | |
;; Keywords: api | |
;; Version: 1.0.0 | |
;; This file is free software; you can redistribute it and/or modify | |
;; it | |
;; under the terms of the GNU General Public License as published by | |
;;the | |
;; Free Software Foundation; either version 2, or (at your option) any | |
;; later version. | |
;; This file is distributed in the hope that it will be useful, but | |
;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
;; General Public License for more details. | |
;; You should have received a copy of the GNU General Public License | |
;; along with GNU Emacs; see the file COPYING. If not, write to the | |
;; Free | |
;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
;; MA 02110-1301, USA. | |
;;; Installation: | |
;; | |
;; Place lp.el into your `load-path` | |
;; Add following to ~/.emacs.d/init.el file: | |
;; (require 'lp) | |
;;; Usage: | |
;; (lp-bug 1) | |
;;; code: | |
(require 'url) | |
(require 'json) | |
(eval-when-compile | |
(require 'cl)) | |
(defun lp-make-url (bug) | |
"make url for lp" | |
(format "https://api.launchpad.net/1.0/bugs/%s" bug)) | |
(defun lp-get (bug) | |
"get url data from launchpad" | |
(let ((result | |
(url-retrieve-synchronously (lp-make-url bug)))) | |
(with-current-buffer result | |
(setf (point) (point-min)) | |
(when (search-forward-regexp "\{" nil t) | |
(buffer-substring-no-properties | |
(line-beginning-position) | |
(line-end-position)))))) | |
(defun lp-bug (bug) | |
"insert json at point" | |
(interactive "title:") | |
(let ((result (lp-get bug))) | |
(if result | |
(let ((json-object-type 'hash-table)) | |
(json-read-from-string result)) | |
(insert (gethash "title")) | |
(error "lp-get: '%s' stupid" bug)))) | |
(provide 'lp) | |
;;; lp.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment