Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
initial commit, business and search work
Browse files Browse the repository at this point in the history
  • Loading branch information
olalonde committed May 14, 2011
0 parents commit ac66c4c
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
18 changes: 18 additions & 0 deletions demo/yelp.js
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/yelp');
55 changes: 55 additions & 0 deletions lib/yelp.js
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit ac66c4c

Please sign in to comment.