Commit 15b602c

Richard Luby <richluby@gmail.com>
2016-11-08 12:36:24
client can submit blueprint to server
client uses query string in get request to submit list of desired categories to server, separated by a hyphen
1 parent df2890d
Changed files (1)
command.go
@@ -151,9 +151,17 @@ func postRecordsToServer(client *http.Client, recordArray *ClientTest) error {
 
 // getRecordFromServer retrieves a record from the server
 func getRecordFromServer(client *http.Client, config CLIENT_CONFIG,
-	numQuestions int, useBlueprint bool) ([]ClientRecord, error) {
+	numQuestions int, blueprint string) ([]ClientRecord, error) {
 	// allows adding configuration for port specific (ie HTTPS) requests
-	resp, err := client.Get(clientConfig.SERVER_URL + API_ROOT + "/test" + "?questions=" + strconv.Itoa(numQuestions))
+	var resp *http.Response
+	var err error
+	var request *http.Request
+	serverUrl := clientConfig.SERVER_URL + API_ROOT + "/test" + "?questions=" + strconv.Itoa(numQuestions)
+	if blueprint != "" {
+		serverUrl = serverUrl + "&blueprint=" + blueprint
+	}
+	request, err = http.NewRequest("GET", serverUrl, nil)
+	resp, err = client.Do(request)
 	if err != nil {
 		return nil, err
 	}
@@ -239,14 +247,19 @@ func executeTest(command Command) error {
 	if err != nil {
 		return fmt.Errorf("Error while parsing flags for test: %+v", err)
 	}
-	clientTest.Records, err = getRecordFromServer(client, clientConfig, questions, useBluprint)
+	if err = getCategoriesFromServer(Command{}); err != nil {
+		return fmt.Errorf("Error while pulling server categories: %+v", err)
+	}
+	blueprint, err := buildBluePrint(useBluprint)
+	if err != nil {
+		return fmt.Errorf("Error while creating blueprint: %+v", err)
+	}
+	clientTest.Records, err = getRecordFromServer(client, clientConfig, questions, blueprint)
 	if err != nil {
 		return fmt.Errorf("Error while requesting test from server: %+v", err)
 	}
 	clientTest.Username = clientConfig.USER
-	if err = getCategoriesFromServer(Command{}); err != nil {
-		return fmt.Errorf("Error while pulling server categories: %+v", err)
-	}
+
 	runTest(&clientTest)
 	fmt.Printf("You scored: %.2f%%.\n", clientTest.Score)
 	return postRecordsToServer(client, &clientTest)