public
Last active

foursquare-streams

  • Download Gist
index.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
var querystring = require('querystring')
var hyperquest = require('hyperquest')
var JSONStream = require('JSONStream')
var through = require('through')
var mapStream = require('map-stream')
 
exports.createClient = function (opts) {
 
if (!opts.clientId || !opts.clientSecret) {
throw new Error('options object requires `clientId` and `clientSecret` members.')
}
 
var clientId = opts.clientId
var clientSecret = opts.clientSecret
var today = new Date()
var month = today.getMonth() + 1
 
if (month < 10) {
month = '0' + month
}
 
var day = today.getDate()
 
if (day < 10) {
day = '0' + day
}
 
var date = today.getFullYear() + '' + month + '' + day
 
var credentials = {
'v': date,
'client_id': clientId,
'client_secret': clientSecret
}
 
var client = {}
client.getVenues = function getVenues(params) {
 
var url = [
'https://api.foursquare.com/v2/venues/search?',
querystring.stringify(params) + '&',
querystring.stringify(credentials)
].join('')
 
return hyperquest(url)
.pipe(JSONStream.parse('response.venues.*'))
.pipe(mapStream(function (venueRef, callback) {
 
var that = this
 
client.getVenue({
venueId: venueRef.id
}).pipe(through(function(venue) {
callback(null, venue)
}))
}))
}
 
client.exploreVenues = function exploreVenues(params, callback) {
var url = [
'https://api.foursquare.com/v2/venues/explore?',
querystring.stringify(params) + '&',
querystring.stringify(credentials)
].join('')
 
return hyperquest(url).pipe(JSONStream.parse())
}
client.getVenue = function getVenue(params, callback) {
var url = [
'https://api.foursquare.com/v2/venues/',
params.venueId + '?',
querystring.stringify(credentials)
].join('')
 
return hyperquest(url).pipe(JSONStream.parse())
}
 
return client
}
license.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Copyright (c) 2013 hij1nx. All rights reserved.
 
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
 
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
 
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package.json
JSON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
{
"name": "foursquare-streams",
"version": "0.0.1",
"description": "various foursquare APIs, streaming",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": "https://gist.github.com/6808425.git",
"author": "",
"license": "BSD",
"readme": "ERROR: No README data found!",
"dist": {
"shasum": "da6ea75dc5b55692332f878ea489001d00e33257"
},
"dependencies": {
"hyperquest": "~0.1.6",
"JSONStream": "~0.6.4",
"through": "~2.3.4",
"map-stream": "0.0.2"
}
}
readme.md
Markdown

SYNOPSIS

A simple streaming abstraction for foursquare's REST APIs

DESCRIPTION

If you for some reason want to collect the garbage that is foursquare's data, but you want to do it with streams, here's a module for it. Zing!

USAGE

var fsconn = {
  clientId: '2DSWUN',
  clientSecret: 'YCSISJ'
}

var foursquare = require('foursquare-streams').createClient(fsconn)

var opts = {
  'near': 'NYC',
  'limit': 50,
}

foursquare.getVenues(opts).pipe(...) // pipe that stream, dog!

INSTALL

$ npm install foursquare-streams

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.