Skip to content

Commit 68585a6

Browse files
committed
Merge pull request #74 from hbeeken/foursquare-time-of-day
Adding capability to explore venues not targetted for current day/time
2 parents d8502d4 + abe0178 commit 68585a6

File tree

3 files changed

+112
-7
lines changed

3 files changed

+112
-7
lines changed

foursquare/foursquare.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,22 @@
168168
<option value="outdoors">outdoor venues</option>
169169
<option value="sights">sights</option>
170170
<option value="all">venues</option>
171-
</select>&nbsp;nearby
171+
</select>&nbsp;nearby
172+
</div>
173+
<div class="form-row">
174+
<label>&nbsp;</label>which are open
175+
<select id="node-input-openday" style='width:50% !important'>
176+
<option value="today">today</option>
177+
<option value="any">on any day of the week</option></select>
172178
</div>
179+
<div class="form-row">
180+
<label>&nbsp;</label>at
181+
<select id="node-input-opentime" style='width:50% !important'>
182+
<option value="currenttime">the current time of day</option>
183+
<option value="any">any time of day</option>
184+
</select>
185+
</div>
186+
173187
<div class="form-row">
174188
<label for="node-input-outputnumber"><i class="fa fa-sign-out"></i> Output</label>
175189
<select id="node-input-outputnumber" style="width:15% !important">
@@ -257,6 +271,8 @@
257271
section: {value:""},
258272
outputnumber:{value:"1"},
259273
outputas:{value:"single"},
274+
openday:{value:"today"},
275+
opentime:{value:"currenttime"},
260276
name: {value:""}
261277
},
262278
inputs:1,

