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
Size: 14
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A simple JavaScript client to the SmartSurvey REST API.
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 }
}
}
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'
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: {...}
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.
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.
options.page
- page to fetch (default 1)options.pageSize
- number of items per page (default 10)options.sortBy
- field(s) to sort bygetSurvey(surveyId, [options,] cb)
https://docs.smartsurvey.io/v1/reference#get-a-survey
Fetch a single survey.
options.detailed
- fetch more detailed survey datagetResponses(surveyId, [options,] cb)
https://docs.smartsurvey.io/v1/reference#get-responses
Fetch a page of responses.
options.completed
- 0=Partial, 1=Completed, 2=Both - Return completed responses or partialoptions.since
- return responses that completed no earlier than this dateoptions.until
- return responses that completed no later than this dateoptions.filterId
- enter the filter report ID you would like to use. Other filters will be ignoredoptions.trackingLinkId
- filter by tracking link idoptions.uniqueId
- filter the unique (x) valueoptions.includeLabels
- return text of page/question/choice labels, rather than indices onlyoptions.page
- page to fetch (default 1)options.pageSize
- number of items per page (default 10)options.sortBy
- field(s) to sort bygetResponse(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
getAll(get, [options,] cb)
get
- function that retrieves a page of contentoptions.pageSize
- size of pages that are retrieved (default 10)options.onPage
- called when each page of results is retrievede.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.