-
Notifications
You must be signed in to change notification settings - Fork 74
/
gh-oauth.el
89 lines (67 loc) · 2.9 KB
/
gh-oauth.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;;; gh-oauth.el --- oauth module for gh.el -*- lexical-binding: t; -*-
;; Copyright (C) 2012 Yann Hodique
;; Author: Yann Hodique <[email protected]>
;; 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
;; 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., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;
;;; Code:
(require 'eieio)
(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)))
(cl-defmethod initialize-instance ((api gh-oauth-api) &rest args)
;; force password authentication for this API
(let ((gh-api-v3-authenticator 'gh-oauth-password-authenticator))
(cl-call-next-method)))
(gh-defclass gh-oauth-authorization (gh-ref-object)
((scopes :initarg :scopes)
(token :initarg :token)
(app :initarg :app :initform nil :marshal-type gh-oauth-app)
(updated-at :initarg :updated-at)
(created-at :initarg :created-at)))
(gh-defclass gh-oauth-app (gh-object)
((url :initarg :url)
(name :initarg :name)))
(cl-defmethod gh-oauth-auth-list ((api gh-oauth-api))
(gh-api-authenticated-request
api (gh-object-list-reader (oref api auth-cls)) "GET"
(format "/authorizations")))
(cl-defmethod gh-oauth-auth-get ((api gh-oauth-api) id)
(gh-api-authenticated-request
api (gh-object-reader (oref api auth-cls)) "GET"
(format "/authorizations/%s" id)))
(cl-defmethod gh-oauth-auth-new ((api gh-oauth-api) &optional scopes)
(gh-api-authenticated-request
api (gh-object-reader (oref api auth-cls)) "POST"
(format "/authorizations") (list (cons 'scopes scopes)
(cons 'note (format "gh.el - %s"
(system-name))))))
(cl-defmethod gh-oauth-auth-update ((api gh-oauth-api) id &optional scopes)
(gh-api-authenticated-request
api (gh-object-reader (oref api auth-cls)) "PATCH"
(format "/authorizations/%s" id) (list (cons 'scopes scopes))))
(cl-defmethod gh-oauth-auth-delete ((api gh-oauth-api) id)
(gh-api-authenticated-request
api nil "DELETE" (format "/authorizations/%s" id)))
(provide 'gh-oauth)
;;; gh-oauth.el ends here
;; Local Variables:
;; indent-tabs-mode: nil
;; End: