unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to use http-get properly in code
@ 2006-02-05 18:41 Mathias Dahl
  2006-02-06 22:59 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 3+ messages in thread
From: Mathias Dahl @ 2006-02-05 18:41 UTC (permalink / raw)



I am currently trying to do an Emacs interface to Flickr and decided
to use http-get.el (http://emacswiki.org/cgi-bin/wiki/HttpGet) to
communicate with the servers (to make API-calls).

I have created my "sentinel" to fetch the data I get back from the
request. Here are parts of the code:

;; Somewhere to keep the result
(defvar ef-response-xml nil)

;; The sentinel
(defun ef-http-get-sentinel (proc message)
  (save-excursion
    (set-buffer (process-buffer proc))
    (setq ef-response-xml
          (xml-parse-region (point-min) (point-max)))))

;; Make a request
(defun ef-get-rest-response (arguments)
  (http-get 
   (ef-get-rest-url
    arguments)
   nil 'ef-http-get-sentinel nil "*ef*"))

;; Flickr-specific code to get a "frob" from the response xml
(defun ef-get-frob-from-xml (response-xml)
  (car (xml-node-children 
        (car (xml-get-children 
              (car response-xml)
              'frob)))))

;; Get the frob
(defun ef-get-frob ()
  (ef-get-rest-response
    (list (cons "method"  "flickr.auth.getFrob")
          (cons "api_key" ef-api-key)))
  (ef-get-frob-from-xml ef-response-xml))

The code above kind of works. The problem is the last line in the last
function above: it runs before the sentinel has been able to fetch the
results, because the request is done asynchronously. How do I get
around this? I have been thinking about adding a loop that waits for
some flag that the sentinel sets when it has fetched the data, and
then when the flag is found to be true, continue with the code, but
that feels ugly.

Is there a Correct Way (TM) to do this?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-02-06 23:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-05 18:41 How to use http-get properly in code Mathias Dahl
2006-02-06 22:59 ` Thien-Thi Nguyen
2006-02-06 23:23   ` Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).