• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java BoxAPIConnection类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中com.box.sdk.BoxAPIConnection的典型用法代码示例。如果您正苦于以下问题:Java BoxAPIConnection类的具体用法?Java BoxAPIConnection怎么用?Java BoxAPIConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

BoxAPIConnection类属于com.box.sdk包,在下文中一共展示了BoxAPIConnection类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createMojitoFolderStructure

点赞 3

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
/**
 * When root folder is not provided, create the following structure inside user's root.
 * <UserRoot>
 * |-> Mojito
 * |-> Project Requests
 * <p>
 * Note: We're creating a Mojito root folder to store everythign related to Mojito
 * because an App User can be accessible by other API keys
 * <p>
 * Note: for now, we're only creating the Project Requests (Drops) folder.
 * Maybe later when we extend our usage of the platform, we'll
 * need another folder to store other things
 */
@Pollable(message = "Start Creating Mojito Folder Structure")
private MojitoAppUserInfo createMojitoFolderStructure() throws BoxSDKServiceException {
    logger.debug("Creating Mojito Folder Structure");
    try {
        MojitoAppUserInfo result = new MojitoAppUserInfo();

        BoxAPIConnection apiConnection = boxAPIConnectionProvider.getConnection();
        BoxFolder parentFolder = new BoxFolder(apiConnection, BoxFolder.getRootFolder(apiConnection).getID());
        BoxFolder.Info mojitoFolder = parentFolder.createFolder(MOJITO_FOLDER_NAME);
        logger.debug("Created Mojito Folder: " + mojitoFolder.getID());
        result.setRootFolderId(mojitoFolder.getID());

        BoxFolder.Info projectRequestFolder = mojitoFolder.getResource().createFolder(PROJECT_REQUESTS_FOLDER_NAME);
        logger.debug("Created Project Requests Folder: " + projectRequestFolder.getID());
        result.setDropsFolderId(projectRequestFolder.getID());

        return result;
    } catch (BoxAPIException e) {
        throw new BoxSDKServiceException("Can't creating Mojito Folder Structure.", e);
    }
}
 

开发者ID:box,
项目名称:mojito,
代码行数:35,
代码来源:BoxSDKServiceConfigEntityService.java

示例2: validateConfig

点赞 3

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
/**
 * @param boxSDKServiceConfig
 */
@Pollable(message = "Validate Config Values")
private void validateConfig(BoxSDKServiceConfigEntity boxSDKServiceConfig, @ParentTask PollableTask parentTask) {
    logger.debug("Validating Box SDK Config");
    try {
        BoxAPIConnection apiConnection = boxAPIConnectionProvider.getConnection();
        BoxFolder mojitoFolder = new BoxFolder(apiConnection, boxSDKServiceConfig.getRootFolderId());
        BoxSharedLink sharedLink = mojitoFolder.createSharedLink(BoxSharedLink.Access.COLLABORATORS, null, null);

        boxSDKServiceConfig.setRootFolderUrl(sharedLink.getURL());
        boxSDKServiceConfig.setValidated(true);

        boxSDKServiceConfigEntityRepository.save(boxSDKServiceConfig);

        logger.debug("Shared link for root folder: {}", sharedLink);
    } catch (BoxSDKServiceException e) {
        boxSDKServiceConfig.setValidated(false);
        logger.error("Error validing config", e);
    }
}
 

开发者ID:box,
项目名称:mojito,
代码行数:23,
代码来源:BoxSDKServiceConfigEntityService.java

示例3: testGetConnectionWillReuseConnection

点赞 3

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
@Test
public void testGetConnectionWillReuseConnection() throws BoxSDKServiceException {
    BoxSDKServiceConfig config = getTestConfig();
    Mockito.when(boxSDKServiceConfigProvider.getConfig()).thenReturn(config);

    BoxAPIConnectionProvider providerSpy = getBoxAPIConnectionProviderMock();

    logger.debug("Get connection first time will create a new connection");
    BoxAPIConnection connection = providerSpy.getConnection();

    logger.debug("Get connection 2nd time will resuse the last one");
    BoxAPIConnection connection2 = providerSpy.getConnection();

    Assert.assertNotNull("A connection is returned", connection);
    Assert.assertNotNull("A connection is returned", connection2);
    Assert.assertEquals("Connections should be the same", connection, connection2);

    logger.debug("Box API connection should only be created once even though getConnection was called multiple times");
    Mockito.verify(providerSpy, Mockito.times(1)).createBoxAPIConnection();
}
 

开发者ID:box,
项目名称:mojito,
代码行数:21,
代码来源:BoxAPIConnectionProviderTest.java

示例4: createAccountFromAuthCode

