Repository: OneDrive/onedrive-sdk-android Branch: master Commit: 1af2f0e788b1 Files: 386 Total size: 1.0 MB Directory structure: gitextract_y9dr_hog/ ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── THIRD PARTY NOTICES ├── build.gradle ├── checkstyle.xml ├── docs/ │ ├── authentication.md │ ├── collections.md │ ├── contributions.md │ ├── errors.md │ ├── extensibility.md │ ├── items.md │ └── overview.md ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── onedrivesdk/ │ ├── .gitignore │ ├── build.gradle │ └── src/ │ ├── androidTest/ │ │ └── java/ │ │ └── com/ │ │ └── onedrive/ │ │ └── sdk/ │ │ ├── concurrency/ │ │ │ └── MockExecutors.java │ │ ├── core/ │ │ │ ├── CoreTests.java │ │ │ └── MockClient.java │ │ ├── http/ │ │ │ ├── BaseRequestTests.java │ │ │ ├── DefaultHttpProviderTests.java │ │ │ ├── MockInterceptor.java │ │ │ ├── MockRequest.java │ │ │ └── MockSingleConnectionFactory.java │ │ ├── logger/ │ │ │ └── MockLogger.java │ │ └── serializer/ │ │ ├── DefaultSerializerTests.java │ │ ├── ISO8601Test.java │ │ └── MockSerializer.java │ └── main/ │ ├── AndroidManifest.xml │ └── java/ │ └── com/ │ └── onedrive/ │ └── sdk/ │ ├── authentication/ │ │ ├── ADALAccountInfo.java │ │ ├── ADALAuthenticator.java │ │ ├── AccountType.java │ │ ├── AuthorizationInterceptor.java │ │ ├── ClientAuthenticatorException.java │ │ ├── DisambiguationAuthenticator.java │ │ ├── DisambiguationDialog.java │ │ ├── DisambiguationRequest.java │ │ ├── DisambiguationResponse.java │ │ ├── DisambiguationWebView.java │ │ ├── DiscoveryServiceResponse.java │ │ ├── IAccountInfo.java │ │ ├── IAuthenticator.java │ │ ├── MSAAccountInfo.java │ │ ├── MSAAuthenticator.java │ │ ├── MicrosoftOAuthConfig.java │ │ ├── ServiceInfo.java │ │ └── adal/ │ │ └── BrokerPermissionsChecker.java │ ├── concurrency/ │ │ ├── AsyncMonitor.java │ │ ├── AsyncMonitorLocation.java │ │ ├── AsyncMonitorResponseHandler.java │ │ ├── AsyncOperationException.java │ │ ├── ChunkedUploadProvider.java │ │ ├── ChunkedUploadRequest.java │ │ ├── ChunkedUploadResponseHandler.java │ │ ├── DefaultExecutors.java │ │ ├── ICallback.java │ │ ├── IExecutors.java │ │ ├── IProgressCallback.java │ │ ├── ResultGetter.java │ │ ├── SimpleWaiter.java │ │ └── SynchronousExecutor.java │ ├── core/ │ │ ├── BaseClient.java │ │ ├── ClientException.java │ │ ├── DefaultClientConfig.java │ │ ├── IBaseClient.java │ │ ├── IClientConfig.java │ │ └── OneDriveErrorCodes.java │ ├── extensions/ │ │ ├── AsyncOperationStatus.java │ │ ├── Audio.java │ │ ├── ChunkedUploadResult.java │ │ ├── ChunkedUploadSessionDescriptor.java │ │ ├── CopyBody.java │ │ ├── CopyRequest.java │ │ ├── CopyRequestBuilder.java │ │ ├── CreateLinkBody.java │ │ ├── CreateLinkRequest.java │ │ ├── CreateLinkRequestBuilder.java │ │ ├── CreateSessionBody.java │ │ ├── CreateSessionRequest.java │ │ ├── CreateSessionRequestBuilder.java │ │ ├── Deleted.java │ │ ├── DeltaCollectionPage.java │ │ ├── DeltaRequest.java │ │ ├── DeltaRequestBuilder.java │ │ ├── DeltaResponse.java │ │ ├── Drive.java │ │ ├── DriveCollectionPage.java │ │ ├── DriveCollectionRequest.java │ │ ├── DriveCollectionRequestBuilder.java │ │ ├── DriveRequest.java │ │ ├── DriveRequestBuilder.java │ │ ├── File.java │ │ ├── FileSystemInfo.java │ │ ├── Folder.java │ │ ├── Hashes.java │ │ ├── ICopyRequest.java │ │ ├── ICopyRequestBuilder.java │ │ ├── ICreateLinkRequest.java │ │ ├── ICreateLinkRequestBuilder.java │ │ ├── ICreateSessionRequest.java │ │ ├── ICreateSessionRequestBuilder.java │ │ ├── IDeltaCollectionPage.java │ │ ├── IDeltaRequest.java │ │ ├── IDeltaRequestBuilder.java │ │ ├── IDriveCollectionPage.java │ │ ├── IDriveCollectionRequest.java │ │ ├── IDriveCollectionRequestBuilder.java │ │ ├── IDriveRequest.java │ │ ├── IDriveRequestBuilder.java │ │ ├── IItemCollectionPage.java │ │ ├── IItemCollectionRequest.java │ │ ├── IItemCollectionRequestBuilder.java │ │ ├── IItemRequest.java │ │ ├── IItemRequestBuilder.java │ │ ├── IItemStreamRequest.java │ │ ├── IItemStreamRequestBuilder.java │ │ ├── IOneDriveClient.java │ │ ├── IPermissionCollectionPage.java │ │ ├── IPermissionCollectionRequest.java │ │ ├── IPermissionCollectionRequestBuilder.java │ │ ├── IPermissionRequest.java │ │ ├── IPermissionRequestBuilder.java │ │ ├── IRecentCollectionPage.java │ │ ├── IRecentRequest.java │ │ ├── IRecentRequestBuilder.java │ │ ├── ISearchCollectionPage.java │ │ ├── ISearchRequest.java │ │ ├── ISearchRequestBuilder.java │ │ ├── IShareCollectionPage.java │ │ ├── IShareCollectionRequest.java │ │ ├── IShareCollectionRequestBuilder.java │ │ ├── IShareRequest.java │ │ ├── IShareRequestBuilder.java │ │ ├── IStringCollectionPage.java │ │ ├── IStringCollectionRequest.java │ │ ├── IStringCollectionRequestBuilder.java │ │ ├── IThumbnailRequest.java │ │ ├── IThumbnailRequestBuilder.java │ │ ├── IThumbnailSetCollectionPage.java │ │ ├── IThumbnailSetCollectionRequest.java │ │ ├── IThumbnailSetCollectionRequestBuilder.java │ │ ├── IThumbnailSetRequest.java │ │ ├── IThumbnailSetRequestBuilder.java │ │ ├── IThumbnailStreamRequest.java │ │ ├── IThumbnailStreamRequestBuilder.java │ │ ├── Identity.java │ │ ├── IdentitySet.java │ │ ├── Image.java │ │ ├── Item.java │ │ ├── ItemCollectionPage.java │ │ ├── ItemCollectionRequest.java │ │ ├── ItemCollectionRequestBuilder.java │ │ ├── ItemReference.java │ │ ├── ItemRequest.java │ │ ├── ItemRequestBuilder.java │ │ ├── ItemStreamRequest.java │ │ ├── ItemStreamRequestBuilder.java │ │ ├── Location.java │ │ ├── OneDriveClient.java │ │ ├── OpenWithApp.java │ │ ├── OpenWithSet.java │ │ ├── Permission.java │ │ ├── PermissionCollectionPage.java │ │ ├── PermissionCollectionRequest.java │ │ ├── PermissionCollectionRequestBuilder.java │ │ ├── PermissionRequest.java │ │ ├── PermissionRequestBuilder.java │ │ ├── Photo.java │ │ ├── Quota.java │ │ ├── RecentCollectionPage.java │ │ ├── RecentRequest.java │ │ ├── RecentRequestBuilder.java │ │ ├── SearchCollectionPage.java │ │ ├── SearchRequest.java │ │ ├── SearchRequestBuilder.java │ │ ├── SearchResult.java │ │ ├── Share.java │ │ ├── ShareCollectionPage.java │ │ ├── ShareCollectionRequest.java │ │ ├── ShareCollectionRequestBuilder.java │ │ ├── ShareRequest.java │ │ ├── ShareRequestBuilder.java │ │ ├── Shared.java │ │ ├── SharingInvitation.java │ │ ├── SharingLink.java │ │ ├── SpecialFolder.java │ │ ├── StringCollectionPage.java │ │ ├── StringCollectionRequest.java │ │ ├── StringCollectionRequestBuilder.java │ │ ├── Thumbnail.java │ │ ├── ThumbnailRequest.java │ │ ├── ThumbnailRequestBuilder.java │ │ ├── ThumbnailSet.java │ │ ├── ThumbnailSetCollectionPage.java │ │ ├── ThumbnailSetCollectionRequest.java │ │ ├── ThumbnailSetCollectionRequestBuilder.java │ │ ├── ThumbnailSetRequest.java │ │ ├── ThumbnailSetRequestBuilder.java │ │ ├── ThumbnailStreamRequest.java │ │ ├── ThumbnailStreamRequestBuilder.java │ │ ├── UploadSession.java │ │ └── Video.java │ ├── generated/ │ │ ├── BaseAsyncOperationStatus.java │ │ ├── BaseAudio.java │ │ ├── BaseChunkedUploadSessionDescriptor.java │ │ ├── BaseCopyBody.java │ │ ├── BaseCopyRequest.java │ │ ├── BaseCopyRequestBuilder.java │ │ ├── BaseCreateLinkBody.java │ │ ├── BaseCreateLinkRequest.java │ │ ├── BaseCreateLinkRequestBuilder.java │ │ ├── BaseCreateSessionBody.java │ │ ├── BaseCreateSessionRequest.java │ │ ├── BaseCreateSessionRequestBuilder.java │ │ ├── BaseDeleted.java │ │ ├── BaseDeltaCollectionPage.java │ │ ├── BaseDeltaCollectionResponse.java │ │ ├── BaseDeltaRequest.java │ │ ├── BaseDeltaRequestBuilder.java │ │ ├── BaseDeltaResponse.java │ │ ├── BaseDrive.java │ │ ├── BaseDriveCollectionPage.java │ │ ├── BaseDriveCollectionRequest.java │ │ ├── BaseDriveCollectionRequestBuilder.java │ │ ├── BaseDriveCollectionResponse.java │ │ ├── BaseDriveRequest.java │ │ ├── BaseDriveRequestBuilder.java │ │ ├── BaseFile.java │ │ ├── BaseFileSystemInfo.java │ │ ├── BaseFolder.java │ │ ├── BaseHashes.java │ │ ├── BaseIdentity.java │ │ ├── BaseIdentitySet.java │ │ ├── BaseImage.java │ │ ├── BaseItem.java │ │ ├── BaseItemCollectionPage.java │ │ ├── BaseItemCollectionRequest.java │ │ ├── BaseItemCollectionRequestBuilder.java │ │ ├── BaseItemCollectionResponse.java │ │ ├── BaseItemReference.java │ │ ├── BaseItemRequest.java │ │ ├── BaseItemRequestBuilder.java │ │ ├── BaseItemStreamRequest.java │ │ ├── BaseItemStreamRequestBuilder.java │ │ ├── BaseLocation.java │ │ ├── BaseOneDriveClient.java │ │ ├── BaseOpenWithApp.java │ │ ├── BaseOpenWithSet.java │ │ ├── BasePermission.java │ │ ├── BasePermissionCollectionPage.java │ │ ├── BasePermissionCollectionRequest.java │ │ ├── BasePermissionCollectionRequestBuilder.java │ │ ├── BasePermissionCollectionResponse.java │ │ ├── BasePermissionRequest.java │ │ ├── BasePermissionRequestBuilder.java │ │ ├── BasePhoto.java │ │ ├── BaseQuota.java │ │ ├── BaseRecentCollectionPage.java │ │ ├── BaseRecentCollectionResponse.java │ │ ├── BaseRecentRequest.java │ │ ├── BaseRecentRequestBuilder.java │ │ ├── BaseSearchCollectionPage.java │ │ ├── BaseSearchCollectionResponse.java │ │ ├── BaseSearchRequest.java │ │ ├── BaseSearchRequestBuilder.java │ │ ├── BaseSearchResult.java │ │ ├── BaseShare.java │ │ ├── BaseShareCollectionPage.java │ │ ├── BaseShareCollectionRequest.java │ │ ├── BaseShareCollectionRequestBuilder.java │ │ ├── BaseShareCollectionResponse.java │ │ ├── BaseShareRequest.java │ │ ├── BaseShareRequestBuilder.java │ │ ├── BaseShared.java │ │ ├── BaseSharingInvitation.java │ │ ├── BaseSharingLink.java │ │ ├── BaseSpecialFolder.java │ │ ├── BaseStringCollectionPage.java │ │ ├── BaseStringCollectionRequest.java │ │ ├── BaseStringCollectionRequestBuilder.java │ │ ├── BaseStringCollectionResponse.java │ │ ├── BaseThumbnail.java │ │ ├── BaseThumbnailRequest.java │ │ ├── BaseThumbnailRequestBuilder.java │ │ ├── BaseThumbnailSet.java │ │ ├── BaseThumbnailSetCollectionPage.java │ │ ├── BaseThumbnailSetCollectionRequest.java │ │ ├── BaseThumbnailSetCollectionRequestBuilder.java │ │ ├── BaseThumbnailSetCollectionResponse.java │ │ ├── BaseThumbnailSetRequest.java │ │ ├── BaseThumbnailSetRequestBuilder.java │ │ ├── BaseThumbnailStreamRequest.java │ │ ├── BaseThumbnailStreamRequestBuilder.java │ │ ├── BaseUploadSession.java │ │ ├── BaseVideo.java │ │ ├── IBaseCopyRequest.java │ │ ├── IBaseCopyRequestBuilder.java │ │ ├── IBaseCreateLinkRequest.java │ │ ├── IBaseCreateLinkRequestBuilder.java │ │ ├── IBaseCreateSessionRequest.java │ │ ├── IBaseCreateSessionRequestBuilder.java │ │ ├── IBaseDeltaCollectionPage.java │ │ ├── IBaseDeltaRequest.java │ │ ├── IBaseDeltaRequestBuilder.java │ │ ├── IBaseDriveCollectionPage.java │ │ ├── IBaseDriveCollectionRequest.java │ │ ├── IBaseDriveCollectionRequestBuilder.java │ │ ├── IBaseDriveRequest.java │ │ ├── IBaseDriveRequestBuilder.java │ │ ├── IBaseItemCollectionPage.java │ │ ├── IBaseItemCollectionRequest.java │ │ ├── IBaseItemCollectionRequestBuilder.java │ │ ├── IBaseItemRequest.java │ │ ├── IBaseItemRequestBuilder.java │ │ ├── IBaseItemStreamRequest.java │ │ ├── IBaseItemStreamRequestBuilder.java │ │ ├── IBaseOneDriveClient.java │ │ ├── IBasePermissionCollectionPage.java │ │ ├── IBasePermissionCollectionRequest.java │ │ ├── IBasePermissionCollectionRequestBuilder.java │ │ ├── IBasePermissionRequest.java │ │ ├── IBasePermissionRequestBuilder.java │ │ ├── IBaseRecentCollectionPage.java │ │ ├── IBaseRecentRequest.java │ │ ├── IBaseRecentRequestBuilder.java │ │ ├── IBaseSearchCollectionPage.java │ │ ├── IBaseSearchRequest.java │ │ ├── IBaseSearchRequestBuilder.java │ │ ├── IBaseShareCollectionPage.java │ │ ├── IBaseShareCollectionRequest.java │ │ ├── IBaseShareCollectionRequestBuilder.java │ │ ├── IBaseShareRequest.java │ │ ├── IBaseShareRequestBuilder.java │ │ ├── IBaseStringCollectionPage.java │ │ ├── IBaseStringCollectionRequest.java │ │ ├── IBaseStringCollectionRequestBuilder.java │ │ ├── IBaseThumbnailRequest.java │ │ ├── IBaseThumbnailRequestBuilder.java │ │ ├── IBaseThumbnailSetCollectionPage.java │ │ ├── IBaseThumbnailSetCollectionRequest.java │ │ ├── IBaseThumbnailSetCollectionRequestBuilder.java │ │ ├── IBaseThumbnailSetRequest.java │ │ ├── IBaseThumbnailSetRequestBuilder.java │ │ ├── IBaseThumbnailStreamRequest.java │ │ └── IBaseThumbnailStreamRequestBuilder.java │ ├── http/ │ │ ├── BaseCollectionPage.java │ │ ├── BaseCollectionRequest.java │ │ ├── BaseRequest.java │ │ ├── BaseRequestBuilder.java │ │ ├── BaseStreamRequest.java │ │ ├── DefaultConnectionFactory.java │ │ ├── DefaultHttpProvider.java │ │ ├── HttpMethod.java │ │ ├── HttpResponseCode.java │ │ ├── IBaseCollectionPage.java │ │ ├── IConnection.java │ │ ├── IConnectionFactory.java │ │ ├── IHttpProvider.java │ │ ├── IHttpRequest.java │ │ ├── IHttpStreamRequest.java │ │ ├── IRequestBuilder.java │ │ ├── IRequestInterceptor.java │ │ ├── IStatefulResponseHandler.java │ │ ├── OneDriveError.java │ │ ├── OneDriveErrorResponse.java │ │ ├── OneDriveFatalServiceException.java │ │ ├── OneDriveInnerError.java │ │ ├── OneDriveServiceException.java │ │ └── UrlConnection.java │ ├── logger/ │ │ ├── DefaultLogger.java │ │ ├── ILogger.java │ │ └── LoggerLevel.java │ ├── options/ │ │ ├── HeaderOption.java │ │ ├── Option.java │ │ └── QueryOption.java │ └── serializer/ │ ├── CalendarSerializer.java │ ├── DefaultSerializer.java │ ├── GsonFactory.java │ ├── IJsonBackedObject.java │ └── ISerializer.java └── settings.gradle ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Built application files *.apk *.ap_ # Files for the Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ # Gradle files .gradle/ build/ # Local configuration file (sdk path, etc) local.properties # Proguard folder generated by Eclipse proguard/ # Log Files *.log # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm *.iml .idea/ ## Directory-based project format: # User-specific stuff: .idea/workspace.xml .idea/tasks.xml .idea/dictionaries # Sensitive or high-churn files: .idea/dataSources.ids .idea/dataSources.xml .idea/sqlDataSources.xml .idea/dynamic.xml .idea/uiDesigner.xml # Gradle: .idea/gradle.xml .idea/libraries # Mongo Explorer plugin: .idea/mongoSettings.xml ## File-based project format: *.ipr *.iws .DS_Store ================================================ FILE: .travis.yml ================================================ language: android env: global: - ADB_INSTALL_TIMEOUT=8 matrix: - ANDROID_TARGET=15 ANDROID_ABI=default/armeabi-v7a - ANDROID_TARGET=21 ANDROID_ABI=default/armeabi-v7a android: components: - platform-tools - extra - android-23 - build-tools-23.0.1 before_script: - echo no | android create avd --force -n test -t android-$ANDROID_TARGET --abi $ANDROID_ABI - emulator -avd test -no-skin -no-audio -no-window & - android-wait-for-emulator - adb shell input keyevent 82 & before_install: - chmod +x gradlew script: - ./gradlew clean assemble - ./gradlew connectedAndroidTest ================================================ FILE: LICENSE ================================================ OneDrive SDK Android Copyright (c) 2015 Microsoft Corporation All rights reserved. MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # OneDrive SDK for Android [ ![Download](https://api.bintray.com/packages/onedrive/Maven/onedrive-sdk-android/images/download.svg) ](https://bintray.com/onedrive/Maven/onedrive-sdk-android/_latestVersion) [![Build Status](https://travis-ci.org/OneDrive/onedrive-sdk-android.svg?branch=master)](https://travis-ci.org/OneDrive/onedrive-sdk-android) Integrate the [OneDrive API](https://dev.onedrive.com/README.htm) into your Android application! ## 1. Installation ### 1.1 Install AAR via Gradle Add the maven central repository to your projects build.gradle file then add a compile dependency for com.onedrive.sdk:onedrive-sdk-android:1.3+ ```gradle repository { jcenter() } dependency { // Include the sdk as a dependency compile ('com.onedrive.sdk:onedrive-sdk-android:1.3+') { transitive = false } // Include the gson dependency compile ('com.google.code.gson:gson:2.3.1') // Include supported authentication methods for your application compile ('com.microsoft.services.msa:msa-auth:0.8.+') compile ('com.microsoft.aad:adal:1.1.+') } ``` ## 2. Getting started ### 2.1 Register your application Register your application by following [these](https://dev.onedrive.com/app-registration.htm) steps. ### 2.2 Set your application Id and scopes The OneDrive SDK for Android comes with Authenticator objects that have already been initialized for OneDrive with Microsoft accounts and Azure Activity Directory accounts. Replace the current settings with the required settings to start authenticating. Application that authenicate via MSA need to have a [scope of access](https://github.com/OneDrive/onedrive-api-docs/blob/master/auth/msa_oauth.md#authentication-scopes) defined to use features on OneDrive. If your application is being used in for OneDrive for business AAD will need the [administrators consent](https://dev.onedrive.com/app-registration.htm) for your application to communicate with OneDrive. Note that your _msa-client-id_ and _adal-client-id_ should look be in GUID format like `00000000-0000-0000-0000-000000000000`. For legacy MSA application, the _msa-client-id_ should look like `0000000000000000`. ```java final MSAAuthenticator msaAuthenticator = new MSAAuthenticator() { @Override public String getClientId() { return ""; } @Override public String[] getScopes() { return new String[] { "onedrive.appfolder" }; } } final ADALAuthenticator adalAuthenticator = new ADALAuthenticator() { @Override public String getClientId() { return ""; } @Override protected String getRedirectUrl() { return "https://localhost"; } } ``` ### 2.3 Get a OneDriveClient object Once you have set the correct application Id and scopes, you must get a **OneDriveClient** object to make requests against the service. The SDK will store the account information for you, but when a user logs on for the first time, it will invoke UI to get the user's account information. ```java final IClientConfig oneDriveConfig = DefaultClientConfig.createWithAuthenticators( msaAuthenticator, adalAuthenticator); final DefaultCallback callback = new DefaultCallback(activity) { @Override public void success(final IOneDriveClient result) { // OneDrive client created successfully. } @Override public void failure(final ClientException error) { // Exception happened during creation. } }; final IOneDriveClient oneDriveClient = new OneDriveClient.Builder() .fromConfig(oneDriveConfig) .loginAndBuildClient(getActivity(), callback); ``` ## 3. Make requests against the service Once you have an OneDriveClient that is authenticated you can begin making calls against the service. The requests against the service look like our [REST API](https://dev.onedrive.com/README.htm). ### Get the drive To retrieve a user's drive: ```java oneDriveClient .getDrive() .buildRequest() .get(new ICallback() { @Override public void success(final Drive result) { final String msg = "Found Drive " + result.id; Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT) .show(); } ... // Handle failure case }); ``` ### Get the root folder To get a user's root folder of their drive: ```java oneDriveClient .getDrive() .getRoot() .buildRequest() .get(new ICallback() { @Override public void success(final Item result) { final String msg = "Found Root " + result.id; Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT) .show(); } ... // Handle failure case }); ``` For a general overview of how the SDK is designed, see [overview](docs/overview.md). ## 4. Documentation For a more detailed documentation see: * [Overview](docs/overview.md) * [Authentication](docs/authentication.md) * [Extensibility](docs/extensibility.md) * [Items](docs/items.md) * [Collections](docs/collections.md) * [Errors](docs/errors.md) * [Contributions](docs/contributions.md) ## 5. Issues For known issues, see [issues](https://github.com/OneDrive/onedrive-sdk-android/issues). ## 6. Contributions The OneDrive SDK is open for contribution. Please read how to contribute to this project [here](docs/contributions.md). ## 7. Supported Android Versions The OneDrive SDK for Android library is supported at runtime for [Android API revision 15](http://source.android.com/source/build-numbers.html) and greater. To build the sdk you need to install Android API revision 23 or greater. ## 8. License [License](LICENSE) ## 9. Third Party Notices [Third Party Notices](THIRD PARTY NOTICES) ## 10. Code of Conduct This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. ================================================ FILE: THIRD PARTY NOTICES ================================================ This file is based on or incorporates material from the projects listed below (Third Party IP). The original copyright notice and the license under which Microsoft received such Third Party IP, are set forth below. Such licenses and notices are provided for informational purposes only. Microsoft licenses the Third Party IP to you under the licensing terms for the Microsoft product. Microsoft reserves all other rights not expressly granted under this agreement, whether by implication, estoppel or otherwise. Gson Copyright 2008-2011 Google Inc. Provided for Informational Purposes Only Apache 2.0 License 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 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ================================================ FILE: build.gradle ================================================ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.3.0' } } allprojects { repositories { maven { url project.nightliesUrl } jcenter() } } ================================================ FILE: checkstyle.xml ================================================ ================================================ FILE: docs/authentication.md ================================================ # Authenticating with the OneDrive SDK for Android The OneDrive SDK requires that all requests are authenticated with OneDrive. This SDK is built to make it easy to incorporate any application with the authentication provider. ## Authenticators Authenticators are provided with the SDK to handle authentication settings. ### Disambiguation Authenticator In order to support as many different users as possible with a single application, we supplied a disambiguation authenticator to provide a user experience that determines which authenticator that user requires. This is the recommended way to distribute your application. ### MSA Authenticator Use the **MSAAuthenticator** object for any account that needs to authenticate with the Microsoft account service. Once you have your client id, you need to determine the appropriate scopes of authority that your application will need. For a complete list of scopes, consult the OAuth [documentation](https://dev.onedrive.com/auth/msa_oauth.htm#authentication-scopes). * For applications that need to store data, use the __onedrive.appfolder__ scope and interact with /drive/special/approot. * For applications that need to read only the contents of user's OneDrive, request the __onedrive.readonly__ scope. Your client id should be formatted like `0000000000000000`. ```java final MSAAuthenticator msaAuthenticator = new MSAAuthenticator { @Override public String getClientId() { return "0000000000000000"; } @Override public String[] getScopes() { return new String[] { "onedrive.appfolder" }; } } ``` ### ADAL Authenticator Use the **ADALAuthenticator** object for accounts that are hosted on Azure Active Directory. After you've [configured](https://dev.onedrive.com/auth/aad_oauth.htm) your service to allow access to an application for OneDrive, you will need create an **ADALAuthenticator** object with the client id and the redirect url in your application. Your client id should be formatted like `00000000-0000-0000-0000-000000000000`. ```java final ADALAuthenticator adalAuthenticator = new ADALAuthenticator { @Override public String getClientId() { return ""; } @Override protected String getRedirectUrl() { return "https://localhost"; } } ``` ## Using Authenticators in your application Creating the **OneDriveClient** object enables the silent or interactive login appropriately, but the only functionality that needs be implemented is the sign out user experience. All the provided authenticators will clear preserved tokens after a sign out has completed, ensuring your application has a clean state. ```java oneDriveClient.getAuthenticator().logout(new ICallback() { @Override public void success(final Void result) { // Handle any state change your application needs to undergo } ... // Handle failure ``` ================================================ FILE: docs/collections.md ================================================ # Collections in the OneDrive SDK for Android The OneDrive SDK for Android allows you to work with item collections in OneDrive. Collection information is contained within a `BaseCollectionPage` object, to which there are three core aspects: * `getCurrentPage` The list of items within the current page. * `getNextPage` The next page request builder. `null` if there are no additional pages. * `getRawObject` The json that represents this page response, containing additional data. ## Getting a children collection by expansion There are several navigation properties within the OneDrive service which can be expanded and returned in collections pages. In order to access these properties, the service request needs to call `expand(...)` once the request is issued. #### Parameters |Name|Description| |----|-----------| |_itemId_|The item id of the item that has the children.| |_propertyToExpand_|The name of the navigation property to expand.| |_callback_|The callback when the get call is returned.| ```java final String itemId = "0000000000000000000000"; final String propertyToExpand = "children"; final ICallback callback = new ICallback { @Override public void success(final Item result) { final IItemCollectionPage page = result.children; Toast.makeText(getActivity(), "Got children", Toast.LENGTH_LONG).show(); } ... // Handle failure } oneDriveClient .getDrive() .getItems(itemId) .buildRequest() .expand(propertyToExpand) .get(callback); ``` ## Getting a children collection by request You can reference navigation properties directly by using the `getChildren()` function within the item's request builder. #### Parameters |Name|Description| |----|-----------| |_itemId_|The item id of the item that has the children.| |_callback_|The callback when the get call is returned.| ```java final String itemId = "0000000000000000000000"; final ICallback callback = new ICallback { @Override public void success(final IItemCollectionPage result) { Toast.makeText(getActivity(), "Got children", Toast.LENGTH_LONG).show(); } ... // Handle failure } oneDriveClient .getDrive() .getItems(itemId) .getChildren() .buildRequest() .get(callback); ``` ## Getting the next page When getting a collection response, the `getNextPage()` function will return the null if there are no more pages, or the request builder to get the next page. By using these request builders you can retrieve all of the items under a collection no matter the size. |Name|Description| |----|-----------| |**itemId**|The item id of the item that has the children| |**callback**|The callback when the get call is returned| ```java final String itemId = "0000000000000000000000"; final ICallback callback = new ICallback { @Override public void success(final IItemCollectionPage result) { // If there was more pages retrieve them too if (result.getNextPage() != null) { result.getNextPage() .buildRequest() .get(new ICallback ...); } Toast.makeText(getActivity(), "Got children", Toast.LENGTH_LONG).show(); } ... // Handle failure } oneDriveClient .getDrive() .getItems(itemId) .getChildren() .buildRequest() .get(callback); ``` ## Create a folder You can create a folder within an item collection by using the request builders `getDrive`, `getItems`, and `getChildren` with the `create` method. #### Parameters |Name|Description| |----|-----------| |_folderToCreate_|The folder to create.| |_parentId_|The item id for the parent item.| |_callback_|The callback when the folder has been created.| ```java final String parentId = "0000000000000000000000"; final Item folderToCreate = new Item(); folderToCreate.name = "NewFolder"; folderToCreate.folder = new Folder(); final ICallback callback = new ICallback { @Override public void success(final Item result) { Toast.makeText(getActivity(), "Created Folder", Toast.LENGTH_LONG).show(); } ... // Handle failure } oneDriveClient .getDrive() .getItems(parentId) .getChildren() .buildRequest() .create(folderToCreate, callback); ``` ================================================ FILE: docs/contributions.md ================================================ # Contributing to the OneDrive SDK for Android The OneDrive SDK is avaliable for all manner of contribution. There are a couple of different recommended paths to get contributions into the released version of this SDK. __NOTE__ A signed a contribution license agreement is required for all contributions, and is checked automatically on new pull requests. Please read and sign the agreement https://cla.microsoft.com/ before starting any work for this repository. ## File issues The best way to get started with a contribution is to start a dialog with the owners of this repository. Sometimes features will be under development or out of scope for this SDK and it's best to check before starting work on contribution. ## Submit pull requests for trivial changes If you are making a change that does not affect the interface components and does not affect other downstream callers, feel free to make a pull request against the __master__ branch. The master branch will be updated frequently, and the gradle dependency will be kept closely inline with it. Revisions of this nature will result in a 0.0.X change of the version number. ## Submit pull requests for features If major functionality is being added, or there will need to be gestation time for a change, it should be submitted against the __feature__ branch. Revisions of this nature will result in a 0.X.X change of the version number. ================================================ FILE: docs/errors.md ================================================ # Handling errors in the OneDrive SDK for Android Errors in the OneDrive SDK for Android behave just like errors returned from the service. You can read more about them [here](https://github.com/OneDrive/onedrive-api-docs/blob/master/misc/errors.md). Anytime you make a request against the service there is the potential for an error. You will see that all requests to the service can return an error. The errors are returned as `ClientException`, with possible subclasses `ClientAuthenticationException` and `OneDriveServiceException` which your application will want to handle. ## Checking the error There are a few different types of errors that can occur during a network call. We have provided some helper methods to make it easy to check what kind of error occurred. These error types are defined in [OneDriveErrorCodes.java](../OneDriveSDK/src/main/java/com/onedrive/sdk/core/OneDriveErrorCodes.java). ```java try { // ... } catch (final ClientExcepion ex) { if (ex.isError(OneDriveErrorCodes.AuthenticationCancelled)) { // Handle the specific authentication cancelled case } // Handle the authentication exception } ``` ### Client authentication exceptions These exceptions represent errors during the authentication flow. The two exceptions are `AuthenticationCancelled` for interactive user cancelation and `AuthenticationFailure` for a problem with the underlying authentication system. ### OneDrive service exceptions These are exceptions from the OneDrive service, that contain extra error diagnostic information. The standard error codes should give your application more than enough detail to message users. However, there is useful debug information contained in the response. __Note__: Sometimes you might see a `OneDriveFatalServiceException`. If you do, please open a [new issue](https://github.com/OneDrive/onedrive-sdk-android/issues/new) so that we can fix it. ================================================ FILE: docs/extensibility.md ================================================ # Extensibility with the OneDrive SDK for Android The OneDrive SDKs are built to allow for customization and enhancement over time while maintaining backwards compatibility. ## Contribution Contributions are welcome on the OneDrive SDKs. To contribute, please open a [new issue](https://github.com/OneDrive/onedrive-sdk-android/issues/new) to start a dialog with the team about what you are creating. __Note__ There is an area of the SDK which is not available for direct contribution, which is anything under the com.onedrive.sdk.generated package. These components are built using automated tools and will be overwritten. As this tooling matures this process will be open to contributions as well. ## Minor modification OneDrive's service is described in accordance with OData. This service description is [available](https://api.onedrive.com/v1.0/$metadata) and continuously updated as new features become available. However, the OneDrive $metadata description does not encompass all features and functionality. To aid with elements of the service that are not described here, the `com.onedrive.sdk.extensions` package was created. The files are all generated automatically but will not be overwritten. Some functionality is already exposed in this manner, and here is example using the `OneDriveClient`. The class hierarchy: ```java class OneDriveClient extends BaseOneDriveClient implements IOneDriveClient {} class BaseOneDriveClient extends BaseClient implements IBaseOneDriveClient {} class BaseClient implements IBaseClient {} ``` The companion interface hierarchy: ```java interface IOneDriveClient extends IBaseOneDriveClient {} interface IBaseOneDriveClient extends IBaseClient {} interface IBaseClient {} ``` - The `BaseClient` layer represents the under-pinnings of an OData client. These objects are open for modification and additions. - The `BaseOneDriveClient` layer is supplied by the OData $metadata description, and is automatically populated with the features described therein. - The `OneDriveClient` layer is where extra functionality above and beyond the $metadata description can be placed. The OneDrive team keeps the interfaces up to date to detect backwards compatibility breaking changes. Most classes generated at this 'top tier' will be empty to support future modification, and OneDriveClient already has been modified to support the 'drive()' behavior. 'drive' is exposed to shorten the `{service-root}/drives/{default-drive-id}` into `{service-root}/drive`. ## Major dependencies During the construction of the `IOneDriveClient` object an `IClientConfig` is used. This configuration determines how the internal functionality of the SDK is supplied. By creating a new `IClientConfig` implementation the components can be modified or wholly replaced to best meet the needs of the caller. ### IHttpProvider Provides the http fabric that is used for all network requests within the SDK. ### IAuthenticator Provides the facilities to authenticate users and supply an authentication token for requests to the service. ### ISerializer Serializes and deserializes the structured object from the service. ### IExecutors Handles executing tasks for the SDK on foreground and background threads. ### ILogger The logging system used by the SDK to report debug and error messages for debugging purposes. ================================================ FILE: docs/items.md ================================================ # Items in the OneDrive SDK for Android Items in the OneDrive SDK behave just like items through the OneDrive API. All actions on items described in the OneDrive API are available through the SDK. For more information, see the [Items Reference](https://dev.onedrive.com/README.htm#item-resource). The examples in this topic all use a previously created `oneDriveClient` object. * [Get an item](#get-an-item) * [Delete an item](#delete-an-item) * [Upload a file](#upload-a-file) * [Download a file](#download-a-file) * [Move an item](#move-an-item) * [Rename an item](#rename-an-item) * [Copy an item](#copy-an-item) * [Upload a large file](#upload-a-large-file) ## Get an item To get an item, you construct request builders `getDrive` and `getItems`, you call `buildRequest` to build the request, and then make a final call to `get`. #### Parameters |Name|Description| |----|-----------| |_itemId_|The item id of the item to retrieve.| |_callback_|The callback for when the get call is returned.| #### Example ```java //Enter the itemId here. final String itemId = "0000000000000000000000"; final ICallback callback = new ICallback() { @Override public void success(final Item result) { Toast.makeText(getActivity(), "Got item", Toast.LENGTH_LONG).show(); } ... // Handle failure } oneDriveClient .getDrive() .getItems(itemId) .buildRequest() .get(callback); ``` ## Delete an item To delete an item, you construct request builders to get the item you want to delete, and then call `delete` on the item. #### Parameters |Name|Description| |--------------|-----------| |_itemId_|The item id of the item to delete.| |_callback_|The callback for when the get call is completed.| #### Example ```java final String itemId = "0000000000000000000000"; final ICallback callback = new ICallback() { @Override public void success(final Void ignored) { Toast.makeText(getActivity(), "Deleted item", Toast.LENGTH_LONG).show(); } ... // Handle failure } oneDriveClient .getDrive() .getItems(itemId) .buildRequest() .delete(callback); ``` ## Upload a file To upload a file, you chain together build requests in this order: `getDrive`, `getItems`, `getChildren`, `byID`, and then `getContent`. You then call `buildRequest` to build the requests, and finally, `put` to complete the upload. #### Parameters |Name|Description| |----|-----------| |_filename_|The name of the file to upload.| |_fileContents_|The byte array (byte[]) that contains the file contents.| |_callback_|The callback when the file is uploaded, as well as progress reported.| #### Example ```java final String filename = "The Filename.txt"; final byte[] fileContents = new byte[] { /* The File contents to upload */}; final IProgressCallback callback = new IProgressCallback() { public void success(final Item item) { Toast.makeText(getActivity(), "Item uploaded", Toast.LENGTH_LONG).show(); } ... // Handle progress // Handle failure } oneDriveClient .getDrive() .getItems(ItemId) .getChildren() .byId(filename) .getContent() .buildRequest() .put(fileContents, callback); ``` ## Download a file To download a file, you construct the request builders `getDrive`, `getItems`, and `getContent`, and then call `buildRequest` to build the request. Finally, you call `get` to retrieve the item to download. #### Parameters |Name|Description| |----|-----------| |_itemId_|The item id of the item to download.| #### Example ```java final String itemId = "0000000000000000000000"; final InputStream inputStream = oneDriveClient .getDrive() .getItems(itemId) .getContent() .buildRequest() .get(); // Use the input stream // Close the input stream ``` ## Move an item To move an item, construct request builders to get the item with `getItem`, and then call `update` with the new location. #### Parameters |Name|Description| |----|-----------| |_newParentId_|The new parent's item id.| |_itemId_|The item id of the item to move.| |_newLocation_|The specific aspects of the item to update.| |_callback_|The callback when the item update has returned.| #### Example ```java final String newParentId = "0000000000000000000000"; final String itemId = "0000000000000000000000"; final Item newLocation = new Item(); newLocation.parentReference = new ItemReference(); newLocation.parentReference.id = newParentId; final ICallback callback = new ICallback() { @Override public void success(final Item result) { Toast.makeText(getActivity(), "Update the item location", Toast.LENGTH_LONG).show(); } ... // Handle failure } oneDriveClient .getDrive() .getItems(itemId) .buildRequest() .update(newLocation, callback); ``` ## Rename an item Like all other operations, you rename an item by constructing request builders `getDrive` and `getItems` on the item, and then calling `update` with the new name. #### Parameters |Name|Description| |----|-----------| |_newItemName_|The new name for the item.| |_itemId_|The item id of the item to rename.| |_newName_|The specific aspects of the item to update.| |_callback_|The callback when the item update has returned.| #### Example ```java final String newItemName = "My File.txt"; final String itemId = "0000000000000000000000"; final Item newName = new Item(); newName.name = newItemName; final ICallback callback = new ICallback() { @Override public void success(final Item result) { Toast.makeText(getActivity(), "Update the item name", Toast.LENGTH_LONG).show(); } ... // Handle failure } oneDriveClient .getDrive() .getItems(itemId) .buildRequest() .update(newName, callback); ``` ## Copy an item Copy requests are processed asynchronously on the service, so the pattern is slightly different, and can require multiple sets of requests. ### Starting a copy request You create a copy request for an item by constructing request builders `getDrive`, `getItems` and 'getCopy' on the item, and then calling `create` to start the request. #### Parameters |Name|Description| |----|-----------| |_itemId_|The item id of the item to copy.| |_copiedItemName_|The name for the copied item.| |_parentId_|The parent's item id for the copied item.| |_callback_|The callback when the copy request has started.| #### Example ```java final String itemId = "0000000000000000000000"; final String copiedItemName = "My File Copy.txt" final String newParentId = "0000000000000000000000"; final ItemReference parentReference = new ItemReference(); parentReference.id = newParentId; final ICallback> callback = new ICallback>() { @Override public void success(final AsyncMonitor itemAsyncMonitor) { Toast.makeText(getActivity(), "Started the copy session", Toast.LENGTH_LONG).show(); } ... // Handle failure }; oneDriveClient .getDrive() .getItems(itemId) .getCopy(copiedItemName, parentReference) .buildRequest() .create(callback); ``` ### Waiting for a copy request to finish The result from the copy requests creation is a monitor that can be checked for status updates, return result of the operation, and automatically poll for the result. Most applications will want to get the result to the user as soon as possible via a polling approach, the following shows how to get the resulting item from with a process notifications. #### Parameters |Name|Description| |----|-----------| |_millisBetweenPoll_|The time in milliseconds between progress updates.| |_asyncMonitor_|The name for the copied item.| |_callback_|The callback when the copy request has finished and progressed.| #### Example ```java final int millisBetweenPoll = 1000; // 1 second final AsyncMonitor asyncMonitor = ...; final IProgressCallback callback = new IProgressCallback() { public void success(final Item item) { Toast.makeText(getActivity(), "Item copied!", Toast.LENGTH_LONG).show(); } public void progress(final int progress, final int progressMax) { Toast.makeText(getActivity(), "Item copy process " + progress, Toast.LENGTH_SHORT).show(); } ... // Handle failure } asyncMonitor .pollForResult(millisBetweenPoll, callback); ``` ## Upload a large file Uploading a large file to OneDrive needs create upload session and uploading bytes to the session url. #### Make create session request You create a create session request for an item by constructing request builders `getDrive`, `getRoot`, `getItemWithPath`, `getCreateSession`, `buildRequest` on the item, and then calling `post` to start the create session request. The response is an upload session object which you call `createUploadProvider` of the object to create an upload provider which handles large file uploading. #### Parameters |Name|Description| |----|-----------| |_itemPath_|The path to the file.| |_chunkedUploadSessionDescriptor_| The chunked upload session descriptor.| |_oneDriveClient_|The one drive client.| |_fileStream_|The input file stream.| |_fileSize_|The size of the file.| |_uploadType_|The upload class type.| |_uploadOptions_|The upload options.| |_callback_|The upload callback.| |_chunkSize_|The chunk size for each upload chunk, default is 5MiB.| |_maxRetry_| The max retry times for each upload chunk, default is 3.| #### Example ```java final String itemPath = "documents/file to copy.txt"; final Option uploadOptions = new QueryOption("@name.conflictBehavior", "fail"); final int chunkSize = 640 * 1024; //must be the multiple of 320KiB final int maxRetry = 5; final IProgressCallback callback = new IProgressCallback() { @Override public void progress(long current, long max) { dialog.setProgress((int) current); dialog.setMax((int) max); } @Override public void success(Item item) {dialog.dismiss(); Toast.makeText(getActivity(), application .getString(R.string.upload_complete, item.name), Toast.LENGTH_LONG).show(); refresh(); } @Override public void failure(ClientException error) { dialog.dismiss(); if (error.isError(OneDriveErrorCodes.NameAlreadyExists)) { Toast.makeText(getActivity(), R.string.upload_failed_name_conflict, Toast.LENGTH_LONG).show(); } else { Toast.makeText(getActivity(), application .getString(R.string.upload_failed, filename), Toast.LENGTH_LONG).show(); } } } oneDriveClient .getDrive() .getRoot() .getItemWithPath(itemPath) .getCreateSession(new ChunkedUploadSessionDescriptor()) .buildRequest() .post() .createUploadProvider(oneDriveClient, fileStream, fileSize, Item.class) .upload(Collections.singletonList(uploadOptions), callback, chunkSize, maxRetry); ``` ================================================ FILE: docs/overview.md ================================================ # Overview for the OneDrive SDK for Android The OneDrive SDK for Android is designed to look just like the OneDrive API. ## OneDriveClient A `OneDriveClient` is always associated with a authentication session. This can be created by using the **Builder** subclass of the `OneDriveClient` implementation, `loginAndBuildClient(..)`. All requests use this object to send information to the service and it should be constructed once for your applications life cycle. ## Resource model Resources, like [items](/docs/items.md) or drives, are represented by `Item` and `Drive`, respectively. These objects contain properties that represent the properties of a resource. These objects can't make calls against the service-they are purely models. To get the name of an item you address the `name` property. It is possible for any of these properties to be null at any time. To check if an item is a folder you address the `folder` property. If the item is a folder an `ODFolder` facet on that object will be returned, and it contains all of the properties described by the [folder](https://github.com/OneDrive/onedrive-api-docs/blob/master/facets/folder_facet.md) facet. See [Resource model](https://github.com/onedrive/onedrive-api-docs/#resource-model) for more info. The resources that are generated map to the json model described by the $metadata service document. There are items that might not be exposed because they expire very quickly or represent functionality that is not featured in this SDK as of yet. To access these fields use `getRawObject()` on the model items and access the specific properties that are not in the model. ## Issuing requests To make requests against the service, first build a request with **RequestBuilder** and then build it into a Request object, which is then sent against the service. This follows the URL scheme that the OneDrive API uses for all its resources. ### Request builders To generate requests you chain together calls on request builder objects. You get the first request builder from the `OneDriveClient` object. To get a drive, create a request builder by calling **OneDriveClient.getDrive**. |Task | SDK | URL | |:---------------|:-----------------:|:--------------------------------| |Get a drive | `oneDriveClient.getDrive()` | GET api.onedrive.com/v1.0/drive/| `getDrive` will return an `IDriveRequestBuilder` object. From `getDrive`, you can continue to chain the requests to get everything else in the API, like an item. |Task | SDK | URL | |:---------------|:----------------------------------:|:------------------------------------------| |Get an item | `oneDriveClient.getDrive().getItems("1234")` | GET api.onedrive.com/v1.0/drive/items/1234| Here, `oneDriveClient.getDrive()` returns an `IDriveRequestBuilder` that contains a method `getItems(...)` to get an `IItemRequestBuilder`. Similarly, to get thumbnails, you chain together the request builders `getThumbnails` and `getItems`. |Task | SDK | URL | |----------------|--------------------------------|--------------------------| | Get thumbnails | `... .getItems("1234").getThumbnails()` | .../items/1234/thumbnails| Here, `oneDriveClient.getDrive().getItems("1234")` returns an `IItemRequestBuilder` that contains the method `getThumbnails()`. This returns a collection of [thumbnail sets](https://github.com/OneDrive/onedrive-api-docs/blob/master/resources/thumbnailSet.md). To index the collection directly you can call: |Task | SDK | URL | |-------------------|-------------------------------------|----------------------------| | Get thumbnail Set | `... .getItems("1234").getThumbnails("0")` | ...items/1234/thumbnails/0 | To return a thumbnail set, and to get a specific [thumbnail](https://github.com/OneDrive/onedrive-api-docs/blob/master/resources/thumbnail.md), you can add the name of the thumbnail to the URL like this: |Task | SDK | URL | |-----------------|-----------------------------|------------------------| | Get a thumbnail | `... .getThumbnails("0").getThumbnailSize("small")` | .../thumbnails/0/small | ### Requests Once you have constructed the request you call the `buildRequest()` method on the request builder. This will construct the request object needed to make calls against the service. For an item you call: ```java final IItemRequest itemRequest = OneDriveClient.getDrive().getItems("1234").buildRequest(); ``` All request builders have a `buildRequest()` method that can generate a `IHttpRequest` object. Request objects may have different methods on them depending on the type of request. To get an item you call: ```java itemRequest.get(new ICallback{ @Override public void success(final Item result) { // This will make the network request and return the item } @Override public void failure(final ClientException ex) { // or an error if there was one } }); ``` You could also chain this together with call above : ```java OneDriveClient.getDrive().getItems("1234").buildRequest().get(new ICallback{ @Override public void success(final Item result) { // This will make the network request and return the item } @Override public void failure(final ClientException ex) { // or an error if there was one } }); ``` See [items](/docs/items.md) for more info on items and [errors](/docs/errors.md) for more info on errors. ## Query options If you only want to retrieve certain properties of a resource, you use `select` specify them. Here's how to get only the names and ids of an item: ```java oneDriveClient.getDrive().getItems("1234").buildRequest().select("name,id").get(new ICallback() { @Override public void success(final Item result) { // The item object will have null properties for everything except name and id } }); ``` To expand certain properties on resources you can call a similar `expand` method, like this: ```java oneDriveClient.getDrive().getItems("1234").buildRequest().expand("thumbnails").get(new ICallback() { @Override public void success(final Item result) { // the item object will have collection page of thumbnails for its thumbnails property if thumbnails exist. } }); ``` ## Additional request options If you need to include more specific behavior during a request, there are `Option` objects that you can add when calling `buildRequest`. See a detailed list of query parameters in the [OneDrive API optional query parameters](https://dev.onedrive.com/odata/optional-query-parameters.htm) documentation. Here's an example of how to add an additional query parameter to sort the returned collection page results by size: ```java final List