├── .babelrc ├── .gitignore ├── .npmignore ├── index.js ├── .travis.yml ├── .zuul.yml ├── .eslintrc ├── LICENSE ├── package.json ├── src └── index.js ├── test └── index.js └── README.md /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ "es2015" ] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | npm-debug.log 3 | .envrc 4 | lib/ 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | npm-debug.log 3 | .envrc 4 | src/ 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var Yelp = require('./lib').default; 2 | module.exports = Yelp; 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "4.1" 4 | - "4.0" 5 | - "0.12" 6 | - "0.11" 7 | - "0.10" 8 | - "iojs" 9 | -------------------------------------------------------------------------------- /.zuul.yml: -------------------------------------------------------------------------------- 1 | ui: tape 2 | browserify: 3 | - transform: 4 | name: babelify 5 | browsers: 6 | - name: chrome 7 | version: -1..latest 8 | - name: firefox 9 | version: -1..latest -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | // Use this file as a starting point for your project's .eslintrc. 2 | // Copy this file, and add rule overrides as needed. 3 | { 4 | "extends": "airbnb/base", 5 | "parser": "babel-eslint" 6 | } 7 | 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2012, Olivier Lalonde . All rights reserved. 2 | Redistribution and use in source and binary forms, with or without 3 | modification, are permitted provided that the following conditions are 4 | met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of Olivier Lalonde nor the names of its 13 | contributors may be used to endorse or promote products derived 14 | from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yelp", 3 | "description": "Library for interfacing with Yelp's API v2.0.", 4 | "version": "1.0.2", 5 | "main": "./index.js", 6 | "scripts": { 7 | "lint": "eslint ./src ./test", 8 | "build": "babel ./src --out-dir ./lib --copy-files", 9 | "clean": "rimraf ./lib", 10 | "pretest": "npm run lint", 11 | "test": "babel-node test/*.js", 12 | "test-browser-local": "zuul --local -- test/*.js", 13 | "preversion": "npm test", 14 | "version:auto": "npm version $(conventional-recommended-bump --preset=angular)", 15 | "postversion": "git push --tags && git push", 16 | "release": "npm run version:auto && npm publish", 17 | "prepublish": "npm run build" 18 | }, 19 | "engines": { 20 | "node": "> 0.8" 21 | }, 22 | "author": { 23 | "name": "Olivier Lalonde", 24 | "email": "olalonde@gmail.com", 25 | "url": "http://www.syskall.com/" 26 | }, 27 | "repository": { 28 | "type": "git", 29 | "url": "https://github.com/olalonde/node-yelp.git" 30 | }, 31 | "homepage": "https://github.com/olalonde/node-yelp", 32 | "dependencies": { 33 | "oauth": ">=0.9.0 <1.0.0" 34 | }, 35 | "license": "MIT", 36 | "devDependencies": { 37 | "babel-cli": "^6.1.18", 38 | "babel-eslint": "^4.1.5", 39 | "babel-preset-es2015": "^6.1.18", 40 | "babelify": "^7.3.0", 41 | "blue-tape": "^0.1.10", 42 | "conventional-recommended-bump": "0.0.3", 43 | "cz-conventional-changelog": "^1.1.4", 44 | "eslint": "^1.9.0", 45 | "eslint-config-airbnb": "^1.0.0", 46 | "rimraf": "^2.4.3", 47 | "zuul": "^3.11.1" 48 | }, 49 | "config": { 50 | "commitizen": { 51 | "path": "node_modules/cz-conventional-changelog/" 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import querystring from 'querystring'; 2 | import oauth from 'oauth'; 3 | 4 | const OAuth = oauth.OAuth; 5 | 6 | const baseUrl = 'https://api.yelp.com/v2/'; 7 | 8 | class Yelp { 9 | constructor(opts) { 10 | this.oauthToken = opts.token; 11 | this.oauthTokenSecret = opts.token_secret; 12 | this.oauth = new OAuth( 13 | null, 14 | null, 15 | opts.consumer_key, 16 | opts.consumer_secret, 17 | opts.version || '1.0', 18 | null, 19 | 'HMAC-SHA1' 20 | ); 21 | } 22 | 23 | get(resource, params = {}, cb) { 24 | const promise = new Promise((resolve, reject) => { 25 | const debug = params.debug; 26 | delete params.debug; 27 | 28 | this.oauth.get( 29 | baseUrl + resource + '?' + querystring.stringify(params), 30 | this.oauthToken, 31 | this.oauthTokenSecret, 32 | (err, _data, response) => { 33 | if (err) return reject(err); 34 | const data = JSON.parse(_data); 35 | if (debug) return resolve([ data, response ]); 36 | resolve(data); 37 | } 38 | ); 39 | }); 40 | if (typeof cb === 'function') { 41 | promise 42 | .then((res) => cb(null, res)) 43 | .catch(cb); 44 | return null; 45 | } 46 | return promise; 47 | } 48 | 49 | search(params, callback) { 50 | return this.get('search', params, callback); 51 | } 52 | 53 | business(id, callback) { 54 | return this.get('business/' + id, undefined, callback); 55 | } 56 | 57 | /** 58 | * Exampe: 59 | * yelp.phone_search({phone: "+12223334444"}, function(error, data) {}); 60 | */ 61 | phoneSearch(params, callback) { 62 | return this.get('phone_search', params, callback); 63 | } 64 | } 65 | 66 | export default Yelp; 67 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | import test from 'blue-tape'; 2 | import Yelp from '../src/'; 3 | 4 | const opts = { 5 | consumer_key: process.env.CONSUMER_KEY, 6 | consumer_secret: process.env.CONSUMER_SECRET, 7 | token: process.env.TOKEN, 8 | token_secret: process.env.TOKEN_SECRET, 9 | }; 10 | 11 | const yelp = new Yelp(opts); 12 | 13 | test('yelp search', (t) => { 14 | return yelp.search({ 15 | term: 'food', 16 | location: 'Montreal', 17 | }).then((data) => { 18 | t.equal(typeof data.region, 'object'); 19 | t.equal(typeof data.total, 'number'); 20 | t.ok(Array.isArray(data.businesses), 'businesses is array'); 21 | }) 22 | .catch((err) => { 23 | t.error(err); 24 | }); 25 | }); 26 | 27 | test('yelp business', (t) => { 28 | return yelp.business('yelp-san-francisco').then((data) => { 29 | t.equal(data.is_claimed, true); 30 | t.equal(typeof data.rating, 'number'); 31 | t.equal(typeof data.mobile_url, 'string'); 32 | t.ok(Array.isArray(data.categories), 'categories is array'); 33 | t.ok(Array.isArray(data.reviews), 'reviews is array'); 34 | }) 35 | .catch((err) => { 36 | t.error(err); 37 | }); 38 | }); 39 | 40 | test('yelp phoneSearch', (t) => { 41 | return yelp.phoneSearch({ phone: '+15555555555' }).then((data) => { 42 | t.equal(typeof data.total, 'number'); 43 | t.ok(Array.isArray(data.businesses), 'businesses is array'); 44 | }) 45 | .catch((err) => { 46 | t.error(err); 47 | }); 48 | }); 49 | 50 | test('yelp - callback', (t) => { 51 | t.plan(4); 52 | yelp.search({ 53 | term: 'food', 54 | location: 'Montreal', 55 | }, (err, data) => { 56 | t.error(err); 57 | t.equal(typeof data.region, 'object'); 58 | t.equal(typeof data.total, 'number'); 59 | t.ok(Array.isArray(data.businesses), 'businesses is array'); 60 | }); 61 | }); 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/olalonde/node-yelp.svg?branch=master)](https://travis-ci.org/olalonde/node-yelp) [![NPM version](https://badge.fury.io/js/yelp.png)](http://badge.fury.io/js/yelp) 2 | 3 | Node.js module for interfacing with [Yelp](http://www.yelp.com)'s API 4 | v2.0. Supports both promises and callbacks. 5 | 6 | # Install 7 | 8 | ``` 9 | npm install --save yelp 10 | ``` 11 | 12 | # Usage 13 | 14 | ```javascript 15 | // Request API access: http://www.yelp.com/developers/getting_started/api_access 16 | var Yelp = require('yelp'); 17 | 18 | var yelp = new Yelp({ 19 | consumer_key: 'consumer-key', 20 | consumer_secret: 'consumer-secret', 21 | token: 'token', 22 | token_secret: 'token-secret', 23 | }); 24 | 25 | // See http://www.yelp.com/developers/documentation/v2/search_api 26 | yelp.search({ term: 'food', location: 'Montreal' }) 27 | .then(function (data) { 28 | console.log(data); 29 | }) 30 | .catch(function (err) { 31 | console.error(err); 32 | }); 33 | 34 | // See http://www.yelp.com/developers/documentation/v2/business 35 | yelp.business('yelp-san-francisco') 36 | .then(console.log) 37 | .catch(console.error); 38 | 39 | yelp.phoneSearch({ phone: '+15555555555' }) 40 | .then(console.log) 41 | .catch(console.error); 42 | 43 | // A callback based API is also available: 44 | yelp.business('yelp-san-francisco', function(err, data) { 45 | if (err) return console.log(error); 46 | console.log(data); 47 | }); 48 | ``` 49 | 50 | See [./test](./test) for more usage examples. 51 | 52 | # References 53 | 54 | - [Search API](http://www.yelp.com/developers/documentation/v2/search_api) 55 | - [Business API](http://www.yelp.com/developers/documentation/v2/business) 56 | 57 | # Test 58 | 59 | ```bash 60 | CONSUMER_KEY="" CONSUMER_SECRET="" TOKEN="" TOKEN_SECRET="" npm test 61 | ``` 62 | 63 | # License 64 | 65 | Copyright (c) 2012 Olivier Lalonde 66 | 67 | Permission is hereby granted, free of charge, to any person obtaining a 68 | copy of this software and associated documentation files (the 69 | "Software"), to deal in the Software without restriction, including 70 | without limitation the rights to use, copy, modify, merge, publish, 71 | distribute, sublicense, and/or sell copies of the Software, and to 72 | permit persons to whom the Software is furnished to do so, subject to 73 | the following conditions: 74 | 75 | The above copyright notice and this permission notice shall be included 76 | in all copies or substantial portions of the Software. 77 | 78 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 79 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 81 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 82 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 83 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 84 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 85 | --------------------------------------------------------------------------------