Search in sources :

Example 21 with RestParams

use of com.instructure.canvasapi2.builders.RestParams in project instructure-android by instructure.

the class UserManager_Test method getObserveesForParent.

public static void getObserveesForParent(String airwolfDomain, RestBuilder adapter, RestParams params, String parentId, StatusCallback<List<Student>> callback) {
    adapter.setStatusCallback(callback);
    Response response = new Response.Builder().code(200).message("success").protocol(Protocol.HTTP_1_0).body(ResponseBody.create(MediaType.parse("application/json"), "success".getBytes())).addHeader("content-type", "application/json").build();
    retrofit2.Response response1 = retrofit2.Response.success(response);
    callback.onResponse(response1, new LinkHeaders(), ApiType.API);
}
Also used : Response(okhttp3.Response) ParentResponse(com.instructure.canvasapi2.models.ParentResponse) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 22 with RestParams

use of com.instructure.canvasapi2.builders.RestParams in project instructure-android by instructure.

the class AlertThresholdManager method createAlertThreshold.

public static void createAlertThreshold(String airwolfDomain, String parentId, String studentId, String alertType, StatusCallback<AlertThreshold> callback) {
    if (isTesting() || mTesting) {
    // TODO:
    } else {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withShouldIgnoreToken(false).withPerPageQueryParam(false).withDomain(airwolfDomain).withAPIVersion("").build();
        AlertThresholdAPI.createAlertThreshold(airwolfDomain, adapter, params, parentId, studentId, alertType, callback);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 23 with RestParams

use of com.instructure.canvasapi2.builders.RestParams in project instructure-android by instructure.

the class AnnouncementManager method getAnnouncements.

/**
 * Get announcements for the given context codes and date range. Currently this only works for
 * courses. All non-course context codes will be ignored.
 * @param contextCodes List of context_codes to retrieve announcements for (for example,
 *                     course_123). Only courses are presently supported and all non-course
 *                     context codes will be ignored.
 * @param startDate Only return announcements posted since the start_date (inclusive). May be null,
 *                  defaults to 14 days ago. The value should be formatted as: yyyy-mm-dd
 *                  or ISO 8601 YYYY-MM-DDTHH:MM:SSZ.
 * @param endDate Only return announcements posted before the end_date (inclusive). May be null,
 *                defaults to 28 days from start_date. The value should be formatted as: yyyy-mm-dd
 *                or ISO 8601 YYYY-MM-DDTHH:MM:SSZ. Announcements scheduled for future posting
 *                will only be returned to course administrators.
 * @param forceNetwork Force network
 * @param callback StatusCallback
 */
public static void getAnnouncements(@NonNull List<String> contextCodes, String startDate, String endDate, boolean forceNetwork, @NonNull StatusCallback<List<DiscussionTopicHeader>> callback) {
    // Use only course context codes
    ArrayList<String> courseContextCodes = new ArrayList<>();
    for (String code : contextCodes) {
        if (code != null && code.startsWith("course")) {
            courseContextCodes.add(code);
        }
    }
    // noinspection PointlessBooleanExpression
    if (isTesting() || mTesting) {
        AnnouncementManager_Test.getAnnouncements(courseContextCodes, startDate, endDate, callback);
    } else {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).build();
        AnnouncementAPI.getAnnouncements(courseContextCodes, startDate, endDate, adapter, callback, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ArrayList(java.util.ArrayList) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 24 with RestParams

use of com.instructure.canvasapi2.builders.RestParams in project instructure-android by instructure.

the class AnnouncementManager method getAllAnnouncements.

public static void getAllAnnouncements(@NonNull CanvasContext canvasContext, boolean forceNetwork, StatusCallback<List<DiscussionTopicHeader>> callback) {
    if (isTesting() || mTesting) {
    // TODO:
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        final RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).build();
        StatusCallback<List<DiscussionTopicHeader>> depaginatedCallback = new ExhaustiveListCallback<DiscussionTopicHeader>(callback) {

            @Override
            public void getNextPage(@NotNull StatusCallback<List<DiscussionTopicHeader>> callback, @NotNull String nextUrl, boolean isCached) {
                AnnouncementAPI.getNextPage(nextUrl, adapter, callback, params);
            }
        };
        adapter.setStatusCallback(depaginatedCallback);
        AnnouncementAPI.getFirstPageAnnouncements(canvasContext, adapter, depaginatedCallback, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) List(java.util.List) ArrayList(java.util.ArrayList) StatusCallback(com.instructure.canvasapi2.StatusCallback) DiscussionTopicHeader(com.instructure.canvasapi2.models.DiscussionTopicHeader) ExhaustiveListCallback(com.instructure.canvasapi2.utils.ExhaustiveListCallback) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with RestParams

use of com.instructure.canvasapi2.builders.RestParams in project instructure-android by instructure.

the class AnnouncementManager method getAnnouncements.

public static void getAnnouncements(@NonNull CanvasContext canvasContext, boolean forceNetwork, StatusCallback<List<DiscussionTopicHeader>> callback) {
    if (isTesting() || mTesting) {
        AnnouncementManager_Test.getAnnouncements(canvasContext, callback);
    } else {
        RestBuilder adapter = new RestBuilder(callback);
        RestParams params = new RestParams.Builder().withPerPageQueryParam(true).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
        AnnouncementAPI.getAnnouncements(canvasContext, adapter, callback, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Aggregations

RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)276 RestParams (com.instructure.canvasapi2.builders.RestParams)264 List (java.util.List)33 StatusCallback (com.instructure.canvasapi2.StatusCallback)28 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)25 NonNull (android.support.annotation.NonNull)23 ArrayList (java.util.ArrayList)21 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)20 Response (okhttp3.Response)16 ParentResponse (com.instructure.canvasapi2.models.ParentResponse)10 Conversation (com.instructure.canvasapi2.models.Conversation)7 FileFolder (com.instructure.canvasapi2.models.FileFolder)7 UpdateFileFolder (com.instructure.canvasapi2.models.UpdateFileFolder)7 Group (com.instructure.canvasapi2.models.Group)6 NotNull (org.jetbrains.annotations.NotNull)5 DiscussionTopicHeader (com.instructure.canvasapi2.models.DiscussionTopicHeader)4 ApiType (com.instructure.canvasapi2.utils.ApiType)4 Nullable (android.support.annotation.Nullable)3 WorkerThread (android.support.annotation.WorkerThread)3 Course (com.instructure.canvasapi2.models.Course)3