@smarterservices/sp-public-client
Advanced tools
Comparing version 0.0.3 to 0.0.5
1391
index.js
@@ -24,3 +24,3 @@ /*jshint -W069 */ | ||
/** | ||
* | ||
* Used to make sure that the api is current only | ||
* @method | ||
@@ -96,3 +96,1392 @@ * @name Client#health | ||
}; | ||
/** | ||
* Will return a full list of all institutions | ||
* @method | ||
* @name Client#listInstitutions | ||
* | ||
*/ | ||
Client.prototype.listInstitutions = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/institutions'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* Get all the incident types | ||
* @method | ||
* @name Client#getIncidentTypes | ||
* | ||
*/ | ||
Client.prototype.getIncidentTypes = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/incidents/types'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* Will return detailed information about an institution | ||
* @method | ||
* @name Client#getInstitution | ||
* @param {string} institution_id - | ||
* | ||
*/ | ||
Client.prototype.getInstitution = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/institutions/{institution_id}'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{institution_id}', parameters['institution_id']); | ||
if (parameters['institution_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: institution_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* List all exams for a course | ||
* @method | ||
* @name Client#listExams | ||
* @param {string} course_id - | ||
* | ||
*/ | ||
Client.prototype.listExams = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/courses/{course_id}/exams'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{course_id}', parameters['course_id']); | ||
if (parameters['course_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: course_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* List all instructors for a course | ||
* @method | ||
* @name Client#listInstructors | ||
* @param {string} course_id - | ||
* | ||
*/ | ||
Client.prototype.listInstructors = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/courses/{course_id}/instructors'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{course_id}', parameters['course_id']); | ||
if (parameters['course_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: course_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* List students for a given exam | ||
* @method | ||
* @name Client#listStudents | ||
* @param {string} exam_id - | ||
* | ||
*/ | ||
Client.prototype.listStudents = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/exams/{exam_id}/students'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{exam_id}', parameters['exam_id']); | ||
if (parameters['exam_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: exam_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* List sessions for a given exam | ||
* @method | ||
* @name Client#listSessions | ||
* @param {string} exam_id - | ||
* | ||
*/ | ||
Client.prototype.listSessions = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/exams/{exam_id}/sessions'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{exam_id}', parameters['exam_id']); | ||
if (parameters['exam_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: exam_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* Will return return a list of courses for an institution | ||
* @method | ||
* @name Client#listCourses | ||
* @param {string} institution_id - | ||
* | ||
*/ | ||
Client.prototype.listCourses = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/institutions/{institution_id}/courses'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{institution_id}', parameters['institution_id']); | ||
if (parameters['institution_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: institution_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* List incidents for a given session | ||
* @method | ||
* @name Client#listIncidents | ||
* @param {string} session_id - | ||
* | ||
*/ | ||
Client.prototype.listIncidents = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/sessions/{session_id}/incidents'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{session_id}', parameters['session_id']); | ||
if (parameters['session_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: session_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* Creates an incident for a given session | ||
* @method | ||
* @name Client#createIncident | ||
* @param {string} session_id - | ||
* @param {} body - | ||
* | ||
*/ | ||
Client.prototype.createIncident = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/sessions/{session_id}/incidents'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{session_id}', parameters['session_id']); | ||
if (parameters['session_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: session_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters['body'] !== undefined) { | ||
body = parameters['body']; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'POST', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* Get exam details | ||
* @method | ||
* @name Client#getExam | ||
* @param {string} course_id - | ||
* @param {string} exam_id - | ||
* | ||
*/ | ||
Client.prototype.getExam = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/courses/{course_id}/exams/{exam_id}'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{course_id}', parameters['course_id']); | ||
if (parameters['course_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: course_id')); | ||
return deferred.promise; | ||
} | ||
path = path.replace('{exam_id}', parameters['exam_id']); | ||
if (parameters['exam_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: exam_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* Get instructor details | ||
* @method | ||
* @name Client#getInstructor | ||
* @param {string} course_id - | ||
* @param {string} instructor_id - | ||
* | ||
*/ | ||
Client.prototype.getInstructor = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/courses/{course_id}/instructors/{instructor_id}'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{course_id}', parameters['course_id']); | ||
if (parameters['course_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: course_id')); | ||
return deferred.promise; | ||
} | ||
path = path.replace('{instructor_id}', parameters['instructor_id']); | ||
if (parameters['instructor_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: instructor_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* Get session details for a given exam | ||
* @method | ||
* @name Client#getSession | ||
* @param {string} exam_id - | ||
* @param {string} session_id - | ||
* | ||
*/ | ||
Client.prototype.getSession = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/exams/{exam_id}/sessions/{session_id}'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{exam_id}', parameters['exam_id']); | ||
if (parameters['exam_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: exam_id')); | ||
return deferred.promise; | ||
} | ||
path = path.replace('{session_id}', parameters['session_id']); | ||
if (parameters['session_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: session_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* Get student details for a given exam | ||
* @method | ||
* @name Client#getStudent | ||
* @param {string} exam_id - | ||
* @param {string} student_id - | ||
* | ||
*/ | ||
Client.prototype.getStudent = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/exams/{exam_id}/students/{student_id}'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{exam_id}', parameters['exam_id']); | ||
if (parameters['exam_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: exam_id')); | ||
return deferred.promise; | ||
} | ||
path = path.replace('{student_id}', parameters['student_id']); | ||
if (parameters['student_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: student_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* Will return return details about a single course | ||
* @method | ||
* @name Client#getCourse | ||
* @param {string} course_id - | ||
* @param {string} institution_id - | ||
* | ||
*/ | ||
Client.prototype.getCourse = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/institutions/{institution_id}/courses/{course_id}'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{course_id}', parameters['course_id']); | ||
if (parameters['course_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: course_id')); | ||
return deferred.promise; | ||
} | ||
path = path.replace('{institution_id}', parameters['institution_id']); | ||
if (parameters['institution_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: institution_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'GET', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* Proxys login request to Auth server | ||
* @method | ||
* @name Client#login | ||
* | ||
*/ | ||
Client.prototype.login = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/login'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'POST', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
/** | ||
* Cancel session for a given exam | ||
* @method | ||
* @name Client#cancelSession | ||
* @param {string} exam_id - | ||
* @param {string} session_id - | ||
* | ||
*/ | ||
Client.prototype.cancelSession = function(parameters) { | ||
if (parameters === undefined) { | ||
parameters = {}; | ||
} | ||
var deferred = Q.defer(); | ||
var domain = this.domain; | ||
var path = '/v1/exams/{exam_id}/sessions/{session_id}/cancel'; | ||
var body; | ||
var queryParameters = {}; | ||
var headers = {}; | ||
var form = {}; | ||
path = path.replace('{exam_id}', parameters['exam_id']); | ||
if (parameters['exam_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: exam_id')); | ||
return deferred.promise; | ||
} | ||
path = path.replace('{session_id}', parameters['session_id']); | ||
if (parameters['session_id'] === undefined) { | ||
deferred.reject(new Error('Missing required parameter: session_id')); | ||
return deferred.promise; | ||
} | ||
if (parameters.$queryParameters) { | ||
Object.keys(parameters.$queryParameters) | ||
.forEach(function(parameterName) { | ||
var parameter = parameters.$queryParameters[parameterName]; | ||
queryParameters[parameterName] = parameter; | ||
}); | ||
} | ||
var req = { | ||
method: 'POST', | ||
uri: domain + path, | ||
qs: queryParameters, | ||
headers: headers, | ||
body: body | ||
}; | ||
if (Object.keys(form).length > 0) { | ||
req.form = form; | ||
} | ||
if (typeof(body) === 'object' && !(body instanceof Buffer)) { | ||
req.json = true; | ||
} | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject(error); | ||
} else { | ||
if (/^application\/(.*\\+)?json/.test(response.headers['content-type'])) { | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
} | ||
} | ||
if (response.statusCode === 204) { | ||
deferred.resolve({ | ||
response: response | ||
}); | ||
} else if (response.statusCode >= 200 && response.statusCode <= 299) { | ||
deferred.resolve({ | ||
response: response, | ||
body: body | ||
}); | ||
} else { | ||
deferred.reject({ | ||
response: response, | ||
body: body | ||
}); | ||
} | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
return Client; | ||
@@ -99,0 +1488,0 @@ })(); |
@@ -1,1 +0,1 @@ | ||
{"name":"@smarterservices/sp-public-client","version":"0.0.3","description":"the middle layer to microservice architecture for SP that handles tasks like proxying to backend api's,formatting responces,checking permissions","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":"jordan piepkow","license":null} | ||
{"name":"@smarterservices/sp-public-client","version":"0.0.5","description":"the middle layer to microservice architecture for SP that handles tasks like proxying to backend api's,formatting responces,checking permissions","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":"jordan piepkow","license":null} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46648
1333
1