Permalink
Browse files

added files

  • Loading branch information...
TJkrusinski committed Sep 28, 2012
1 parent 30183e8 commit f1ade1cac8cca24d334b2a01792924a11724d761
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
@@ -0,0 +1,7 @@
+REPORTER = spec
+
+test:
+ @NODE_ENV=test ./node_modules/.bin/mocha \
+ --reporter $(REPORTER)
+
+.PHONY: test
View
@@ -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
@@ -0,0 +1 @@
+module.exports = require('./foursquare.js');
View
@@ -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
Binary file not shown.
Oops, something went wrong.

0 comments on commit f1ade1c

Please sign in to comment.