tableflip/smartsurvey-client

Name: smartsurvey-client

Owner: TABLEFLIP

Description: A simple JavaScript client to the SmartSurvey REST API

Created: 2017-03-07 08:20:40.0

Updated: 2017-03-07 08:22:47.0

Pushed: 2017-06-28 09:10:45.0

Homepage:

Size: 14

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

smartsurvey-client

A simple JavaScript client to the SmartSurvey REST API.

Example
SmartSurveyClient = require('smartsurvey-client')
client = new SmartSurveyClient({ apiToken: 'TOKEN', apiTokenSecret: 'SECRET' })

nt.getSurveys({ page: 1, pageSize: 25 }, function (err, result) {
 (err) throw err
nsole.log(result)
 result:
 {
   data: [],
   meta: {
     pagination: { page: 1, pageSize: 25, returned: 25, total: 31 }
   }
 }

Errors

Non HTTP 200 responses to API calls will be returned as an error. If the API provides it, the error message will have a status, message and code property. If not, status will be set to the status code from the request and message will be a generic error message.

estError {
atus: 404,
ssage: "Survey with id '123' could not be found.",
de: 'not_found'

Callbacks

Callback results to API methods have a standard structure. They are objects with a data property (the data returned by the API - an array or an object), a meta property (metadata included in the HTTP headers) and a raw response property.

lt {
ta: [...],
ta: {
pagination: { page: 1, pageSize: 25, returned: 25, total: 31 }
release: '1.1.0.29',
server: 'Web1'

sponse: {...}

Conventions

Request params are named as per the params documented in the SmartSurvey API docs, however they are renamed from snake_case to camelCase.

All requests take apiToken and apiTokenSecret params, but they can be optionally passed to the constructor where they will automatically be added to each request.

API

This module is work in progress.

The following API calls have been implemented:

getSurveys([options,] cb)

https://docs.smartsurvey.io/v1/reference#surveys

Fetch a page of surveys.

getSurvey(surveyId, [options,] cb)

https://docs.smartsurvey.io/v1/reference#get-a-survey

Fetch a single survey.

getResponses(surveyId, [options,] cb)

https://docs.smartsurvey.io/v1/reference#get-responses

Fetch a page of responses.

getResponse(surveyId, responseId, [options,] cb)

https://docs.smartsurvey.io/v1/reference#get-a-response

Fetch a single response.

getFolder(folderId, [options,] cb)

https://docs.smartsurvey.io/v1/reference#get-a-response

Fetch a details on a folder (a way that surveys are collected).

https://docs.smartsurvey.io/v1/reference#surveyfoldersfolder_iddetailed

Utility
getAll(get, [options,] cb)

e.g.

SmartSurveyClient = require('smartsurvey-client')
getAll = require('smartsurvey-client/get-all')
client = new SmartSurveyClient({ apiToken: 'TOKEN', apiTokenSecret: 'SECRET' })

etrieve a page of surveys
tion getPageOfSurveys (page, pageSize, cb) {
 Merge page and pageSize with your request options
ient.getSurveys({ page: page, pageSize: pageSize }, cb)


ptional callback for each page
tion onPage (result) {
nsole.log('Got page number', result.meta.pagination.page)


tart fetch all the pages!
ll(getPageOfSurveys, { pageSize: 10, onPage: onPage }, function (err, result) {
nsole.log(result.data) // All surveys


A (?°?°???TABLEFLIP side project.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.