Beispiel #1
0
// CreateQualificationType creates a new Qualification type.
func (client amtClient) CreateQualificationType(name, description string,
	keywords []string, retryDelayInSeconds int,
	qualificationTypeStatus, test, answerKey string,
	testDurationInSeconds int, autoGranted bool,
	autoGrantedValue int) (amtgen.TxsdCreateQualificationTypeResponse, error) {

	// Prepare the request
	var (
		request  amtgen.TxsdCreateQualificationType
		args     amtgen.TCreateQualificationTypeRequest
		response amtgen.TxsdCreateQualificationTypeResponse
	)
	args.Name = xsdt.String(name)
	args.Description = xsdt.String(description)
	args.Keywords = xsdt.String(strings.Join(keywords, ","))
	args.RetryDelayInSeconds = xsdt.Long(retryDelayInSeconds)
	args.QualificationTypeStatus = amtgen.TQualificationTypeStatus(
		qualificationTypeStatus)
	args.Test = xsdt.String(test)
	args.AnswerKey = xsdt.String(answerKey)
	args.TestDurationInSeconds = xsdt.Long(testDurationInSeconds)
	args.AutoGranted = xsdt.Boolean(autoGranted)
	args.AutoGrantedValue = xsdt.Int(autoGrantedValue)
	request.Requests = append(request.Requests, &args)

	// Send the request
	req, err := client.signRequest("CreateQualificationType", &request)
	if err == nil {
		err = client.sendRequest(req, &response)
	}
	return response, err
}
Beispiel #2
0
// CreateHITFromHITTypeId creates a new Human Intelligence Task (HIT) from a
// HITTypeId.
func (client amtClient) CreateHITFromHITTypeId(hitTypeId, question string,
	hitLayoutId string, hitLayoutParameters map[string]string,
	lifetimeInSeconds, maxAssignments int,
	assignmentReviewPolicy, hitReviewPolicy *amtgen.TReviewPolicy,
	requesterAnnotation, uniqueRequestToken string) (
	amtgen.TxsdCreateHITResponse, error) {

	// Prepare the request
	var (
		args amtgen.TCreateHITRequest
	)
	args.HITTypeId = xsdt.String(hitTypeId)
	args.Question = xsdt.String(question)
	args.HITLayoutId = xsdt.String(hitLayoutId)
	var hitLayoutParameterOrder []string
	for name, _ := range hitLayoutParameters {
		hitLayoutParameterOrder = append(hitLayoutParameterOrder, name)
	}
	sort.Strings(hitLayoutParameterOrder)
	for _, name := range hitLayoutParameterOrder {
		value := hitLayoutParameters[name]
		var param amtgen.THITLayoutParameter
		param.Name = xsdt.String(name)
		param.Value = xsdt.String(value)
		args.HITLayoutParameters = append(args.HITLayoutParameters, &param)
	}
	args.LifetimeInSeconds = xsdt.Long(lifetimeInSeconds)
	args.MaxAssignments = xsdt.Int(maxAssignments)
	args.AssignmentReviewPolicy = assignmentReviewPolicy
	args.HITReviewPolicy = hitReviewPolicy
	args.RequesterAnnotation = xsdt.String(requesterAnnotation)
	args.UniqueRequestToken = xsdt.String(uniqueRequestToken)
	return client.CreateHITFromArgs(args)
}
Beispiel #3
0
func getObjectFields(object interface{}, vals map[string]string) {
	v := reflect.Indirect(reflect.ValueOf(object))
	if !v.IsValid() {
		return
	}
	t := v.Type()
	switch t.Kind() {
	case reflect.Slice:
		for i := 0; i < v.Len(); i++ {
			getObjectFields(v.Index(i).Interface(), vals)
		}
	case reflect.Struct:
		for i := 0; i < t.NumField(); i++ {
			field := t.Field(i)
			switch field.Type.Kind() {
			case reflect.Struct, reflect.Ptr, reflect.Slice:
				getObjectFields(v.Field(i).Interface(), vals)
			default:
				if field.Type == reflect.TypeOf(xsdt.Int(0)) {
					vals[field.Name] = fmt.Sprintf("%d", v.Field(i).Interface())
				} else if field.Type == reflect.TypeOf(xsdt.Long(0)) {
					vals[field.Name] = fmt.Sprintf("%d", v.Field(i).Interface())
				} else {
					vals[field.Name] = v.Field(i).String()
				}
			}
		}
	}
}
Beispiel #4
0
// CreateHIT creates a new Human Intelligence Task (HIT) without a HITTypeId.
func (client amtClient) CreateHIT(title, description, question string,
	hitLayoutId string, hitLayoutParameters map[string]string,
	reward float32, assignmentDurationInSeconds,
	lifetimeInSeconds, maxAssignments, autoApprovalDelayInSeconds int,
	keywords []string,
	qualificationRequirements []*amtgen.TQualificationRequirement,
	assignmentReviewPolicy, hitReviewPolicy *amtgen.TReviewPolicy,
	requesterAnnotation, uniqueRequestToken string) (
	amtgen.TxsdCreateHITResponse, error) {

	// Prepare the request
	var (
		args amtgen.TCreateHITRequest
	)
	args.Title = xsdt.String(title)
	args.Description = xsdt.String(description)
	args.Question = xsdt.String(question)
	args.HITLayoutId = xsdt.String(hitLayoutId)
	var hitLayoutParameterOrder []string
	for name, _ := range hitLayoutParameters {
		hitLayoutParameterOrder = append(hitLayoutParameterOrder, name)
	}
	sort.Strings(hitLayoutParameterOrder)
	for _, name := range hitLayoutParameterOrder {
		value := hitLayoutParameters[name]
		var param amtgen.THITLayoutParameter
		param.Name = xsdt.String(name)
		param.Value = xsdt.String(value)
		args.HITLayoutParameters = append(args.HITLayoutParameters, &param)
	}
	args.Reward = &amtgen.TPrice{}
	args.Reward.Amount = xsdt.Decimal(fmt.Sprint(reward))
	args.Reward.CurrencyCode = CURRENCY_USD
	args.AssignmentDurationInSeconds = xsdt.Long(assignmentDurationInSeconds)
	args.LifetimeInSeconds = xsdt.Long(lifetimeInSeconds)
	args.MaxAssignments = xsdt.Int(maxAssignments)
	args.AutoApprovalDelayInSeconds = xsdt.Long(autoApprovalDelayInSeconds)
	args.Keywords = xsdt.String(strings.Join(keywords, ","))
	args.QualificationRequirements = qualificationRequirements
	args.AssignmentReviewPolicy = assignmentReviewPolicy
	args.HITReviewPolicy = hitReviewPolicy
	args.RequesterAnnotation = xsdt.String(requesterAnnotation)
	args.UniqueRequestToken = xsdt.String(uniqueRequestToken)
	return client.CreateHITFromArgs(args)
}
Beispiel #5
0
// RegisterHITType creates a new HIT type.
func (client amtClient) RegisterHITType(title, description string,
	reward float32, assignmentDurationInSeconds, autoApprovalDelayInSeconds int,
	keywords []string,
	qualificationRequirements []*amtgen.TQualificationRequirement) (
	amtgen.TxsdRegisterHITTypeResponse, error) {

	// Prepare the request
	var (
		args amtgen.TRegisterHITTypeRequest
	)
	args.Title = xsdt.String(title)
	args.Description = xsdt.String(description)
	args.Reward = &amtgen.TPrice{}
	args.Reward.Amount = xsdt.Decimal(fmt.Sprint(reward))
	args.Reward.CurrencyCode = CURRENCY_USD
	args.AssignmentDurationInSeconds = xsdt.Long(assignmentDurationInSeconds)
	args.AutoApprovalDelayInSeconds = xsdt.Long(autoApprovalDelayInSeconds)
	args.Keywords = xsdt.String(strings.Join(keywords, ","))
	args.QualificationRequirements = qualificationRequirements

	return client.RegisterHITTypeFromArgs(args)
}
Beispiel #6
0
// ExtendHIT increases the maximum number of assignments, or extends the
// expiration date, of an existing HIT.
func (client amtClient) ExtendHIT(hitId string,
	maxAssignmentsIncrement, expirationIncrementInSeconds int,
	uniqueRequestToken string) (
	amtgen.TxsdExtendHITResponse, error) {

	// Prepare the request
	var (
		request  amtgen.TxsdExtendHIT
		args     amtgen.TExtendHITRequest
		response amtgen.TxsdExtendHITResponse
	)
	args.HITId = xsdt.String(hitId)
	args.MaxAssignmentsIncrement = xsdt.Int(maxAssignmentsIncrement)
	args.ExpirationIncrementInSeconds = xsdt.Long(expirationIncrementInSeconds)
	args.UniqueRequestToken = xsdt.String(uniqueRequestToken)
	request.Requests = append(request.Requests, &args)

	// Send the request
	req, err := client.signRequest("ExtendHIT", &request)
	if err == nil {
		err = client.sendRequest(req, &response)
	}
	return response, err
}