foursquare/foursquare.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ module.exports = function(RED) {
5555
node.section = n.section;
5656
node.outputNumber = parseInt(n.outputnumber) || 50;
5757
node.outputAs = n.outputas || "multiple";
58+
node.openday = n.openday || "today";
59+
node.opentime = n.opentime || "currenttime";
5860

5961
var credentials = RED.nodes.getCredentials(n.foursquare);
6062
var credentialsOk = checkCredentials(node, credentials);
@@ -101,13 +103,18 @@ module.exports = function(RED) {
101103
}
102104

103105
function getRecommendedVenuesNearLocation(node, credentials, msg, callback) {
104-
var apiUrl;
105-
if (node.section === "all") {
106-
apiUrl = "https://api.foursquare.com/v2/venues/explore?oauth_token=" + credentials.accesstoken + "&ll=" + msg.location.lat + "," + msg.location.lon + "&v=20141016&m=foursquare";
107-
} else {
108-
apiUrl = "https://api.foursquare.com/v2/venues/explore?oauth_token=" + credentials.accesstoken + "&section=" + node.section + "&ll=" + msg.location.lat + "," + msg.location.lon + "&v=20141016&m=foursquare";
106+
var apiUrl = "https://api.foursquare.com/v2/venues/explore?oauth_token=" + credentials.accesstoken;
107+
if (node.section !== "all") {
108+
apiUrl = apiUrl + "&section=" + node.section;
109109
}
110-
110+
if (node.openday === "any") {
111+
apiUrl = apiUrl + "&day=any";
112+
}
113+
if (node.opentime === "any") {
114+
apiUrl = apiUrl + "&time=any";
115+
}
116+
apiUrl = apiUrl + "&ll=" + msg.location.lat + "," + msg.location.lon + "&v=20141016&m=foursquare";
117+
111118
request.get(apiUrl,function(err, httpResponse, body) {
112119
if (err) {
113120
node.error(err.toString());

test/foursquare/foursquare_spec.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,88 @@ describe('foursquare nodes', function() {
583583
});
584584
});
585585

586+
587+
it('can fetch multiple recommended sights for any day', function(done) {
588+
helper.load(foursquareNode,
589+
[ {id:"n1", type:"helper", wires:[["n2"]]},
590+
{id:"n4", type:"foursquare-credentials"},
591+
{id:"n2", type:"foursquare", foursquare: "n4", wires:[["n3"]], outputnumber:"10",outputas:"single", openday:"any"},
592+
{id:"n3", type:"helper"}],
593+
{
594+
"n4": {
595+
displayname : "John",
596+
clientid: "987654321",
597+
clientsecret:"123456789",
598+
accesstoken:"abcd1234",
599+
},
600+
},
601+
function() {
602+
var scope = nock('https://api.foursquare.com:443')
603+
.get('/v2/venues/explore?oauth_token=abcd1234&section=sights&day=any&ll=51.03,-1.4&v=20141016&m=foursquare')
604+
.reply(200, {"meta":{"code":200},"response":{"groups":
605+
[{"count":1, "items":
606+
[{"reasons": { "count": 1, "items": [ { "summary": "You've been here 3 times", "type": "social", "reasonName": "friendAndSelfCheckinReason", "count": 0 } ] },
607+
"venue": { "id": "4da429a8b", "name": "Zoo", "location": { "lat": 51.03, "lng": -1.42}}},
608+
{"reasons": { "count": 1, "items": [ { "summary": "Very popular", "type": "social", "reasonName": "friendAndSelfCheckinReason", "count": 0 } ] },
609+
"venue": { "id": "5is0fe9fd", "name": "Playground", "location": { "lat": 52.12, "lng": -1.62}}}]
610+
}]}});
611+
612+
var n1 = helper.getNode("n1");
613+
var n2 = helper.getNode("n2");
614+
var n3 = helper.getNode("n3");
615+
n2.should.have.property('id','n2');
616+
n1.send({payload:"nothing", location:{lat:"51.03", lon:"-1.4"}, section:"sights", foo:"bar"});
617+
n3.on('input', function(msg){
618+
msg.should.have.property('foo', "bar");
619+
msg.payload.should.be.an.instanceOf(Array);
620+
done();
621+
});
622+
623+
});
624+
});
625+
626+
627+
it('can fetch multiple recommended sights for any time', function(done) {
628+
helper.load(foursquareNode,
629+
[ {id:"n1", type:"helper", wires:[["n2"]]},
630+
{id:"n4", type:"foursquare-credentials"},
631+
{id:"n2", type:"foursquare", foursquare: "n4", wires:[["n3"]], outputnumber:"10",outputas:"single",opentime:"any"},
632+
{id:"n3", type:"helper"}],
633+
{
634+
"n4": {
635+
displayname : "John",
636+
clientid: "987654321",
637+
clientsecret:"123456789",
638+
accesstoken:"abcd1234",
639+
},
640+
},
641+
function() {
642+
var scope = nock('https://api.foursquare.com:443')
643+
.get('/v2/venues/explore?oauth_token=abcd1234&section=sights&time=any&ll=51.03,-1.4&v=20141016&m=foursquare')
644+
.reply(200, {"meta":{"code":200},"response":{"groups":
645+
[{"count":1, "items":
646+
[{"reasons": { "count": 1, "items": [ { "summary": "You've been here 3 times", "type": "social", "reasonName": "friendAndSelfCheckinReason", "count": 0 } ] },
647+
"venue": { "id": "4da429a8b", "name": "Zoo", "location": { "lat": 51.03, "lng": -1.42}}},
648+
{"reasons": { "count": 1, "items": [ { "summary": "Very popular", "type": "social", "reasonName": "friendAndSelfCheckinReason", "count": 0 } ] },
649+
"venue": { "id": "5is0fe9fd", "name": "Playground", "location": { "lat": 52.12, "lng": -1.62}}}]
650+
}]}});
651+
652+
var n1 = helper.getNode("n1");
653+
var n2 = helper.getNode("n2");
654+
var n3 = helper.getNode("n3");
655+
n2.should.have.property('id','n2');
656+
n1.send({payload:"nothing", location:{lat:"51.03", lon:"-1.4"}, section:"sights", foo:"bar"});
657+
n3.on('input', function(msg){
658+
msg.should.have.property('foo', "bar");
659+
msg.payload.should.be.an.instanceOf(Array);
660+
done();
661+
});
662+
663+
});
664+
});
665+
666+
667+
586668
}}
587669
);
588670
});

0 commit comments

Comments
 (0)