forked from jeffcrouse/mturk
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sunsetmtn84/master
added qualification type and assign qual type to workers
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var xml = require('../lib/xml-native') | ||
EventEmitter = require('events').EventEmitter; | ||
|
||
module.exports = function(config) { | ||
var request = require('../lib/request')(config) | ||
, inherits = require('util').inherits | ||
, Base = require('./base') | ||
, ret; | ||
|
||
function QualWorker() { | ||
} | ||
|
||
|
||
inherits(QualWorker, Base); | ||
|
||
ret = QualWorker; | ||
|
||
/* | ||
* Create a Qualification Type | ||
*/ | ||
ret.createQualification = function(qualtypename, qualtypedescription, callback){ | ||
var options = { | ||
Name: qualtypename | ||
, Description: qualtypedescription, | ||
QualificationTypeStatus: 'Active' | ||
}; | ||
request('AWSMechanicalTurkRequester', 'CreateQualificationType', 'POST', options, function(err, response) { | ||
if (err) { return callback(err); } | ||
if (! Assignment.prototype.nodeExists(['CreateQualificationTypeResponse', 'QualificationType','Request', 'IsValid'], response)) { callback([new Error('No "CreateQualificationTypeResponse > QualificationType > Request > IsValid" node on the response')]); return; } | ||
if (response.CreateQualificationTypeResponse.QualificationType.Request.IsValid.toLowerCase() != 'true') { | ||
return callback([new Error('Response says ApproveAssignmentResult request is invalid: ' + JSON.stringify(response.ApproveAssignmentResult.Request.Errors))]); | ||
} | ||
callback(null); | ||
}); | ||
}; | ||
|
||
/* | ||
* Assign Qualification to worker | ||
*/ | ||
ret.assignQualToWorker = function(qualtypeid, workerid, integervalue, callback){ | ||
var options = { | ||
QualificationTypeId: qualtypeid | ||
, WorkerId: workerid, | ||
IntegerValue: integervalue | ||
}; | ||
request('AWSMechanicalTurkRequester', 'AssignQualification', 'POST', options, function(err, response) { | ||
if (err) { return callback(err); } | ||
if (! Assignment.prototype.nodeExists(['AssignQualificationResult', 'Request', 'IsValid'], response)) { callback([new Error('No "AssignQualificationResult > Request > IsValid" node on the response')]); return; } | ||
if (response.AssignQualificationResult.Request.IsValid.toLowerCase() != 'true') { | ||
return callback([new Error('Response says AssignQualificationResult request is invalid: ' + JSON.stringify(response.ApproveAssignmentResult.Request.Errors))]); | ||
} | ||
callback(null); | ||
}); | ||
}; | ||
|
||
}; |