spypoint-api-wrapper

2.1.3 • Public • Published

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

Spypoint.login() ⇒ Promise.<string>

Returns: Promise.<string> - Bearer token used for authorization (this is automatically set and added to all requests)

Spypoint.cameras() ⇒ Promise.<Array>

Returns: Promise.<Array> - List of all available cameraIds

Spypoint.filters() ⇒ Promise.<Object>

Returns: Promise.<Object> - Object containing a property .species w/ list of all available filter tags

Spypoint.mostRecentPhotosByCamera() ⇒ Promise.<Array>

Returns: Promise.<Array> - List of most recent photo taken from each camera

Spypoint.photosByCamera(cameraId, [options]) ⇒ Promise.<Array>

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

Spypoint.queryAllPhotos([options]) ⇒ Promise.<Array>

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

Package Sidebar

Install

npm i spypoint-api-wrapper

Weekly Downloads

3

Version

2.1.3

License

MIT

Unpacked Size

11.3 kB

Total Files

4

Last publish

Collaborators

  • coloradude