Search in sources :

Example 1 with DbxUserUsersRequests

use of com.dropbox.core.v2.users.DbxUserUsersRequests in project cyberduck by iterate-ch.

the class DropboxQuotaFeature method get.

@Override
public Space get() throws BackgroundException {
    try {
        final SpaceUsage usage = new DbxUserUsersRequests(session.getClient()).getSpaceUsage();
        final SpaceAllocation allocation = usage.getAllocation();
        if (allocation.isIndividual()) {
            long remaining = allocation.getIndividualValue().getAllocated() - usage.getUsed();
            return new Space(usage.getUsed(), remaining);
        } else if (allocation.isTeam()) {
            long remaining = allocation.getTeamValue().getAllocated() - usage.getUsed();
            return new Space(usage.getUsed(), remaining);
        }
        return unknown;
    } catch (DbxException e) {
        throw new DropboxExceptionMappingService().map("Failure to read attributes of {0}", e, new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)));
    }
}
Also used : Path(ch.cyberduck.core.Path) SpaceUsage(com.dropbox.core.v2.users.SpaceUsage) SpaceAllocation(com.dropbox.core.v2.users.SpaceAllocation) DbxUserUsersRequests(com.dropbox.core.v2.users.DbxUserUsersRequests) DbxException(com.dropbox.core.DbxException)

Example 2 with DbxUserUsersRequests

use of com.dropbox.core.v2.users.DbxUserUsersRequests in project PrettySecureCloud by SandroGuerotto.

the class DropBoxServiceTest method getAvailableStorageSpace.

@Test
void getAvailableStorageSpace() throws DbxException {
    cut = new DropBoxService(dbxClientV2Mock);
    DbxUserUsersRequests DbxUserUsersRequestsMock = mock(DbxUserUsersRequests.class);
    when(dbxClientV2Mock.users()).thenReturn(DbxUserUsersRequestsMock);
    when(DbxUserUsersRequestsMock.getSpaceUsage()).thenReturn(new SpaceUsage(1_000_000_000_000L, SpaceAllocation.individual(new IndividualSpaceAllocation(5_000_000_000_000L))));
    BigDecimal usedStorageSpace = cut.getUsedStorageSpace();
    assertEquals(1_000_000_000_000L, usedStorageSpace.longValue());
}
Also used : SpaceUsage(com.dropbox.core.v2.users.SpaceUsage) DbxUserUsersRequests(com.dropbox.core.v2.users.DbxUserUsersRequests) IndividualSpaceAllocation(com.dropbox.core.v2.users.IndividualSpaceAllocation) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 3 with DbxUserUsersRequests

use of com.dropbox.core.v2.users.DbxUserUsersRequests in project cyberduck by iterate-ch.

the class DropboxSession method login.

@Override
public void login(final Proxy proxy, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException {
    authorizationService.setTokens(authorizationService.authorize(host, prompt, cancel, OAuth2AuthorizationService.FlowType.AuthorizationCode));
    try {
        final FullAccount account = new DbxUserUsersRequests(client).getCurrentAccount();
        if (log.isDebugEnabled()) {
            log.debug(String.format("Authenticated as user %s", account));
        }
        final Credentials credentials = host.getCredentials();
        credentials.setUsername(account.getEmail());
        credentials.setSaved(true);
        switch(account.getAccountType()) {
            case BUSINESS:
                locking = new DropboxLockFeature(this);
        }
    } catch (DbxException e) {
        throw new DropboxExceptionMappingService().map(e);
    }
}
Also used : DbxUserUsersRequests(com.dropbox.core.v2.users.DbxUserUsersRequests) FullAccount(com.dropbox.core.v2.users.FullAccount) Credentials(ch.cyberduck.core.Credentials) DbxException(com.dropbox.core.DbxException)

Aggregations

DbxUserUsersRequests (com.dropbox.core.v2.users.DbxUserUsersRequests)3 DbxException (com.dropbox.core.DbxException)2 SpaceUsage (com.dropbox.core.v2.users.SpaceUsage)2 Credentials (ch.cyberduck.core.Credentials)1 Path (ch.cyberduck.core.Path)1 FullAccount (com.dropbox.core.v2.users.FullAccount)1 IndividualSpaceAllocation (com.dropbox.core.v2.users.IndividualSpaceAllocation)1 SpaceAllocation (com.dropbox.core.v2.users.SpaceAllocation)1 BigDecimal (java.math.BigDecimal)1 Test (org.junit.jupiter.api.Test)1