Nuddles
Nuddles is a Node.js wrapper for the foursquare API. It will enable you to effortlessly query their multiple endpoints. We make no assumptions about how you are going to use it, we just return the data to you. You are free do manipulate the results as you wish.
Requirements
Before you can start using Nuddles, please make sure you have your access tokens ready. If you
don't know how to aquire them, you can simply head over to the foursquare developers
site, click "create new app" and follow the instructions. Foursquare will provide you with
a clientId
and a clientSecret
token that you will need to query the API.
Installation
$ npm install nuddles --save
Depending on your setup, you may need sudo privileges
Usage
Userless Access
To use Nuddles in your project, you first need to import it and instantiate a new Client
object.
const nuddles = const client = clientId: "your client id" clientSecret: "your client secret"
Every new Client
object must be instantiated with both your clientId
and clientSecret
,
you can also specify an optional api version if you wish to (it currently defaults to
20161026
)
const client = clientId: "your client id" clientSecret: "your client secret" apiVersion: "YYYYMMDD"
Authenticated requests
The setup above is perfectly fine for making requests to Foursquare's publicly accessible endpoints. However if you need to access protected endpoints that require acting users, you must first authenticate them using the OAuth2 flow.
Step 1: Instantiate a new nuddles.Client
object
const client = clientId: "your client id" clientSecret: "your client secret" apiVersion: "YYYYMMDD" // optional redirectUri: "your redirect uri"
Notice that we pass a redirectUri
attribute to the config. It must match the
redirect uri you set when creating the app on the foursquare developer's site.
Step 2: Create an authorization link / button for your users
const authorizationUrl = clientauth_url// Render this url as a link / button in your front end app
Step 3: Request an access token
Once your users click on the link and give your app authorization to use their account on
their behalf, they will be redirected to your redirectUri
.
An authorization code will be passed along as a query parameter. You will need to capture that code and store it in a variable.
// Example using expresslet authorizationCode app
Once you have that code you can request an access token to Foursquare
client // Make note of this token // Handle the error
Step 4: Set your access token
clientaccessToken = "yourSavedAccessToken"
Ideally you'd want to store your credentials in a separate config file ignored by version control or in environment variables
Set your acccess token directly
Alternatively, if you already have an access token, you can just skip step 1 to 4 and directly instantiate a client with your accessToken.
const client = nuddles
Nuddles also exposes seven other classes: User
, Venue
, Checkin
, Tip
, Photo
, Settings
and List
.
All of the above classes accept an optional id
upon instantiation (ex: the Id of a venue when creating a new Venue)
Venue
const client = clientId: "your client id" clientSecret:"your client secret" // Venueconst venue = client "someVenueId" // Listconst list = client "someListId"
Examples
Please note that all methods return promises, which means you will have to call .then()
to manipulate the response
All methods that accept a params
argument should be passed an object with a list of
query parameters for your request, these parameters should match the ones listed in the
official documentation.
Search Venues
client // Your other query params here
Get a Venue's Opening Hours
venue
Get a List's Followers
list
Full list of methods
All Venues
client
Venue
venuevenuevenuevenuevenuevenuevenuevenuevenuevenuevenuevenuevenuevenue
List
listlistlistlistlistlistlistlistlistlistlistlistlistlistlistlist
Checkin
checkincheckincheckincheckincheckincheckincheckincheckin
Tips
tiptiptiptiptiptiptip
Photo
photo
Settings
settingssettingsallsettings
Event
EventEventEvent
Special
SpecialSpecialSpecial
User
UserUserUserUserUserUserUserUserUser
Testing
In order to run the tests:
- rename the
credentials.example.js
file tocredentials.js
- fill in your personal credentials
- run
npm test
Contributing
Nuddles is a work in progress and an open source project. If you spot something that can be improved, a missing endpoint or find a better way to achieve the same functionality, please feel free to add your contribution by way of a pull request.
License
Nuddles is licensed under the Do What The Fuck You Want license.
Todo
- User.deny()
- User.setPings()
- User.updatePhoto()
- User.unfriend()
- User.approve()