点赞 3

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
@Override
public final Account createAccountFromAuthCode(String code) throws AccountException {
    BoxAccount boxAccount = null;

    try {
        BoxAPIConnection conn = new BoxAPIConnection(getAppId(), getAppSecret());
        conn.authenticate(code);
        conn.setAutoRefresh(true);

        AccountMetadata metadata = new AccountMetadata(
                getAppId(),
                getAppSecret(),
                conn.getAccessToken(),
                conn.getRefreshToken()
        );

        boxAccount = new BoxAccount(metadata, conn);
    } catch (Exception ex) {
        throw new BoxException("Failed to finish auth process.", ex);
    }

    return boxAccount;
}
 

开发者ID:omnidrive,
项目名称:omnidrive,
代码行数:24,
代码来源:BoxAuthorizer.java

示例5: getConnection

点赞 2

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
/**
 * @return An API connection for use
 * @throws BoxSDKServiceException
 */
public BoxAPIConnection getConnection() throws BoxSDKServiceException {
    logger.debug("Getting Box API Connection");
    BoxSDKServiceConfig currentConfig = boxSDKServiceConfigProvider.getConfig();

    if (!Objects.equals(boxSDKServiceConfig, currentConfig) || boxAPIConnection == null) {
        logger.debug("Saving config for used later");
        boxSDKServiceConfig = currentConfig;

        logger.debug("Getting new API connection because config has changed");
        boxAPIConnection = createBoxAPIConnection();
    }

    return boxAPIConnection;
}
 

开发者ID:box,
项目名称:mojito,
代码行数:19,
代码来源:BoxAPIConnectionProvider.java

示例6: createBoxAPIConnection

点赞 2

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
/**
 * @return A fresh API connection using the current config
 * @throws BoxSDKServiceException
 */
protected BoxAPIConnection createBoxAPIConnection() throws BoxSDKServiceException {
    logger.debug("Getting a new App User Connection using the current config");

    BoxSDKServiceConfig boxSDKServiceConfig = boxSDKServiceConfigProvider.getConfig();
    JWTEncryptionPreferences encryptionPref = boxSDKJWTProvider.getJWTEncryptionPreferences(boxSDKServiceConfig);

    return BoxDeveloperEditionAPIConnection.getAppUserConnection(
            boxSDKServiceConfig.getAppUserId(),
            boxSDKServiceConfig.getClientId(),
            boxSDKServiceConfig.getClientSecret(),
            encryptionPref, getAccessTokenCache());
}
 

开发者ID:box,
项目名称:mojito,
代码行数:17,
代码来源:BoxAPIConnectionProvider.java

示例7: getBoxAPIConnectionProviderMock

点赞 2

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
public BoxAPIConnectionProvider getBoxAPIConnectionProviderMock() throws BoxSDKServiceException {
    BoxAPIConnection boxAPIConnection = Mockito.mock(BoxAPIConnection.class);
    BoxAPIConnection boxAPIConnection2 = Mockito.mock(BoxAPIConnection.class);
    BoxAPIConnectionProvider providerSpy = Mockito.spy(boxAPIConnectionProvider);
    Mockito.doReturn(boxAPIConnection)
            .doReturn(boxAPIConnection2)
            .when(providerSpy).createBoxAPIConnection();
    return providerSpy;
}
 

开发者ID:box,
项目名称:mojito,
代码行数:10,
代码来源:BoxAPIConnectionProviderTest.java

示例8: testGetConnectionWillCreateBoxAPIConnection

点赞 2

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
@Test
public void testGetConnectionWillCreateBoxAPIConnection() throws Exception {
    BoxSDKServiceConfig config = getTestConfig();
    Mockito.when(boxSDKServiceConfigProvider.getConfig()).thenReturn(config);

    BoxAPIConnectionProvider providerSpy = getBoxAPIConnectionProviderMock();
    BoxAPIConnection connection = providerSpy.getConnection();

    Assert.assertNotNull("A connection is returned", connection);
    Mockito.verify(providerSpy, Mockito.times(1)).createBoxAPIConnection();
}
 

开发者ID:box,
项目名称:mojito,
代码行数:12,
代码来源:BoxAPIConnectionProviderTest.java

示例9: testGetConnectionWillCreateNewConnectionIfConfigChanges

