Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit, business and search work

  • Loading branch information...
commit ac66c4cd851be8442ddd3370b6396f99a2db2af5 0 parents
@olalonde authored
Showing with 87 additions and 0 deletions.
  1. +18 −0 demo/yelp.js
  2. +1 −0  index.js
  3. +55 −0 lib/yelp.js
  4. +13 −0 package.json
18 demo/yelp.js
@@ -0,0 +1,18 @@
+var yelp = require("./yelp/index").createClient({
+ consumer_key: "consumer-key",
+ consumer_secret: "consumer-secret",
+ token: "token",
+ token_secret: "token-secret"
+});
+
+
+yelp.search({term: "food", location: "Montreal"}, function(error, data) {
+ console.log(error);
+ console.log(data);
+});
+
+yelp.business("yelp-san-francisco", function(error, data) {
+ console.log(error);
+ console.log(data);
+});
+
1  index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/yelp');
55 lib/yelp.js
@@ -0,0 +1,55 @@
+var sys = require('sys'),
+ querystring = require('querystring'),
+ OAuth = require('oauth').OAuth;
+
+var Client = function(oauth_config) {
+ this.oauth_token = oauth_config.token;
+ this.oauth_token_secret = oauth_config.token_secret;
+
+ this.oauth = new OAuth(
+ null,
+ null,
+ oauth_config.consumer_key,
+ oauth_config.consumer_secret,
+ oauth_config.version || "1.0",
+ null,
+ 'HMAC-SHA1'
+ );
+
+ return this;
+};
+
+var base_url = "http://api.yelp.com/v2/";
+
+Client.prototype.get = function(resource, params, callback) {
+ return this.oauth.get(
+ base_url + resource + '?' + querystring.stringify(params),
+ this.oauth_token,
+ this.oauth_token_secret,
+ function(error, data, response) {
+ if(!error) data = JSON.parse(data);
+ callback(error, data, response);
+ }
+ );
+}
+
+/*
+Exampe:
+yelp.search({term: "food", location: "Montreal"}, function(error, data) {});
+*/
+Client.prototype.search = function(params, callback) {
+ return this.get('search', params, callback);
+}
+
+/*
+Example:
+yelp.business("yelp-san-francisco", function(error, data) {});
+*/
+Client.prototype.business = function(id, callback) {
+ return this.get('business/' + id, null, callback);
+}
+
+// @see http://www.yelp.com/developers/documentation/v2/authentication
+module.exports.createClient = function(oauth_config) {
+ return new Client(oauth_config);
+};
13 package.json
@@ -0,0 +1,13 @@
+{ "name" : "yelp"
+, "description" : "Library for interacting with Yelp's API v2.0."
+, "version" : "0.1.0"
+, "directories" : { "lib" : "./lib" }
+, "main" : "index.js"
+, "author" : {
+ "name" : "Olivier Lalonde"
+ , "email" : "olalonde@gmail.com"
+ , "url" : "http://www.syskall.com/"
+ }
+, "repository" : { "type":"git", "url":"https://github.com/olalonde/node-yelp.git" }
+, "homepage" : "https://github.com/olalonde/node-yelp"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.