spypoint-api-wrapper
A simple Node.js wrapper for the Spypoint game camera API
Getting Started
Initialize the Spypoint client
import SpypointClient from 'spypoint-api-wrapper'
const Spypoint = new SpypointClient()
await Spypoint.login('YOUR_EMAIL_OR_USERNAME', 'YOUR_PASSWORD')
Using within express.js routes and individual users
import SpypointClient from './spypoint.js'
// Send user crederntials to login route and set auth token on the cookie
router.post('/login', async (req, res) => {
const Spypoint = new SpypointClient()
const bearer = await Spypoint.login(req.body.email, req.body.password)
res.cookie('authorization', bearer, {
expire: '2100-01-01T00:00:00.000Z,
httpOnly: process.env.NODE_ENV === 'production' ? true : false
})
res.send()
})
// Middleware to pass auth token for requestsg
const SpypointInit = (req, res, next) => {
if (!req.cookies.authorization) throw Error('You need to login with valid credentials first!')
req.Spypoint = new SpypointClient(req.cookies.authorization)
next()
}
router.get('/', SpypointInit, (req, res) => {
const cameras = await req.Spypoint.cameras()
res.send(cameras)
})
API
Promise.<string>
Spypoint.login() ⇒ Returns: Promise.<string>
- Bearer token used for authorization (this is automatically set and added to all requests)
Promise.<Array>
Spypoint.cameras() ⇒ Returns: Promise.<Array>
- List of all available cameraId
s
Promise.<Object>
Spypoint.filters() ⇒ Returns: Promise.<Object>
- Object containing a property .species
w/ list of all available filter tags
Promise.<Array>
Spypoint.mostRecentPhotosByCamera() ⇒ Returns: Promise.<Array>
- List of most recent photo taken from each camera
Promise.<Array>
Spypoint.photosByCamera(cameraId, [options]) ⇒ Returns: Promise.<Array>
- List of photos from an individual camera
Param | Type | Description |
---|---|---|
cameraId | string |
Unique identifier for the camera to request photos from |
[options] | Object |
Options object |
[options.tags] |
Array | string
|
Array of filter tag options or a single tag as a string |
[options.limit] | Number |
Maximum number of results to return |
Promise.<Array>
Spypoint.queryAllPhotos([options]) ⇒ Returns: Promise.<Array>
- List of photo by individual camera
Param | Type | Description |
---|---|---|
[options] | Object |
Options object |
[options.tags] |
Array | string
|
Array of filter tag options or a single tag as a string |
[options.limit] | Number |
Maximum number of results to return |