点赞 2

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
@Test
public void testGetConnectionWillCreateNewConnectionIfConfigChanges() throws BoxSDKServiceException {
    BoxSDKServiceConfig config = getTestConfig();
    Mockito.when(boxSDKServiceConfigProvider.getConfig())
            .thenReturn(config)
            .thenReturn(config)
            .thenReturn(getTestConfig2());

    BoxAPIConnectionProvider providerSpy = getBoxAPIConnectionProviderMock();

    logger.debug("Get connection first time will create a new connection");
    BoxAPIConnection connection = providerSpy.getConnection();

    logger.debug("Get connection 2nd time will resuse the last one");
    BoxAPIConnection connection2 = providerSpy.getConnection();

    logger.debug("Get connection 3nd time will have a different config, so should create a new connection");
    BoxAPIConnection connection3 = providerSpy.getConnection();

    Assert.assertNotNull("A connection is returned", connection);
    Assert.assertNotNull("A connection is returned", connection2);
    Assert.assertNotNull("A connection is returned", connection3);

    Assert.assertNotEquals(connection2, connection3);

    logger.debug("Box API connection should only be created twice.  The first time getConnection was called and when config was changed.");
    Mockito.verify(providerSpy, Mockito.times(2)).createBoxAPIConnection();

}
 

开发者ID:box,
项目名称:mojito,
代码行数:30,
代码来源:BoxAPIConnectionProviderTest.java

示例10: restoreAccount

点赞 2

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
@Override
public Account restoreAccount(AccountMetadata metadata, RefreshedAccountObserver observer) throws AccountException {
    BoxAPIConnection conn = new BoxAPIConnection(
            getAppId(),
            getAppSecret(),
            metadata.getAccessToken(),
            metadata.getRefreshToken()
    );

    BoxAccount account = new BoxAccount(metadata, conn, observer);
    //account.refreshAuthorization(); // BOX API does auto refresh here

    return account;
}
 

开发者ID:omnidrive,
项目名称:omnidrive,
代码行数:15,
代码来源:BoxAuthorizer.java

示例11: onRefresh

点赞 2

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
@Override
public void onRefresh(BoxAPIConnection boxAPIConnection) {
    System.out.println("Box: refresh token");
    if (boxAPIConnection.getAccessToken() != null) {
        this.metadata.setAccessToken(boxAPIConnection.getAccessToken());
    }
    if (boxAPIConnection.getRefreshToken() != null) {
        this.metadata.setRefreshToken(boxAPIConnection.getRefreshToken());
    }
    notifyRefreshed();
}
 

开发者ID:omnidrive,
项目名称:omnidrive,
代码行数:12,
代码来源:BoxAccount.java

示例12: main

点赞 2

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
public static void main(String[] args) {
    // Turn off logging to prevent polluting the output.
    Logger.getLogger("com.box.sdk").setLevel(Level.OFF);

    BoxAPIConnection api = new BoxAPIConnection(DEVELOPER_TOKEN);

    BoxUser.Info userInfo = BoxUser.getCurrentUser(api).getInfo();
    System.out.format("Welcome, %s <%s>!\n\n", userInfo.getName(), userInfo.getLogin());

    BoxFolder rootFolder = BoxFolder.getRootFolder(api);
    listFolder(rootFolder, 0);
}
 

开发者ID:box,
项目名称:box-java-sdk,
代码行数:13,
代码来源:Main.java

示例13: getBoxAPIConnection

点赞 2

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
public BoxAPIConnection getBoxAPIConnection() throws BoxSDKServiceException {
    return boxAPIConnectionProvider.getConnection();
}
 

开发者ID:box,
项目名称:mojito,
代码行数:4,
代码来源:BoxSDKService.java

示例14: BoxAccount

点赞 2

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
public BoxAccount(AccountMetadata metadata, BoxAPIConnection connection) {
    this(metadata, connection, null);
}
 

开发者ID:omnidrive,
项目名称:omnidrive,
代码行数:4,
代码来源:BoxAccount.java

示例15: onError

点赞 2

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
@Override
public void onError(BoxAPIConnection boxAPIConnection, BoxAPIException e) {
    System.out.println("Box error: " + e.getResponse());
}
 

开发者ID:omnidrive,
项目名称:omnidrive,
代码行数:5,
代码来源:BoxAccount.java

示例16: Box

点赞 1

import com.box.sdk.BoxAPIConnection; //导入依赖的package包/类
/**
 * initializes a new Box storage facade
 * @param appSecret developer app secret
 * @param appKey developer box app id
 * @param userAccessToken auth code for authenticated user
 * @throws ElasticSyncException if invalid parameters
 */
public Box(String appSecret, String appKey, String userAccessToken) throws ElasticSyncException {
	super(appSecret, appKey, userAccessToken);
	this.boxApp = new BoxAPIConnection(this.appKey,
			this.appSecret, this.userAccessToken);
}
 

开发者ID:KosherKampus,
项目名称:elasticsync,
代码行数:13,
代码来源:Box.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)