Created
March 8, 2009 20:33
-
-
Save wfarr/75891 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (defmacro yql (query &rest args) | |
| "Constructs a function call based on `query', which should be one of | |
| `show', `desc', `select', or `filter'." | |
| (unless (member query '(show desc select filter)) | |
| (error "`query' must be one of `show', `desc', `select', or `filter'!")) | |
| (cond ((eq query 'show) | |
| (quote (yql-show))) | |
| (args | |
| (let ((query-args | |
| (mapcar (lambda (x) | |
| (coerce (symbol-name x) 'string)) | |
| args))) | |
| `(cond ((eq (quote ,query) 'desc) | |
| (yql-desc ,@query-args)) | |
| ((eq (quote ,query) 'select) | |
| (yql-select ,@query-args)) | |
| ((eq (quote ,query) 'filter) | |
| (yql-filter ,@query-args))))) | |
| (t (error "`desc', `select', and `filter' require args")))) | |
| (yql show) | |
| ;; ("atom" "csv" "feed" "flickr.photos.exif" "flickr.photos.info" "flickr.photos.interestingness" "flickr.photos.recent" "flickr.photos.search" "flickr.photos.sizes" "flickr.places" "flickr.places.info" "geo.places" ...) | |
| (yql desc flickr.places) | |
| ;; ((request (select . [... ...])) (meta (sampleQuery . "select * from flickr.places where query=\"north beach\"") (documentationURL . ["http://www.flickr.com/services/api/flickr.places.find.html" "http://www.flickr.com/services/api/flickr.places.findByLatLon.html"]) (author . "Yahoo! Inc.")) (name . "flickr.places")) | |
| (yql select item.condition.temp weather.forecast location=30332) | |
| ;; ((query (results (channel ...)) (diagnostics (build-version . "911") (service-time . "29") (user-time . "36") (url ... ...) (publiclyCallable . "true")) (uri . "http://query.yahooapis.com/v1/yql?q=SELECT+item.condition.temp+FROM+weather.forecast+WHERE+location%3D30332") (updated . "2009-03-08T09:20:35Z") (lang . "en-US") (created . "2009-03-08T09:20:35Z") (count . "1"))) | |
| (yql filter sampleQuery (yql desc flickr.places)) | |
| ;; FAILS: nil | |
| (yql foo bar) | |
| ;; ERROR: "`query' must be one of `show', `desc', `select', or `filter'!" | |
| (yql select) | |
| ;; ERROR: "`desc', `select', and `filter' require args" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment