Rename s/data-type/parser/g

This commit is contained in:
Takafumi Arakaki 2012-05-26 20:23:22 +02:00
parent 5a65aba368
commit f6bcb438e8
2 changed files with 16 additions and 10 deletions

View file

@ -80,7 +80,7 @@
(ein:query-ajax
(ein:notebooklist-url url-or-port)
:cache nil
:data-type #'ein:json-read
:parser #'ein:json-read
:success (cons success url-or-port)
:timeout 5000))
(ein:notebooklist-get-buffer url-or-port))
@ -126,8 +126,8 @@
(unless (setq url-or-port (ein:$notebooklist-url-or-port ein:notebooklist)))
(ein:query-ajax
(ein:notebooklist-new-url url-or-port)
:data-type (lambda ()
(ein:notebooklist-get-data-in-body-tag "data-notebook-id"))
:parser (lambda ()
(ein:notebooklist-get-data-in-body-tag "data-notebook-id"))
:success (cons #'ein:notebooklist-new-notebook-callback (current-buffer))
:timeout 5000))

View file

@ -47,7 +47,7 @@
(cache t)
(type "GET")
(data nil)
(data-type nil)
(parser nil)
(headers nil)
(success nil)
(error nil)
@ -58,7 +58,7 @@
:CACHE (nil/t) : append time-stamp to URL so the URL is always loaded.
:TYPE (string) : sets `url-request-method'
:DATA (string) : sets `url-request-data'
:DATA-TYPE (symbol) : a function that reads current buffer and return data
:PARSER (symbol) : a function that reads current buffer and return data
:HEADERS (alist) : sets `url-request-extra-headers'
:SUCCESS (cons) : called on success
:ERROR (cons) : called on error
@ -86,7 +86,7 @@ arguments to be passed, depending on situation.
* :SUCCESS callback
This callback takes :DATA (object), which is a data object parsed
by :DATA-TYPE. If :DATA-TYPE is not specified, this is nil.
by :PARSER. If :PARSER is not specified, this is nil.
The :SUCCESS callback also takes the :STATUS and :RESPONSE-STATUS
argument.
@ -96,6 +96,12 @@ Each value of this alist is a callback which is similar to :ERROR
or :SUCCESS callback. However, current buffer of this callback
is not guaranteed to be the process buffer.
* :PARSER function
This is analogous to the `dataType' argument of `$.ajax'.
Only this function can accuses to the process buffer, which
is killed immediately after the execution of this function.
* See also: http://api.jquery.com/jQuery.ajax/"
(ein:log 'debug "EIN:QUERY-AJAX")
(unless cache
@ -116,7 +122,7 @@ is not guaranteed to be the process buffer.
(defun* ein:query-ajax-callback (status &key
(headers nil)
(data-type nil)
(parser nil)
(success nil)
(error nil)
(timeout nil)
@ -130,13 +136,13 @@ is not guaranteed to be the process buffer.
(ein:log 'debug "(buffer-string) =\n%s" (buffer-string))
(ein:query-ajax-cancel-timer)
(let* ((buffer (current-buffer)) ; `data-type' could change buffer...
(let* ((buffer (current-buffer)) ; `parser' could change buffer...
(response-status url-http-response-status)
(status-code-callback (cdr (assq response-status status-code)))
(status-error (plist-get status :error))
(data (if (and data-type (not status-error))
(data (if (and parser (not status-error))
(unwind-protect
(funcall data-type)
(funcall parser)
(kill-buffer buffer)))))
(ein:log 'debug "Executing success/error callback.")