/*
* Copyright 2014 Objectos, Fábrica de Software LTDA.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.objectos.way.gdrive;
import static com.google.common.collect.Lists.newArrayList;
import java.util.List;
import com.google.api.client.http.FileContent;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.ParentReference;
/**
* @author mario.marques@objectos.com.br (Mario Marques Junior)
*/
class GDirectoryFolder implements GDirectory {
private final File file;
private final GDrive drive;
private final String directoryId;
public GDirectoryFolder(File file, GDrive drive, String directoryId) {
this.file = file;
this.drive = drive;
this.directoryId = directoryId;
}
@Override
public List<GFile> listFiles() {
return drive.listFiles(directoryId);
}
@Override
public GDirectory mkdir(String dirName) {
return drive.mkdir(directoryId, dirName);
}
@Override
public String getName() {
return file.getTitle();
}
@Override
public String getId() {
return file.getId();
}
@Override
public GFile write(java.io.File file) {
File body = new File();
body.setTitle(file.getName());
body.setMimeType("text/plain");
body.setParents(newArrayList(new ParentReference().setId(getId())));
FileContent mediaContent = new FileContent("text/plain", file);
return drive.insert(body, mediaContent);
}
@Override
public List<GChange> listChanges() {
return drive.listChanges(directoryId, null);
}
@Override
public List<GChange> listChanges(Long startChangeId) {
return drive.listChanges(directoryId, startChangeId);
}
}