Skip to content

Commit e585871

Browse files
authored
[CSL-2207] Quizzes - Update finalize to results (#115)
* Update finalize to results * Lint * Add quiz_session_id, quiz_version_id changes * Update test resources * update resource * Update tests * Update comments * lint comments * Address comemnts * lint * Update comments * Add result sources, address comments * Result sources test
1 parent 4683366 commit e585871

21 files changed

+1594
-323
lines changed

constructorio-client/src/main/java/io/constructor/client/ConstructorIO.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,25 +2524,35 @@ public String allRedirectsAsJson(AllRedirectsRequest req) throws ConstructorExce
25242524
* Creates a Quiz OkHttp request
25252525
*
25262526
* @param req the Quiz request
2527-
* @param type the type of quiz request (next/finalize)
2527+
* @param type the type of quiz request (next/results)
25282528
* @return a Task OkHttp request
25292529
* @throws ConstructorException
25302530
*/
25312531
protected Request createQuizRequest(QuizRequest req, String type, UserInfo userInfo)
25322532
throws ConstructorException {
25332533
try {
2534-
if (!type.equals("next") && !type.equals("finalize"))
2535-
throw new IllegalArgumentException("type must be either 'next' or 'finalize'");
2534+
if (!type.equals("next") && !type.equals("results"))
2535+
throw new IllegalArgumentException("type must be either 'next' or 'results'");
25362536

2537-
List<String> paths = Arrays.asList("v1", "quizzes", req.getId(), type);
2537+
List<String> paths = Arrays.asList("v1", "quizzes", req.getQuizId(), type);
25382538
HttpUrl url = this.makeUrl(paths);
25392539

25402540
if (req.getSection() != null) {
25412541
url = url.newBuilder().addQueryParameter("section", req.getSection()).build();
25422542
}
25432543

2544-
if (req.getVersionId() != null) {
2545-
url = url.newBuilder().addQueryParameter("version_id", req.getVersionId()).build();
2544+
if (req.getQuizVersionId() != null) {
2545+
url =
2546+
url.newBuilder()
2547+
.addQueryParameter("quiz_version_id", req.getQuizVersionId())
2548+
.build();
2549+
}
2550+
2551+
if (req.getQuizSessionId() != null) {
2552+
url =
2553+
url.newBuilder()
2554+
.addQueryParameter("quiz_session_id", req.getQuizSessionId())
2555+
.build();
25462556
}
25472557

25482558
if (req.getAnswers().size() > 0) {
@@ -2551,9 +2561,9 @@ protected Request createQuizRequest(QuizRequest req, String type, UserInfo userI
25512561
url = url.newBuilder().addQueryParameter("a", answerParam).build();
25522562
}
25532563
} else {
2554-
if (type.equals("finalize")) {
2564+
if (type.equals("results")) {
25552565
throw new IllegalArgumentException(
2556-
"answers is a required parameter for a finalize request");
2566+
"answers is a required parameter for a results request");
25572567
}
25582568
}
25592569

@@ -2612,7 +2622,7 @@ public String quizNextQuestionAsJson(QuizRequest req, UserInfo userInfo)
26122622
public QuizResultsResponse quizResults(QuizRequest req, UserInfo userInfo)
26132623
throws ConstructorException {
26142624
try {
2615-
Request request = createQuizRequest(req, "finalize", userInfo);
2625+
Request request = createQuizRequest(req, "results", userInfo);
26162626
Response response = clientWithRetry.newCall(request).execute();
26172627
String json = getResponseBody(response);
26182628
return createQuizResultsResponse(json);
@@ -2631,7 +2641,7 @@ public QuizResultsResponse quizResults(QuizRequest req, UserInfo userInfo)
26312641
public String quizResultsAsJson(QuizRequest req, UserInfo userInfo)
26322642
throws ConstructorException {
26332643
try {
2634-
Request request = createQuizRequest(req, "finalize", userInfo);
2644+
Request request = createQuizRequest(req, "results", userInfo);
26352645
Response response = clientWithRetry.newCall(request).execute();
26362646
return getResponseBody(response);
26372647
} catch (Exception exception) {

constructorio-client/src/main/java/io/constructor/client/QuizRequest.java

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,43 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
/** Constructor.io Next Quiz and Finalize Quiz request */
6+
/** Constructor.io Next Quiz and Results Quiz request */
77
public class QuizRequest {
8-
private String id;
8+
private String quizId;
99
private String indexKey;
1010
private String section;
1111
private List<List<String>> answers;
12-
private String versionId;
12+
private String quizVersionId;
13+
private String quizSessionId;
1314

1415
/**
15-
* Creates a Next Quiz/Finalize Quiz request
16+
* Creates a Next Quiz/Results Quiz request
1617
*
17-
* @param id the id of the quiz to request
18+
* @param quizId the id of the quiz to request
1819
*/
19-
public QuizRequest(String id) {
20-
if (id == null)
20+
public QuizRequest(String quizId) {
21+
if (quizId == null)
2122
throw new IllegalArgumentException("id is a required parameter of type String");
2223

23-
this.id = id;
24+
this.quizId = quizId;
2425
this.section = null;
2526
this.answers = new ArrayList<>();
26-
this.versionId = null;
27+
this.quizVersionId = null;
28+
this.quizSessionId = null;
2729
}
2830

2931
/**
30-
* @param id the id of the quiz to request
32+
* @param quizId the id of the quiz to request
3133
*/
32-
public void setId(String id) {
33-
this.id = id;
34+
public void setQuizId(String quizId) {
35+
this.quizId = quizId;
3436
}
3537

3638
/**
3739
* @return the id of the quiz to request
3840
*/
39-
public String getId() {
40-
return id;
41+
public String getQuizId() {
42+
return quizId;
4143
}
4244

4345
/**
@@ -71,16 +73,38 @@ public List<List<String>> getAnswers() {
7173
}
7274

7375
/**
74-
* @param versionId the specific version id for the quiz
76+
* @param quizVersionId The quiz version id will be returned with the first request and it
77+
* should be passed with subsequent requests. More information can be found:
78+
* https://docs.constructor.io/rest_api/quiz/using_quizzes/#quiz-versioning
7579
*/
76-
public void setVersionId(String versionId) {
77-
this.versionId = versionId;
80+
public void setQuizVersionId(String quizVersionId) {
81+
this.quizVersionId = quizVersionId;
7882
}
7983

8084
/**
81-
* @return the specific version id for the quiz
85+
* @return the quizVersionId. The quiz version id will be returned with the first request and it
86+
* should be passed with subsequent requests. More information can be found:
87+
* https://docs.constructor.io/rest_api/quiz/using_quizzes/#quiz-versioning
8288
*/
83-
public String getVersionId() {
84-
return versionId;
89+
public String getQuizVersionId() {
90+
return quizVersionId;
91+
}
92+
93+
/**
94+
* @param quizSessionId The quiz session id will be returned with the first request, and it
95+
* should be passed with subsequent requests. More information can be found:
96+
* https://docs.constructor.io/rest_api/quiz/using_quizzes/#quiz-sessions
97+
*/
98+
public void setQuizSessionId(String quizSessionId) {
99+
this.quizSessionId = quizSessionId;
100+
}
101+
102+
/**
103+
* @return the quizSessionId. The quiz session id will be returned with the first request and it
104+
* should be passed with subsequent requests. More information can be found:
105+
* https://docs.constructor.io/rest_api/quiz/using_quizzes/#quiz-sessions
106+
*/
107+
public String getQuizSessionId() {
108+
return quizSessionId;
85109
}
86110
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package io.constructor.client.models;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import java.util.List;
5+
6+
/** Constructor.io Base Result ... uses Gson/Reflection to load data in */
7+
public class BaseResultsResponse {
8+
9+
@SerializedName("facets")
10+
private List<FilterFacet> facets;
11+
12+
@SerializedName("groups")
13+
private List<FilterGroup> groups;
14+
15+
@SerializedName("results")
16+
private List<Result> results;
17+
18+
@SerializedName("total_num_results")
19+
private Integer totalNumberOfResults;
20+
21+
@SerializedName("sort_options")
22+
private List<FilterSortOption> sortOptions;
23+
24+
@SerializedName("result_sources")
25+
private ResultSources resultSources;
26+
27+
/**
28+
* @return the facets
29+
*/
30+
public List<FilterFacet> getFacets() {
31+
return facets;
32+
}
33+
34+
/**
35+
* @return the groups
36+
*/
37+
public List<FilterGroup> getGroups() {
38+
return groups;
39+
}
40+
41+
/**
42+
* @return the results
43+
*/
44+
public List<Result> getResults() {
45+
return results;
46+
}
47+
48+
/**
49+
* @return the totalNumberOfResults
50+
*/
51+
public Integer getTotalNumberOfResults() {
52+
return totalNumberOfResults;
53+
}
54+
55+
/**
56+
* @return the sort options
57+
*/
58+
public List<FilterSortOption> getSortOptions() {
59+
return sortOptions;
60+
}
61+
62+
/**
63+
* @return resultSources data
64+
*/
65+
public ResultSources getResultSources() {
66+
return resultSources;
67+
}
68+
69+
public void setFacets(List<FilterFacet> facets) {
70+
this.facets = facets;
71+
}
72+
73+
public void setGroups(List<FilterGroup> groups) {
74+
this.groups = groups;
75+
}
76+
77+
public void setResults(List<Result> results) {
78+
this.results = results;
79+
}
80+
81+
public void setTotalNumberOfResults(Integer totalNumberOfResults) {
82+
this.totalNumberOfResults = totalNumberOfResults;
83+
}
84+
85+
public void setSortOptions(List<FilterSortOption> sortOptions) {
86+
this.sortOptions = sortOptions;
87+
}
88+
89+
public void setResultSources(ResultSources resultSources) {
90+
this.resultSources = resultSources;
91+
}
92+
}

constructorio-client/src/main/java/io/constructor/client/models/BrowseResponseInner.java

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,20 @@
11
package io.constructor.client.models;
22

33
import com.google.gson.annotations.SerializedName;
4-
import java.util.List;
54

65
/** Constructor.io Browse Response Inner ... uses Gson/Reflection to load data in */
7-
public class BrowseResponseInner {
8-
9-
@SerializedName("facets")
10-
List<FilterFacet> facets;
11-
12-
@SerializedName("groups")
13-
private List<FilterGroup> groups;
14-
15-
@SerializedName("results")
16-
private List<Result> results;
17-
18-
@SerializedName("total_num_results")
19-
private Integer totalNumberOfResults;
20-
21-
@SerializedName("sort_options")
22-
private List<FilterSortOption> sortOptions;
6+
public class BrowseResponseInner extends BaseResultsResponse {
237

248
@SerializedName("collection")
259
private ItemCollection collection;
2610

27-
/**
28-
* @return the facets
29-
*/
30-
public List<FilterFacet> getFacets() {
31-
return facets;
32-
}
33-
34-
/**
35-
* @return the groups
36-
*/
37-
public List<FilterGroup> getGroups() {
38-
return groups;
39-
}
40-
41-
/**
42-
* @return the results
43-
*/
44-
public List<Result> getResults() {
45-
return results;
46-
}
47-
48-
/**
49-
* @return the totalNumberOfResults
50-
*/
51-
public Integer getTotalNumberOfResults() {
52-
return totalNumberOfResults;
53-
}
54-
55-
/**
56-
* @return the sort options
57-
*/
58-
public List<FilterSortOption> getSortOptions() {
59-
return sortOptions;
60-
}
61-
6211
/**
6312
* @return the item collection data
6413
*/
6514
public ItemCollection getCollection() {
6615
return collection;
6716
}
6817

69-
public void setFacets(List<FilterFacet> facets) {
70-
this.facets = facets;
71-
}
72-
73-
public void setGroups(List<FilterGroup> groups) {
74-
this.groups = groups;
75-
}
76-
77-
public void setResults(List<Result> results) {
78-
this.results = results;
79-
}
80-
81-
public void setTotalNumberOfResults(Integer totalNumberOfResults) {
82-
this.totalNumberOfResults = totalNumberOfResults;
83-
}
84-
85-
public void setSortOptions(List<FilterSortOption> sortOptions) {
86-
this.sortOptions = sortOptions;
87-
}
88-
8918
public void setCollection(ItemCollection collection) {
9019
this.collection = collection;
9120
}

0 commit comments

Comments
 (0)