Created
July 26, 2011 04:33
-
-
Save leegao/1105982 to your computer and use it in GitHub Desktop.
Coffee Protocol: RPC 2324
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
;;; coffee - Submit a BREW request to an RFC2324-compliant coffee device | |
;;; | |
;;; Author: Eric Marsden <emarsden@laas.fr> | |
;;; Version: 0.2 | |
;;; Copyright: (C) 1999 Eric Marsden | |
;;; Keywords: coffee, brew, kitchen-sink, can't | |
;; | |
;; 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 2 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, write to the Free | |
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
;; MA 02111-1307, USA. | |
(require 'cl) | |
(defvar coffee-host "coffee" | |
"*The host which provides the coffee service.") | |
(defvar coffee-pot-designator 1 | |
"*On machines with multiple pots, the number of the pot to brew in") | |
(defconst coffee-milk-types | |
'("Cream" "Half-and-Half" "Whole-Milk" "Part-Skim" "Skim" "Non-Dairy")) | |
(defconst coffee-syrup-types '("Vanilla" "Almond" "Raspberry" "Chocolate")) | |
(defconst coffee-sweetener-types '("White-Sugar" "Brown-Sugar" "Artificial-Sweetener")) | |
(defconst coffee-alcohol-types '("Whiskey" "Rum" "Kahula" "Aquavit")) | |
(defconst coffee-addition-types | |
`(("Milk" . ,coffee-milk-types) | |
("Syrup" . ,coffee-syrup-types) | |
("Sweetener" . ,coffee-sweetener-types) | |
("Alcohol" . ,coffee-alcohol-types))) | |
;;;###autoload | |
(defun coffee () | |
"Submit a BREW request to an RFC2324-compliant coffee device" | |
(interactive) | |
(require 'url) | |
(let* ((additions-list | |
(append coffee-milk-types | |
coffee-syrup-types | |
coffee-sweetener-types | |
coffee-alcohol-types)) | |
(additions-string | |
(mapconcat #'identity additions-list ",")) | |
(url (coffee-url)) | |
(url-request-method "BREW") | |
(url-request-extra-headers | |
`(("Content-type" . "message-coffeepot") | |
("Accept-Additions" . ,additions-string))) | |
(url-request-data "START")) | |
(run-hooks 'coffee-brew-hook) | |
(url-retrieve url))) | |
(defun coffee-additions () | |
(let* ((type-name | |
(completing-read "Coffee addition: " coffee-addition-types nil t)) | |
(type (cdr (assoc type-name coffee-addition-types))) | |
(ingredients (mapcar #'(lambda (a) (cons a a)) type)) | |
(ingredient | |
(completing-read "Addition type: " ingredients nil t))) | |
ingredient)) | |
(defun coffee-url () | |
(require 'w3-forms) | |
(concat "coffee://" coffee-host "/" | |
(int-to-string coffee-pot-designator) | |
"?" (w3-form-encode-xwfu (coffee-additions)))) | |
(provide 'coffee) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
According to RFC 2324:
pot-designator = "pot-" integer ; for machines with multiple pots
So
(concat "coffee://" coffee-host "/"
(line 78) should be(concat "coffee://" coffee-host "/pot-"
.