Skip to content
Browse files

added files

  • Loading branch information...
1 parent 30183e8 commit f1ade1cac8cca24d334b2a01792924a11724d761 @TJkrusinski TJkrusinski committed Sep 28, 2012
Showing with 463 additions and 0 deletions.
  1. +7 −0 Makefile
  2. +169 −0 lib/foursquare.js
  3. +1 −0 lib/index.js
  4. +35 −0 package.json
  5. BIN tests/.DS_Store
  6. +251 −0 tests/foursquare.js
View
7 Makefile
@@ -0,0 +1,7 @@
+REPORTER = spec
+
+test:
+ @NODE_ENV=test ./node_modules/.bin/mocha \
+ --reporter $(REPORTER)
+
+.PHONY: test
View
169 lib/foursquare.js
@@ -0,0 +1,169 @@
+'use strict';
+
+var https = require('https'),
+ querystring = require('querystring');
+
+module.exports = function(appId, secretKey){
+
+ var fourSquare = {
+ _request: function(method, path, callback){
+ var requestOptions,
+ req;
+
+ requestOptions = {
+ host: "api.foursquare.com",
+ method: method,
+ port: 443,
+ path: "/v2"+path,
+ headers: {
+ 'Accept': 'text/json',
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ 'Content-Length': '0'
+ },
+ };
+
+ req = https.request(requestOptions);
+ this._response(req, callback);
+ req.write('');
+ req.end();
+ },
+ _response: function(req, callback){
+ var me = this,
+ err;
+
+ if(typeof req === 'function') return;
+
+ req.on('response', function(res){
+ var response = '';
+
+ res.setEncoding('utf8');
+ res.on('data', function(data){
+ response += data;
+ });
+ res.on('end', function(){
+ err = res.statusCode;
+ try {
+ response = JSON.parse(response);
+ } catch(e) {
+ err = 500;
+ response = "Foursquare did not return JSON";
+ };
+ return callback(err, response);
+ });
+ });
+ },
+ post: function(path, callback){
+ this._request('POST', path, callback);
+ },
+ get: function(path, callback){
+ this._request('GET', path, callback);
+ },
+ log: function(args){
+ if(!this.logging) return;
+ args.forEach(console.log);
+ },
+ logging: 'taking them to the mill, fine sir',
+ query: function(path, obj){
+ var requestData;
+
+ if(obj){
+ requestData = querystring.stringify(obj);
+ path += '?'+requestData+'&';
+ } else {
+ path += '?';
+ };
+ return path+'client_id='+appId+'&client_secret='+secretKey+'&v=20120928';
+ },
+ };
+
+ return {
+ venues: {
+ venue: function(venueId, callback){
+ fourSquare.get(fourSquare.query('/venues/'+venueId), callback);
+ },
+ categories: function(callback){
+ fourSquare.get(fourSquare.query('/venues/categories'), callback);
+ },
+ search: function(infoObj, callback){
+ fourSquare.get(fourSquare.query('/venues/search', infoObj), callback);
+ },
+ explore: function(infoObj, callback){
+ fourSquare.get(fourSquare.query('/venues/explore', infoObj), callback);
+ },
+ suggestcompletion: function(infoObj, callback){
+ fourSquare.get(fourSquare.query('/venues/suggestcompletion', infoObj), callback);
+ },
+ trending: function(infoObj, callback){
+ fourSquare.get(fourSquare.query('/venues/trending', infoObj), callback);
+ },
+ events: function(venueId, callback){
+ fourSquare.get(fourSquare.query('/venues/'+venueId+'/events'), callback);
+ },
+ hours: function(venueId, callback){
+ fourSquare.get(fourSquare.query('/venues/'+venueId+'/hours'), callback);
+ },
+ likes: function(venueId, callback){
+ fourSquare.get(fourSquare.query('/venues/'+venueId+'/likes'), callback);
+ },
+ links: function(venueId, callback){
+ fourSquare.get(fourSquare.query('/venues/'+venueId+'/links'), callback);
+ },
+ listed: function(venueId, infoObj, callback){
+ fourSquare.get(fourSquare.query('/venues/'+venueId+'/listed', infoObj), callback);
+ },
+ menu: function(venueId, callback){
+ fourSquare.get(fourSquare.query('/venues/'+venueId+'/menu'), callback);
+ },
+ photos: function(venueId, infoObj, callback){
+ fourSquare.get(fourSquare.query('/venues/'+venueId+'/photos', infoObj), callback);
+ },
+ tips: function(venueId, infoObj, callback){
+ fourSquare.get(fourSquare.query('/venues/'+venueId+'/tips', infoObj), callback);
+ },
+ },
+ tips: {
+ search: function(infoObj, callback){
+ fourSquare.get(fourSquare.query('/tips/search', infoObj), callback);
+ },
+ done: function(tipId, infoObj, callback){
+ fourSquare.get(fourSquare.query('/tips/'+tipId+'/done', infoObj), callback);
+ },
+ likes: function(tipId, callback){
+ fourSquare.get(fourSquare.query('/tips/'+tipId+'/likes'), callback);
+ },
+ listed: function(tipId, infoObj, callback){
+ fourSquare.get(fourSquare.query('/tips/'+tipId+'/listed', infoObj), callback);
+ },
+ },
+ lists: {
+ detail: function(listId, infoObj, callback){
+ fourSquare.get(fourSquare.query('/lists/'+listId, infoObj), callback);
+ },
+ followers: function(listId, callback){
+ fourSquare.get(fourSquare.query('/lists/'+listId+'/followers'), callback);
+ },
+ },
+ specials: {
+ detail: function(listId, infoObj, callback){
+ fourSquare.get(fourSquare.query('/specials/'+listId, infoObj), callback);
+ },
+ search: function(infoObj, callback){
+ fourSquare.get(fourSquare.query('/specials/search', infoObj), callback);
+ },
+ },
+ events: {
+ categories: function(callback){
+ fourSquare.get(fourSquare.query('/events/categories'), callback);
+ },
+ search: function(infoObj, callback){
+ fourSquare.get(fourSquare.query('/events/search', infoObj), callback);
+ },
+ },
+ pages: {
+ venues: function(pageId, infoObj, callback){
+ fourSquare.get(fourSquare.query('/pages/'+pageId+'/venues', infoObj), callback);
+ },
+ },
+ };
+
+};
View
1 lib/index.js
@@ -0,0 +1 @@
+module.exports = require('./foursquare.js');
View
35 package.json
@@ -0,0 +1,35 @@
+{
+ "author": {
+ "name": "TJ Krusinski",
+ "email": "tj@futura.io",
+ "url": "http://futura.io"
+ },
+ "name": "node-foursquare-venues",
+ "description": "v2 API Wrapper for foursquare venue platform",
+ "main": "./foursquare",
+ "version": "0.0.1",
+ "keywords": [
+ "foursquare",
+ "four square",
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/carlos8f/node-idgen.git"
+ },
+ "homepage": "https://github.com/carlos8f/node-idgen",
+ "dependencies": {},
+ "devDependencies": {
+ "mocha": "*"
+ },
+ "optionalDependencies": {},
+ "engines": {
+ "node": "*"
+ },
+ "license": "MIT",
+ "readme": "idgen\n-----\n\nMinimal ID generator\n\n[![build status](https://secure.travis-ci.org/carlos8f/node-idgen.png)](http://travis-ci.org/carlos8f/node-idgen)\n\nInstall\n=======\n\n```bash\n$ npm install idgen\n```\n\nUsage\n=====\n\n```javascript\nvar idgen = require('idgen');\nconsole.log(idgen());\nconsole.log(idgen(10, 'abcdefg'));\n```\n\n```\nJQGZwAVR\negbacgfbgc\n```\n\nCLI version\n===========\n\n```bash\n$ npm install -g idgen\n$ idgen\n1WWQ1OEc\n$ idgen 4 0123456789\n6533\n$ idgen_hex 24\ndd8ea9d0243e1a9b2f28a068\n```\n\nLicense\n=======\n\nMIT",
+ "_id": "idgen@1.1.2",
+ "dist": {
+ "shasum": "7a6ef496692d43a5618feae3ec8f136a353c0c65"
+ },
+ "_from": "idgen@1.1.2"
+}
View
BIN tests/.DS_Store
Binary file not shown.
View
251 tests/foursquare.js
@@ -0,0 +1,251 @@
+var foursquare = require('../foursquare')('2M3G51CNK2XPGPNENIQ4YM4MJRTVT5X500URF5BM5KLI0DG3', 'K40XMENAHJCA5PFNUTXVWYTJEHOUVHXQIAL44ACJKPUMOQ3U'),
+ assert = require('chai').assert;
+
+describe('the foursquare node api', function(){
+ describe('the venues methods', function(){
+ describe('venues#venue()', function(){
+ it('gets a venue', function(done){
+ foursquare.venues.venue('40a55d80f964a52020f31ee3', function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#categories()', function(){
+ it('gets categories of venues', function(done){
+ foursquare.venues.categories(function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#search()', function(){
+ it('gets a list of venues based off a search', function(done){
+ foursquare.venues.search({ll:"40.7,-74", radius:20}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#explore()', function(){
+ it('gets a list of venues based off a search', function(done){
+ foursquare.venues.explore({ll:"40.7,-74", radius:20}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#suggestcompletion()', function(){
+ it('suggestion autocompletion', function(done){
+ foursquare.venues.suggestcompletion({ll:"44.3,37.2", query: "foursq"}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#trending()', function(){
+ it('returns a list of trending venues in the area', function(done){
+ foursquare.venues.trending({ll:"44.3,37.2", limit: 20}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#events()', function(){
+ it('returns a list of events happening at the venue', function(done){
+ foursquare.venues.events('40a55d80f964a52020f31ee3', function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#hours()', function(){
+ it('returns the operating hours at the venue', function(done){
+ foursquare.venues.hours('40a55d80f964a52020f31ee3', function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#likes()', function(){
+ it('returns the number of likes for the venue', function(done){
+ foursquare.venues.likes('40a55d80f964a52020f31ee3', function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#links()', function(){
+ it('returns a list of links for the venue', function(done){
+ foursquare.venues.links('40a55d80f964a52020f31ee3', function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#listed()', function(){
+ it('returns ids of lists the venue is on', function(done){
+ foursquare.venues.listed('40a55d80f964a52020f31ee3', {group:"other"}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#menu()', function(){
+ it('returns the menu if the venue has one', function(done){
+ foursquare.venues.menu('40a55d80f964a52020f31ee3', function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#photos()', function(){
+ it('returns photos of the venue', function(done){
+ foursquare.venues.photos('40a55d80f964a52020f31ee3', {group:"venue"}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('venues#tips()', function(){
+ it('returns the venues tips', function(done){
+ foursquare.venues.tips('40a55d80f964a52020f31ee3', {sort:"recent"}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ });
+ describe('the tips methods', function(){
+ describe('tips#search()', function(){
+ it('gets tips based of a query', function(done){
+ foursquare.tips.search({ll:"44.3,37.2"}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('tips#search()', function(){
+ it('gets tips based of a query', function(done){
+ foursquare.tips.search({ll:"44.3,37.2"}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('tips#done()', function(){
+ it('Returns an array of users have done this tip', function(done){
+ foursquare.tips.done('4e5b969ab61c4aaa3e183989', {limit:"10"}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('tips#likes()', function(){
+ it('Returns friends and a total count of users who have liked this tip', function(done){
+ foursquare.tips.likes('4e5b969ab61c4aaa3e183989', function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('tips#listed()', function(){
+ it('The lists that this tip appears on', function(done){
+ foursquare.tips.listed('4e5b969ab61c4aaa3e183989', {group:"other"}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ });
+ describe('the lists methods', function(){
+ describe('lists#detail()', function(){
+ it('Gives details about a list', function(done){
+ foursquare.lists.detail('50661c87e4b0679acac1d7e9', {limit:"20"}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('lists#followers()', function(){
+ it('Returns a count and items of users following this list. ', function(done){
+ foursquare.lists.followers('50661c87e4b0679acac1d7e9', function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ });
+ describe('specials methods', function(){
+ describe('specials#detail()', function(){
+ it('Gives details about a special', function(done){
+ foursquare.specials.detail('4e0debea922e6f94b1410bb7', {venueId:'4e0deab3922e6f94b1410af3'}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('specials#search()', function(){
+ it('searches for specials', function(done){
+ foursquare.specials.search({ll:"44.3,37.2"}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ });
+ describe('events methods', function(){
+ describe('events#categories()', function(){
+ it('Returns a hierarchical list of categories applied to events', function(done){
+ foursquare.events.categories(function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ describe('events#search()', function(){
+ it('Returns a hierarchical list of categories applied to events', function(done){
+ foursquare.events.search({domain:"songkick.com", eventId:"8183976"}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ });
+ describe('pages methods', function(){
+ describe('pages#venues()', function(){
+ it('Allows you to get the page\'s venues', function(done){
+ foursquare.pages.venues('1070527', {ll:"44.3,37.2"}, function(status, resp){
+ assert.equal(200, status);
+ assert.isObject(resp);
+ done();
+ });
+ });
+ });
+ });
+});

0 comments on commit f1ade1c

Please sign in to comment.
Something went wrong with that request. Please try again.