You are looking at historical revision 16804 of this page. It may differ significantly from its current revision.
#;1> (use yelp) #;2> (by-phone "4154376800") "Invalid YWSID" invalid-ywsid #;3> ,l ../ywsid ; loading ../ywsid.scm ... #;3> (define y (by-phone "4154376800")) #;4> (valid? y) #t
#;5> (display-info y) Pizzeria Delfina 3611 18th Street San Francisco, CA 94110 (415)437-6800 Neighborhood: Mission 37.761398 -122.424003
#;6> (decode y) message: text: OK code: 0 version: 1.1.1 businesses: (1) country_code: US id: bai6umLcCNy9cXql0Js2RQ is_closed: #f city: San Francisco mobile_url: http://mobile.yelp.com/biz/bai6umLcCNy9cXql0Js2RQ review_count: 836 zip: 94110 state: CA ...
#;7> (find y "businesses.phone") "4154376800" #;8> (find y "businesses.categories.name") "Pizza" #;9> (find y "businesses.neighborhoods.name") "Mission"
<blockquote> Copyright (c) 2009 Derrell Piper.
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 3 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.
A full copy of the GPL license can be found at <http://www.gnu.org/licenses/>. </blockquote>
Requires the json egg.
In addition, the chicken-install tests require the test egg. -test also requires a valid YWSID exist in ../ywsid above the egg's temporary install directory. When fetched with chicken-install -r, simply creating a file named ywsid in the parent directory (i.e., the one in which you did the chicken-install -r) with the following content:
...and then doing a chicken-install -test in the yelp subdirectory, should work.
None of this matters if you don't care about regression tests or if you do not specify -test to chicken-install.
Authorization and Introspection[procedure] (set-ywsid! YWSID)
Sets the Yelp web service ID to the value of YWSID. This must be done before calling any other function in this egg.[procedure] (valid? OBJECT)
Is the OBJECT a valid Yelp response? There's no need to check valid? if you check for 'yelp-success.
All Yelp responses include this structure:
message: text: OK code: 0 version: 1.1.1
valid? checks for both "OK" and 0. The Yelp API was not so much designed as hacked on, it seems.
The Yelp API consists of the following functions:
Each of these functions returns two values. The first value is a RESPONSE object if successful or a string representing an error code (either from Yelp or internally generated). The second value is a symbolic return status. These values are defined in this egg:
Other values represent the translation of "message.code" in the Yelp response. 'yelp-succes implies valid?.
Yelp Phone API
See Yelp Phone API.[procedure] (by-phone NUMBER)
Look up a business by its phone number, NUMBER.
Yelp Neighborhood API[procedure] (hood-for-address LOCATION #:CC)
Returns the neighborhood name associated with a street address, LOCATION.[procedure] (hood-for-geocode LAT LON)
Returns the neighborhood name associated with a geocode location, LAT and LON.
Yelp Review Search API[procedure] (near-address TERM LOCATION #:NUMBER #:CC #:CATEGORY)
Returns a list of NUMBER reviews for businesses containing TERM and located near the address LOCATION. The CATEGORY keyword may be used to limit the search to a particular Yelp category name, e.g., "vietnamese".[procedure] (near-geocode TERM LAT LON #:NUMBER #:RADIUS #:CATEGORY)
Returns a list of NUMBER reviews for businesses containing TERM and located in a circle around the geocode location LAT and LON for a radius of RADIUS. The Yelp API fails to specify the units. The CATEGORY keyword may be used to limit the search to a particular Yelp category name, e.g., "pizza".[procedure] (near-geobox TERM TL-LAT TL-LON BR-LAT BR-LON #:NUMBER #:CATEGORY)
Returns a list of NUMBER reviews for businesses containing TERM and located in a box with the upper left geocode of TL-LAT and TL-LON and a bottom-right geocode of BR-LAT and BR-LON. The CATEGORY keyword may be used to limit the search to a particular Yelp category name, e.g., "lounges".
Display and Query[procedure] (display-info RESPONSE [PORT])
Display basic information for a Yelp RESPONSE on PORT. For example:
Pho Tan Hoa 431 Jones St San Francisco, CA 94102 (415)673-3163 Neighborhood: Civic Center/Tenderloin 37.785377 -122.412916[procedure] (decode RESPONSE [PORT])
Walks the JSON tree and decodes the response to PORT. Primarily useful during development to determine the path to the information you're interested in.[procedure] (find RESPONSE PATH)
Walks the JSON tree and searches for the JSON key specified by PATH. find uses simple dotted notation to describe the path, for example: businesses.phone or message.code.
The Yelp routines alway return an outermost JSON structure which the JSON egg maps to a vector. find may return a list or a vector (or a simple value), depending on what's being queried. Either may be passed to decode or find. For example:
#;2> (define y (by-phone "(415)437-6800")) #;3> (define r (find y "businesses.reviews")) #;4> (find r "id") "Si5MaWLUC0vmNfrPa-hLFA" #;5> (find (list-ref r 0) "id") "Si5MaWLUC0vmNfrPa-hLFA" #;6> (for-each (lambda (r) (let ((i (find r "id"))) (print i))) r) Si5MaWLUC0vmNfrPa-hLFA ChCQOJByz8Mc0cuCLgjI0A SrWF2jktPDU53-9fnQgyyA
#;17> (define m (find y "message")) #;18> (decode m) text: OK code: 0 version: 1.1.1 #;19> (find m "text") "OK"
The Yelp API defines the following elements as JSON arrays:
Note that find stops on first match, so regular iteration must be used to access second and subsequent elements, as in the first example above (i.e., reviews by "id").
The Yelp servers sometime return spurious HTML 301 redirects (on a good day) for no apparent reason. There's also quite a lot of information returned by default for the "near-" queries, so it makes sense to limit your queries using #:number or #:category when you can. All of this helps to explain the pessimal behavior of the Yelp iPhone application which, to a certain extent, motivated the creation of this egg.
- 1.0 Initial release