-
Notifications
You must be signed in to change notification settings - Fork 5
/
shampoo-response.el
59 lines (43 loc) · 1.75 KB
/
shampoo-response.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
;;; shampoo-response.el --- Shampoo response object
;;
;; Copyright (C) 2010 - 2012 Dmitry Matveev <[email protected]>
;;
;; This software is released under terms of the MIT license,
;; please refer to the LICENSE file for details.
(eval-when-compile (require 'cl))
(require 'shampoo-xml)
;; Currently response data is represented as a result of
;; xml-parse-region.
(defstruct shampoo-response attrs data)
(defun shampoo-response-from (str)
(let ((xml (shampoo-parse-xml str)))
(make-shampoo-response
:attrs (shampoo-xml-attrs-hash (cadr xml))
:data (cddr xml))))
(defun shampoo-response-type (resp)
(shampoo-response-attr 'type resp))
(defun shampoo-response-id (resp)
(string-to-number (shampoo-response-attr 'id resp)))
(defun shampoo-response-attr (name resp)
(gethash name (shampoo-response-attrs resp)))
(defun shampoo-response-is-success (resp)
(and (equal "OperationalResponse" (shampoo-response-type resp))
(equal "success" (shampoo-response-attr 'status resp))))
(defun shampoo-response-is-failure (resp)
(and (equal "OperationalResponse" (shampoo-response-type resp))
(equal "failure" (shampoo-response-attr 'status resp))))
(defun shampoo-response-items (resp)
(shampoo-response-data resp))
(defun shampoo-response-items-named (name resp)
(shampoo-xml-nodes-named name (shampoo-response-data resp)))
(defun shampoo-response-enclosed-string (resp)
(first (shampoo-response-data resp)))
(defun shampoo-response-aggr-item (data-item)
(when (listp data-item)
(caddr data-item)))
(defun shampoo-response-is-last-in-sequence (resp)
(if (equal "FileOut" (shampoo-response-type resp))
(equal "true" (shampoo-response-attr 'last resp))
t))
(provide 'shampoo-response)
;;; shampoo-response.el ends here.