Skip to content

Commit

Permalink
Update Moodle endpoint to get courses
Browse files Browse the repository at this point in the history
  • Loading branch information
therealsujitk committed Sep 6, 2023
1 parent 18a5d81 commit 861aa89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void onError(@NonNull Throwable e) {
* Function to get a list of course ids
*/
private void getCourses() {
this.moodleApi.getCourses(this.moodleToken)
this.moodleApi.getCourses(this.moodleToken, this.moodleUserId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new SingleObserver<ResponseBody>() {
Expand All @@ -120,10 +120,14 @@ public void onSubscribe(@NonNull Disposable d) {
@Override
public void onSuccess(@NonNull ResponseBody responseBody) {
try {
JSONObject response = new JSONObject(responseBody.string());
throwErrorIfExists(response);
String response = responseBody.string();

if (response.startsWith("{")) {
throwErrorIfExists(new JSONObject(response));
throw new Exception("Unknown Error.");
}

JSONArray courses = response.getJSONArray("courses");
JSONArray courses = new JSONArray(response);
List<Integer> courseIds = new ArrayList<>();

for (int i = 0; i < courses.length(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Single<ResponseBody> signIn(@Query("username") String username,
Single<ResponseBody> getUserId(@Query("wstoken") String moodleToken);

@GET(SettingsRepository.MOODLE_WEBSERVICE_PATH +
"?wsfunction=core_course_get_enrolled_courses_by_timeline_classification" +
"&classification=inprogress" +
"?wsfunction=core_enrol_get_users_courses" +
"&moodlewsrestformat=json")
Single<ResponseBody> getCourses(@Query("wstoken") String moodleToken);
Single<ResponseBody> getCourses(@Query("wstoken") String moodleToken,
@Query("userid") int userId);

@GET(SettingsRepository.MOODLE_WEBSERVICE_PATH +
"?wsfunction=mod_assign_get_assignments" +
Expand Down

0 comments on commit 861aa89

Please sign in to comment.