Browse files

first shot at oauth api

  • Loading branch information...
sigma committed Jan 15, 2012
1 parent 9e4f934 commit 0dc393bba29d6ef847c905328f6f01fab6d736a6
Showing with 107 additions and 0 deletions.
  1. +107 −0 gh-oauth.el
@@ -0,0 +1,107 @@
;;; gh-oauth.el --- oauth module for gh.el
;; Copyright (C) 2012 Yann Hodique
;; Author: Yann Hodique <>
;; Keywords:
;; 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
;; 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., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;; Code:
(require 'gh-api)
(require 'gh-auth)
(require 'gh-common)
(defclass gh-oauth-api (gh-api-v3)
((auth-cls :allocation :class :initform gh-oauth-authorization))
"OAuth API")
(defclass gh-oauth-password-authenticator (gh-password-authenticator)
((remember :allocation :class :initform nil)))
(defmethod constructor :static ((api gh-oauth-api) newname &rest args)
;; force password authentication for this API
(let ((gh-api-v3-authenticator 'gh-oauth-password-authenticator))
(defclass gh-oauth-authorization (gh-object)
((id :initarg :id)
(url :initarg :url)
(scopes :initarg :scopes)
(token :initarg :token)
(app :initarg :app :initform nil)
(updated-at :initarg :updated-at)
(created-at :initarg :created-at)
(app-cls :allocation :class :initform gh-oauth-app)))
(defmethod gh-object-read-into ((auth gh-oauth-authorization) data)
(with-slots (id url scopes token app updated-at created-at)
(setq id (gh-read data 'id)
url (gh-read data 'url)
scopes (gh-read data 'scopes)
token (gh-read data 'token)
app (gh-object-read (or (oref auth :app)
(oref auth app-cls))
(gh-read data 'app))
updated-at (gh-read data 'updated_at)
created-at (gh-read data 'created_at))))
(defclass gh-oauth-app (gh-object)
((url :initarg :url)
(name :initarg :name)))
(defmethod gh-object-read-into ((app gh-oauth-app) data)
(with-slots (url name)
(setq url (gh-read data 'url)
name (gh-read data 'name))))
(defmethod gh-oauth-auth-list ((api gh-oauth-api))
api (gh-object-list-reader (oref api auth-cls)) "GET"
(format "/authorizations")))
(defmethod gh-oauth-auth-get ((api gh-oauth-api) id)
api (gh-object-reader (oref api auth-cls)) "GET"
(format "/authorizations/%s" id)))
(defmethod gh-oauth-auth-new ((api gh-oauth-api) &optional scopes)
api (gh-object-reader (oref api auth-cls)) "POST"
(format "/authorizations") (list (cons 'scopes scopes))))
(defmethod gh-oauth-auth-update ((api gh-oauth-api) id &optional scopes)
api (gh-object-reader (oref api auth-cls)) "PATCH"
(format "/authorizations/%s" id) (list (cons 'scopes scopes))))
(defmethod gh-oauth-auth-delete ((api gh-oauth-api) id)
api nil "DELETE" (format "/authorizations/%s" id)))
(provide 'gh-oauth)
;;; gh-oauth.el ends here

0 comments on commit 0dc393b

Please sign in to comment.