Ejemplo n.º 1
0
func RunShow(client amt.AmtClient, hitId, assnId string) {
	switch {
	case hitId != "":
		if resp, err := client.GetHIT(hitId); err != nil {
			fmt.Printf("Error: The AMT request failed: %v\n", err)
			return
		} else if len(resp.Hits) > 0 && resp.Hits[0].Request != nil &&
			resp.Hits[0].Request.Errors != nil {

			printObject(resp.Hits[0].Request)
		} else {
			printObject(resp)
		}

	case assnId != "":
		if resp, err := client.GetAssignment(assnId); err != nil {
			fmt.Printf("Error: The AMT request failed: %v\n", err)
			return
		} else if len(resp.GetAssignmentResults) > 0 &&
			resp.GetAssignmentResults[0].Request != nil &&
			resp.GetAssignmentResults[0].Request.Errors != nil {

			printObject(resp.GetAssignmentResults[0].Request)
		} else {
			printObject(resp)
		}

	default:
		fmt.Println("You must provide a value for either --hit or --assn")
	}
}
Ejemplo n.º 2
0
func RunExpire(client amt.AmtClient, hitId string, all bool) {
	if all {
		const maxHits = 100
		if resp, err := client.SearchHITs("CreationTime", false, maxHits, 1); err != nil {
			fmt.Printf("Error: The AMT request failed: %v\n", err)
			return
		} else if len(resp.SearchHITsResults) > 0 &&
			resp.SearchHITsResults[0].Request != nil &&
			resp.SearchHITsResults[0].Request.Errors != nil {

			printObject(resp.SearchHITsResults[0].Request)
		} else if len(resp.SearchHITsResults[0].Hits) == 0 {
			fmt.Println("Found no HITs for this account")
		} else {
			for _, hit := range resp.SearchHITsResults[0].Hits {
				if hit.HITStatus == "Assignable" {
					fmt.Printf("Expire HIT %q with %d available assignments\n",
						hit.HITId, hit.NumberOfAssignmentsAvailable)
					RunExpire(client, string(hit.HITId), false)
				}
			}
			if len(resp.SearchHITsResults[0].Hits) == maxHits {
				fmt.Println("Retrieved the maximum number of HITs. Repeat the command to find any remaining HITs.")
			}
		}
	} else if resp, err := client.ForceExpireHIT(hitId); err != nil {
		fmt.Printf("Error: Could not expire HIT - %v", err)
	} else {
		printObject(resp)
	}
}
Ejemplo n.º 3
0
func RunBalance(client amt.AmtClient) {
	balance, err := client.GetAccountBalance()
	if err != nil {
		fmt.Printf("Error: The AMT request failed: %v\n", err)
		return
	}
	printObject(balance)
}
Ejemplo n.º 4
0
func RunBonus(client amt.AmtClient, workerId, assnId string, amount float32,
	reason, token string) {
	resp, err := client.GrantBonus(workerId, assnId, amount, reason, token)
	if err != nil {
		fmt.Printf("Error: The AMT request failed: %v\n", err)
		return
	}
	printObject(resp)
}
Ejemplo n.º 5
0
func RunHits(client amt.AmtClient, sort string, desc bool, page, pageSize int) {
	if resp, err := client.SearchHITs(sort, !desc, pageSize, page); err != nil {
		fmt.Printf("Error: The AMT request failed: %v\n", err)
		return
	} else if len(resp.SearchHITsResults) > 0 &&
		resp.SearchHITsResults[0].Request != nil &&
		resp.SearchHITsResults[0].Request.Errors != nil {

		printObject(resp.SearchHITsResults[0].Request)
	} else if len(resp.SearchHITsResults[0].Hits) == 0 {
		fmt.Println("Found no HITs for this account")
	} else {
		for i, hit := range resp.SearchHITsResults[0].Hits {
			fmt.Printf("HIT %d/%d:\n", i+1, len(resp.SearchHITsResults))
			printObject(hit)
			fmt.Println()
		}
	}
}
Ejemplo n.º 6
0
func RunAssns(client amt.AmtClient, hitId string, statuses []string, sort string, desc bool, page, pageSize int) {
	if resp, err := client.GetAssignmentsForHIT(hitId, statuses, sort, !desc,
		pageSize, page); err != nil {

		fmt.Printf("Error: The AMT request failed: %v\n", err)
		return
	} else if len(resp.GetAssignmentsForHITResults) > 0 &&
		resp.GetAssignmentsForHITResults[0].Request != nil &&
		resp.GetAssignmentsForHITResults[0].Request.Errors != nil {

		printObject(resp.GetAssignmentsForHITResults[0].Request)
	} else if len(resp.GetAssignmentsForHITResults[0].Assignments) == 0 {
		fmt.Println("Found no assignments for this HIT")
	} else {
		for i, assn := range resp.GetAssignmentsForHITResults[0].Assignments {
			fmt.Printf("Assignment %d/%d:\n", i+1, len(resp.GetAssignmentsForHITResults))
			printObject(assn)
			fmt.Println()
		}
	}
}