Search in sources :

Example 21 with File

use of com.google.api.services.drive.model.File in project Aegis by Decad3nce.

the class BackupGoogleAccountsActivity method createAegisFolder.

private void createAegisFolder() {
    Log.i(TAG, "Creating aeGis folder");
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                File body = new File();
                body.setTitle("aeGis Backup");
                body.setDescription("Backup stored by aeGis");
                body.setMimeType("application/vnd.google-apps.folder");
                File file = service.files().insert(body).execute();
                if (file != null) {
                    finish();
                }
            } catch (UserRecoverableAuthIOException e) {
                startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    t.start();
}
Also used : UserRecoverableAuthIOException(com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException) UserRecoverableAuthIOException(com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException) IOException(java.io.IOException) File(com.google.api.services.drive.model.File)

Example 22 with File

use of com.google.api.services.drive.model.File in project camel by apache.

the class AbstractGoogleDriveTestSupport method uploadTestFile.

protected File uploadTestFile() {
    File fileMetadata = new File();
    fileMetadata.setTitle(UPLOAD_FILE.getName());
    FileContent mediaContent = new FileContent(null, UPLOAD_FILE);
    final Map<String, Object> headers = new HashMap<String, Object>();
    // parameter type is com.google.api.services.drive.model.File
    headers.put("CamelGoogleDrive.content", fileMetadata);
    // parameter type is com.google.api.client.http.AbstractInputStreamContent
    headers.put("CamelGoogleDrive.mediaContent", mediaContent);
    File result = requestBodyAndHeaders("google-drive://drive-files/insert", null, headers);
    return result;
}
Also used : FileContent(com.google.api.client.http.FileContent) HashMap(java.util.HashMap) File(com.google.api.services.drive.model.File)

Example 23 with File

use of com.google.api.services.drive.model.File in project camel by apache.

the class DriveChildrenIntegrationTest method testUploadFileToFolder.

@Test
public void testUploadFileToFolder() throws Exception {
    File folder = uploadTestFolder();
    File file = uploadTestFile();
    final Map<String, Object> headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleDrive.folderId", folder.getId());
    com.google.api.services.drive.model.ChildReference child = new com.google.api.services.drive.model.ChildReference();
    child.setId(file.getId());
    // parameter type is com.google.api.services.drive.model.ChildReference
    headers.put("CamelGoogleDrive.content", child);
    requestBodyAndHeaders("direct://INSERT", null, headers);
    final com.google.api.services.drive.model.ChildList result = requestBody("direct://LIST", folder.getId());
    assertNotNull("insert result", result);
    LOG.debug("insert: " + result);
}
Also used : HashMap(java.util.HashMap) File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Example 24 with File

use of com.google.api.services.drive.model.File in project camel by apache.

the class DriveCommentsIntegrationTest method testComment.

@Test
public void testComment() throws Exception {
    // 1. create test file
    File testFile = uploadTestFile();
    String fileId = testFile.getId();
    // 2. comment on that file
    Map<String, Object> headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleDrive.fileId", fileId);
    // parameter type is com.google.api.services.drive.model.Comment
    com.google.api.services.drive.model.Comment comment = new com.google.api.services.drive.model.Comment();
    comment.setContent("Camel rocks!");
    headers.put("CamelGoogleDrive.content", comment);
    requestBodyAndHeaders("direct://INSERT", null, headers);
    // 3. get a list of comments on the file
    // using String message body for single parameter "fileId"
    com.google.api.services.drive.model.CommentList result1 = requestBody("direct://LIST", fileId);
    assertNotNull(result1.get("items"));
    LOG.debug("list: " + result1);
    Comment comment2 = result1.getItems().get(0);
    // 4. now try and get that comment 
    headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleDrive.fileId", fileId);
    // parameter type is String
    headers.put("CamelGoogleDrive.commentId", comment2.getCommentId());
    final com.google.api.services.drive.model.Comment result3 = requestBodyAndHeaders("direct://GET", null, headers);
    assertNotNull("get result", result3);
    // 5. delete the comment
    headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleDrive.fileId", fileId);
    // parameter type is String
    headers.put("CamelGoogleDrive.commentId", comment2.getCommentId());
    requestBodyAndHeaders("direct://DELETE", null, headers);
    // 6. ensure the comment is gone
    headers = new HashMap<String, Object>();
    // parameter type is String
    headers.put("CamelGoogleDrive.fileId", fileId);
    // parameter type is String
    headers.put("CamelGoogleDrive.commentId", comment2.getCommentId());
    try {
        final com.google.api.services.drive.model.Comment result4 = requestBodyAndHeaders("direct://GET", null, headers);
        assertTrue("Should have thrown an exception.", false);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Comment(com.google.api.services.drive.model.Comment) HashMap(java.util.HashMap) Comment(com.google.api.services.drive.model.Comment) File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Example 25 with File

use of com.google.api.services.drive.model.File in project camel by apache.

the class DriveFilesIntegrationTest method testTrash.

@Test
public void testTrash() throws Exception {
    File testFile = uploadTestFile();
    String fileId = testFile.getId();
    assertNotNull("trash result", requestBody("direct://TRASH", fileId));
    assertNotNull("untrash result", requestBody("direct://UNTRASH", fileId));
}
Also used : File(com.google.api.services.drive.model.File) Test(org.junit.Test)

Aggregations

File (com.google.api.services.drive.model.File)41 Test (org.junit.Test)19 IOException (java.io.IOException)17 HashMap (java.util.HashMap)9 FileList (com.google.api.services.drive.model.FileList)7 ParseException (java.text.ParseException)7 ArrayList (java.util.ArrayList)7 FileContent (com.google.api.client.http.FileContent)6 GeneralSecurityException (java.security.GeneralSecurityException)6 GenericUrl (com.google.api.client.http.GenericUrl)4 HttpResponse (com.google.api.client.http.HttpResponse)4 Permission (com.google.api.services.drive.model.Permission)4 User (com.google.api.services.drive.model.User)4 InputStream (java.io.InputStream)4 UserRecoverableAuthIOException (com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException)3 DateTime (com.google.api.client.util.DateTime)3 ParentReference (com.google.api.services.drive.model.ParentReference)3 Comment (com.google.api.services.drive.model.Comment)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2