2.1.3 • Published 3 years ago

spypoint-api-wrapper v2.1.3

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

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

ParamTypeDescription
cameraIdstringUnique identifier for the camera to request photos from
optionsObjectOptions object
options.tagsArray | stringArray of filter tag options or a single tag as a string
options.limitNumberMaximum number of results to return

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

Returns: Promise.<Array> - List of photo by individual camera

ParamTypeDescription
optionsObjectOptions object
options.tagsArray | stringArray of filter tag options or a single tag as a string
options.limitNumberMaximum number of results to return
2.1.2

3 years ago

2.1.1

3 years ago

2.1.3

3 years ago

6.14.17

3 years ago

2.1.0

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago