From 7ff2a53598afeee74903a56ed6a15ed04e4df715 Mon Sep 17 00:00:00 2001 From: John Miller Date: Fri, 7 Apr 2017 08:25:37 -0500 Subject: [PATCH] Add ein-jupyterhub.el Per popular request, publishing what I have so far for jupyterhub support, which is not much. But it may server as a starting point for someone smarter than I. --- lisp/ein-jupyterhub.el | 85 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 lisp/ein-jupyterhub.el diff --git a/lisp/ein-jupyterhub.el b/lisp/ein-jupyterhub.el new file mode 100644 index 0000000..8c26c77 --- /dev/null +++ b/lisp/ein-jupyterhub.el @@ -0,0 +1,85 @@ +;;; ein-jupyterhub.el --- Interface to Jupyterhub + +;; Copyright (C) 2016 - John Miller + +;; Authors: Takafumi Arakaki +;; John M. Miller + +;; This file is NOT part of GNU Emacs. + +;; ein-jupyterhub.el 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. + +;; ein-jupyterhub.el 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 ein-jupyter.el. If not, see . + +;;; Commentary: +;;; +;;; An interface to the Jupyterhub login and management API as described in +;;; http://jupyterhub.readthedocs.io/en/latest/api/index.html +;;; + +;; + +;;; Code: + + +(defun ein:hub-url (url-or-port &optional path) + (if path + (ein:url url-or-port "hub/api" path) + (ein:url url-or-port "hub/api"))) + +(defun ein:jupyterhub-version (url-or-port &optional callback cbargs) + (let ((url (ein:hub-url url-or-port))) + (ein:query-singleton-ajax + (list 'jupyterhub-version url-or-port) + url + :type "GET" + :timeout ein:content-query-timeout + :parser #'ein:json-read + :success (apply-partially #'ein:jupyterhub-version-success callback cbargs)))) + +(defun* ein:jupyterhub-version-success (callback cbargs &key data &allow-other-keys) + (let ((version (plist-get data :version))) + (when callback + (apply called-interactively-p-functions data cbargs)))) + + +(defun ein:jupyterhub-login (url-or-port username password &optional callback) + (let ((url (ein:url url-or-port "hub/login"))) + (ein:query-singleton-ajax + (list 'jupyterhub-login url-or-port) + url + :type "POST" + :data (concat "username=" (url-hexify-string username) + "&password=" (url-hexify-string password)) + :timeout ein:content-query-timeout + :success #'ein:jupyterhub-login-success + :status-code '((302 . #'ein:jupyterhub-login-redirect))))) + +(defun* ein:jupyterhub-login-redirect (&key data response &allow-other-keys) + (message "Login redirect!")) + +(defun* ein:jupyterhub-login-success (&key data response &allow-other-keys) + response + ) + +(defun ein:jupyterhub-services (url-or-port) + (let ((url (ein:hub-url url-or-port "services"))) + (ein:query-singleton-ajax + (list 'jupyterhub-version url-or-port) + url + :type "GET" + :timeout ein:content-query-timeout + :parser #'ein:json-read + ))) + + +(provide 'ein-jupyterhub)