Search in sources :

Example 11 with RestBuilder

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

the class ErrorReportAPI method buildInterface.

private static ErrorReportInterface buildInterface(StatusCallback<?> callback) {
    RestBuilder adapter = new RestBuilder(callback);
    RestParams params = new RestParams.Builder().withShouldIgnoreToken(true).withPerPageQueryParam(false).withForceReadFromCache(false).withForceReadFromNetwork(true).build();
    return adapter.build(ErrorReportInterface.class, params);
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder)

Example 12 with RestBuilder

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

the class FileFolderAPI method uploadFileSynchronousNoRedirect.

@WorkerThread
public static /* Used to manually handle the last redirect */
RemoteFile uploadFileSynchronousNoRedirect(@NonNull RestBuilder adapter, String uploadUrl, Map<String, RequestBody> uploadParams, String mimeType, File file) throws IOException {
    RestParams params = new RestParams.Builder().withShouldIgnoreToken(true).withDomain(uploadUrl).withPerPageQueryParam(false).build();
    RequestBody fileBody = RequestBody.create(MediaType.parse(mimeType), file);
    Headers headers = adapter.buildNoRedirects(FilesFoldersInterface.class, params).uploadFile(uploadParams, fileBody).execute().headers();
    String redirect = headers.get("Location");
    String newFileUrl = redirect.split("/create_success")[0];
    // POST to the redirect... according to the docs we need to do this to finalize the file upload process
    RemoteFile newFile = adapter.build(FilesFoldersInterface.class, params).postNewlyCreatedFile(redirect).execute().body();
    // We weren't receiving a url in the response from the POST to the redirect - here we grab the full file info as a work around
    FileFolder fileFolder = FileFolderManager.getFileFolderFromURLSynchronous(newFileUrl);
    newFile.setUrl(fileFolder.getUrl());
    newFile.setThumbnailUrl(fileFolder.getThumbnailUrl());
    return newFile;
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) Headers(okhttp3.Headers) FileFolder(com.instructure.canvasapi2.models.FileFolder) UpdateFileFolder(com.instructure.canvasapi2.models.UpdateFileFolder) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RemoteFile(com.instructure.canvasapi2.models.RemoteFile) RequestBody(okhttp3.RequestBody) WorkerThread(android.support.annotation.WorkerThread)

Example 13 with RestBuilder

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

the class FileFolderAPI method uploadFileSynchronous.

@WorkerThread
public static RemoteFile uploadFileSynchronous(@NonNull RestBuilder adapter, String uploadUrl, Map<String, RequestBody> uploadParams, String mimeType, File file) throws IOException {
    RestParams params = new RestParams.Builder().withShouldIgnoreToken(true).withDomain(uploadUrl).withPerPageQueryParam(false).build();
    RequestBody fileBody = RequestBody.create(MediaType.parse(mimeType), file);
    return adapter.build(FilesFoldersInterface.class, params).uploadFile(uploadParams, fileBody).execute().body();
}
Also used : RestParams(com.instructure.canvasapi2.builders.RestParams) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) RequestBody(okhttp3.RequestBody) WorkerThread(android.support.annotation.WorkerThread)

Example 14 with RestBuilder

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

the class RecipientManager_Test method getFirstPageRecipients.

public static void getFirstPageRecipients(String searchQuery, String context, StatusCallback<List<Recipient>> callback, RestBuilder adapter, RestParams params) {
    // TODO:
    Response response = new Response.Builder().code(200).message("todo").protocol(Protocol.HTTP_1_0).body(ResponseBody.create(MediaType.parse("application/json"), "todo".getBytes())).addHeader("content-type", "application/json").build();
    List<Recipient> items = new ArrayList<>();
    retrofit2.Response<List<Recipient>> response1 = retrofit2.Response.success(items, response);
    callback.onResponse(response1, new LinkHeaders(), ApiType.CACHE);
}
Also used : Response(okhttp3.Response) LinkHeaders(com.instructure.canvasapi2.utils.LinkHeaders) RestBuilder(com.instructure.canvasapi2.builders.RestBuilder) ArrayList(java.util.ArrayList) Recipient(com.instructure.canvasapi2.models.Recipient) List(java.util.List) ArrayList(java.util.ArrayList)

Example 15 with RestBuilder

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

the class UserManager_Test method addStudentToParentAirwolf.

public static void addStudentToParentAirwolf(String airwolfDomain, RestBuilder adapter, RestParams params, String parentId, String studentDomain, StatusCallback<ResponseBody> 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)

Aggregations

RestBuilder (com.instructure.canvasapi2.builders.RestBuilder)288 RestParams (com.instructure.canvasapi2.builders.RestParams)261 List (java.util.List)39 StatusCallback (com.instructure.canvasapi2.StatusCallback)34 ExhaustiveListCallback (com.instructure.canvasapi2.utils.ExhaustiveListCallback)31 NonNull (android.support.annotation.NonNull)28 ArrayList (java.util.ArrayList)22 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)6 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