Search in sources :

Example 76 with RestParams

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

the class FileFolderManager method deleteFolder.

public static void deleteFolder(long folderId, final StatusCallback<FileFolder> callback) {
    if (isTesting() || mTesting) {
    // TODO
    } else {
        final RestBuilder adapter = new RestBuilder(callback);
        final RestParams params = new RestParams.Builder().build();
        FileFolderAPI.deleteFolder(folderId, adapter, callback, params);
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 77 with RestParams

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

the class GroupCategoriesManager method getAllGroupsForCategory.

public static void getAllGroupsForCategory(long categoryId, StatusCallback<List<Group>> callback, boolean forceNetwork) {
    if (isTesting() || mTesting) {
    // TODO
    } else {
        final RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).withShouldIgnoreToken(false).build();
        final RestBuilder adapter = new RestBuilder(callback);
        StatusCallback<List<Group>> depaginatedCallback = new ExhaustiveListCallback<Group>(callback) {

            @Override
            public void getNextPage(@NonNull StatusCallback<List<Group>> callback, @NonNull String nextUrl, boolean isCached) {
                GroupCategoriesAPI.getNextPageGroups(nextUrl, adapter, callback, params);
            }
        };
        adapter.setStatusCallback(depaginatedCallback);
        GroupCategoriesAPI.getFirstPageGroupsInCategory(categoryId, adapter, depaginatedCallback, params);
    }
}
Also used : Group(com.instructure.canvasapi2.models.Group) RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) NonNull(android.support.annotation.NonNull) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) List(java.util.List) StatusCallback(com.instructure.canvasapi2.StatusCallback) ExhaustiveListCallback(com.instructure.canvasapi2.utils.ExhaustiveListCallback)

Example 78 with RestParams

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

the class GroupManager method getFavoriteGroups.

public static void getFavoriteGroups(StatusCallback<List<Group>> callback, boolean forceNetwork) {
    if (isTesting() || mTesting) {
    // TODO
    } else {
        final RestParams params = new RestParams.Builder().withForceReadFromNetwork(forceNetwork).withPerPageQueryParam(true).withShouldIgnoreToken(false).build();
        final RestBuilder adapter = new RestBuilder(callback);
        StatusCallback<List<Group>> depaginatedCallback = new ExhaustiveListCallback<Group>(callback) {

            @Override
            public void getNextPage(@NonNull StatusCallback<List<Group>> callback, @NonNull String nextUrl, boolean isCached) {
                GroupAPI.getNextPageGroups(nextUrl, adapter, callback, params);
            }
        };
        adapter.setStatusCallback(depaginatedCallback);
        GroupAPI.getFavoriteGroups(adapter, depaginatedCallback, params);
    }
}
Also used : Group(com.instructure.canvasapi2.models.Group) RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) NonNull(android.support.annotation.NonNull) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ArrayList(java.util.ArrayList) List(java.util.List) StatusCallback(com.instructure.canvasapi2.StatusCallback) ExhaustiveListCallback(com.instructure.canvasapi2.utils.ExhaustiveListCallback)

Example 79 with RestParams

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

the class GroupManager method getFavoriteGroupsSynchronous.

@NonNull
public static List<Group> getFavoriteGroupsSynchronous(final boolean forceNetwork) throws IOException {
    if (isTesting() || mTesting) {
        // TODO
        return new ArrayList<>();
    } else {
        final RestBuilder adapter = new RestBuilder();
        RestParams params = new RestParams.Builder().withPerPageQueryParam(true).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
        Response<List<Group>> response = GroupAPI.getFavoriteGroupsSynchronously(adapter, params);
        if (response != null && response.isSuccessful() && response.body() != null)
            return response.body();
        else
            return new ArrayList<>();
    }
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ArrayList(java.util.ArrayList) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ArrayList(java.util.ArrayList) List(java.util.List) NonNull(android.support.annotation.NonNull)

Example 80 with RestParams

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

the class GroupManager method getGroupsSynchronous.

/**
 * So we are only going to fetch the first 200 groups. If you are reading this and are an instructor with more than 200 groups... sorry.
 * @param forceNetwork
 * @return
 * @throws IOException
 */
@NonNull
public static List<Group> getGroupsSynchronous(final boolean forceNetwork) throws IOException {
    if (isTesting() || mTesting) {
        return new ArrayList<>();
    } else {
        final RestBuilder adapter = new RestBuilder();
        RestParams params = new RestParams.Builder().withPerPageQueryParam(true).withShouldIgnoreToken(false).withForceReadFromNetwork(forceNetwork).build();
        ArrayList<Group> items = new ArrayList<>();
        Response<List<Group>> response = GroupAPI.getGroupsSynchronously(adapter, params);
        if (response != null && response.isSuccessful() && response.body() != null)
            items.addAll(response.body());
        String nextUrl = nextUrl(response);
        if (nextUrl != null) {
            Response<List<Group>> nextResponse = GroupAPI.getNextPageGroupsSynchronously(nextUrl, adapter, params);
            if (nextResponse != null && nextResponse.isSuccessful() && nextResponse.body() != null)
                items.addAll(nextResponse.body());
        }
        return items;
    }
}
Also used : Group(com.instructure.canvasapi2.models.Group) RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ArrayList(java.util.ArrayList) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ArrayList(java.util.ArrayList) List(java.util.List) NonNull(android.support.annotation.NonNull)

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