Need assistance on usage
jhnferraris opened this issue · 3 comments
Hello, is this still being maintained?
I want to know how to properly utilized this library.
// My Manager
export default class FoursquareManager {
constructor() {
const config = {
secrets: {
clientId: 'xxxxx',
clientSecret: 'xxxx$',
redirectUrl: 'xxxx,
},
};
this.foursquare = require("node-foursquare")(config);
}
getVenues() {
console.log('getting venues');
// Set the accesstoken as an empty string since I'm only accessing the public api.
return this.foursquare.Venues.search('40.7', '-74', null, {}, '', function (error, data) {
return data;
})
}
}
Testing via mocha:
describe("FoursquareManager", () => {
let fsqManager;
beforeEach(() => {
fsqManager = new FoursquareManager();
});
context("getVenues", () => {
context("can get venues", () => {
it("gets venues", done => {
let data = fsqManager.getVenues();
console.log('test', data);
done();
});
});
});
});
Logging the data
it revealed that is undefined
.
Is this the expected behavior then using this library or I'm using this in the wrong way?
I’m also having issues with the getVenue method. I can output "data" to the terminal, but the methods returns "undefined” and not the venue json object.
function getVenueDetails(id){
return foursquare.Venues.getVenue(id, null, function(error, data){
if(error) {
console.log(error);
}
else{
console.log(data);
return data
}
});
}
getVenueDetails(attendant);
I worked it out! Async code = difficult! The data object is undefined because it hasn't been created yet.
function getVenueDetails(id, callback){
foursquare.Venues.getVenue(id, null, function(error, data){
if(error) console.log(error)
//console.log(data);
callback(data);
});
}
getVenueDetails(venue_id, function(result){
//your venue info can be found here!
console.log(result);
});
Would be great to add an example like this to the readme
@jhnferraris node-foursquare
is an asynchronous library:
getVenues(callback) {
console.log('getting venues');
// Set the accesstoken as an empty string since I'm only accessing the public api.
this.foursquare.Venues.search('40.7', '-74', null, {}, '', callback);
}
describe("FoursquareManager", () => {
let fsqManager;
beforeEach(() => {
fsqManager = new FoursquareManager();
});
context("getVenues", () => {
context("can get venues", () => {
it("gets venues", done => {
fsqManager.getVenues(function(error, data) {
console.log('test', error || data);
done();
});
});
});
});
Obviously sorry for the delay. This library is maintained, just not as often as I used to maintain it.