diff options
-rw-r--r-- | README.org | 15 | ||||
-rw-r--r-- | stack-auth.el | 70 | ||||
-rw-r--r-- | stack-core.el | 24 |
3 files changed, 98 insertions, 11 deletions
@@ -1,4 +1,4 @@ -#+Title: Stack-Mode for Emacs +#+Title: Stack-Mode #+Author: Sean Allred #+Date: [2014-10-30 Thu] @@ -6,9 +6,9 @@ [[https://gitter.im/vermiculus/stack-mode?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge][https://badges.gitter.im/Join Chat.svg]] [[https://www.waffle.io/vermiculus/stack-mode][https://badge.waffle.io/vermiculus/stack-mode.svg]] -=stack-mode= hopes to be a full featured Stack Exchange mode for -[[http://www.gnu.org/software/emacs/][GNU Emacs]] 24+ using version 2.2 (and subsequent versions as available) of -the [[https://api.stackexchange.com/][Stack Exchange API]]. +=Stack-mode= hopes to be a full featured Stack Exchange mode for +GNU Emacs 24 and up. Using version 2.2, and subsequent versions as available, of +the Stack Exchange API we aim to create a more versatile experience of Stack Exchange inside of Emacs. This README will eventually hold a high-level feature list and details on installation and configuration. @@ -16,7 +16,7 @@ on installation and configuration. Please help contribute! Doing any of the following will help us immensely: - [[https://github.com/vermiculus/stack-mode/issues/new][Open an issue]] - [[https://github.com/vermiculus/stack-mode/pulls][Submit a pull request]] - - Suggest a package or library in our [[https://gitter.im/vermiculus/stack-mode][Chat on Gitter]] + - [[https://gitter.im/vermiculus/stack-mode][Suggest a package or library in our Chat on Gitter]] - Spread the word! For a better view of all of the open issues, take a look at our lovely @@ -24,10 +24,11 @@ For a better view of all of the open issues, take a look at our lovely =ready=. If you have thoughts on any other issues, don't hesitate to chime in! * Resources -- [[https://api.stackexchange.com/docs][SX.API v2.2]] +- [[http://www.gnu.org/software/emacs/][GNU Emacs]] +- [[https://api.stackexchange.com/docs][Stack Exchange API v2.2]] - [[http://stackapps.com/apps/oauth/register][StackApps Registration Page]] - [[http://www.emacswiki.org/emacs/ModeTutorial][Creating Major Modes for Emacs]] -** Icon +** Icons Stack Exchange Mode for Emacs has no explicit use for an icon, although standard SVG files have been gathered in =resources/= if anyone would fancy a crack at it. diff --git a/stack-auth.el b/stack-auth.el new file mode 100644 index 0000000..e55fae1 --- /dev/null +++ b/stack-auth.el @@ -0,0 +1,70 @@ +;;; stack-auth.el --- user authentication for stack-mode -*- lexical-binding: t; -*- + +;; Copyright (C) 2014 Sean Allred + +;; Author: Sean Allred <code@seanallred.com> +;; Keywords: help, hypermedia, mail, news, tools + +;; This program 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 3 of the License, or +;; (at your option) any later version. + +;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; + +;;; Code: + +(require 'stack-core) + +(defconst stack-auth-root + "https://stackexchange.com/oauth/dialog") +(defconst stack-auth--redirect-uri + "http://vermiculus.github.io/stack-mode/auth/auth.htm") +(defconst stack-auth--client-id + "3291") +(defvar stack-auth-access-token + nil + "Your access token. + +This is needed to use your account to write questions, make +comments, and read your inbox. Do not alter this unless you know +what you are doing!") + +(defun stack-authenticate () + "Authenticate this application. + +Authentication is required to read your personal data (such as +notifications) and to write with the API (asking and answering +questions)." + (interactive) + (setq + stack-auth-access-token + (when (browse-url + (let ((stack-core-api-root stack-auth-root) + (stack-core-api-batch-request-separator ",")) + (stack-core-build-request + nil + `((client_id . ,stack-auth--client-id) + (scope . (read_inbox + no_expiry + write_access)) + (redirect_uri . ,(url-hexify-string + stack-auth--redirect-uri)))))) + (read-string "Enter the access token displayed on the webpage: "))) + (if (string-equal "" stack-auth-access-token) + (progn (setq stack-auth-access-token nil) + (error "You must enter this code to use this client fully")) + (stack-cache-set "auth.el" `((access-token . ,stack-auth-access-token))))) + +(provide 'stack-auth) +;;; stack-auth.el ends here diff --git a/stack-core.el b/stack-core.el index c78c316..496533e 100644 --- a/stack-core.el +++ b/stack-core.el @@ -57,6 +57,16 @@ (format "http://api.stackexchange.com/%s/" stack-core-api-version) "The base URL to make requests from.") +(defvar stack-core-api-batch-request-separator + ";" + "The separator character to use when making batch requests. + +Do not change this unless you know what you are doing!") + +(defconst stack-core-api-key + "0TE6s1tveCpP9K5r5JNDNQ((" + "When passed, this key provides a higher request quota.") + (defcustom stack-core-default-keyword-arguments-alist '(("filters/create") ("sites") @@ -110,7 +120,10 @@ a string, just return it." (cond ((stringp thing) thing) ((symbolp thing) (symbol-name thing)) - ((numberp thing) (number-to-string thing)))) + ((numberp thing) (number-to-string thing)) + ((sequencep thing) + (mapconcat #'stack-core-thing-as-string + thing stack-core-api-batch-request-separator)))) (defun stack-core-get-default-keyword-arguments (method) "Gets the correct keyword arguments for METHOD." @@ -164,8 +177,9 @@ entire response as a complex alist." (call (stack-core-build-request method - (cons `(filter . ,(cond (filter filter) - ((boundp 'stack-filter) stack-filter))) + (append `((filter . ,(cond (filter filter) + ((boundp 'stack-filter) stack-filter))) + (key . ,stack-core-api-key)) (if keyword-arguments keyword-arguments (stack-core-get-default-keyword-arguments method)))))) ;; TODO: url-retrieve-synchronously can return nil if the call is @@ -267,7 +281,9 @@ context of `stack-cache-directory'." "Set the content of CACHE to DATA. As with `stack-cache-get', CACHE is a file name within the -context of `stack-cache-directory'." +context of `stack-cache-directory'. + +DATA will be written as returned by `prin1'." (unless (file-exists-p stack-cache-directory) (mkdir stack-cache-directory)) (write-region (prin1-to-string data) nil |