forked from OneDrive/onedrive-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
156 changed files
with
17,606 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
OneDrive Python SDK | ||
=================== | ||
|
||
Lorem ipsum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 OneDrive | ||
|
||
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include LICENSE | ||
include DESCRIPTION.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
**Getting Started with the OneDrive Python SDK** | ||
|
||
------------------------------------------------------------------------ | ||
[](https://ci.appveyor.com/project/OneDrive/vroom-client-python) | ||
|
||
Installation | ||
============ | ||
|
||
To install the OneDrive Python SDK, open a command prompt and type: | ||
|
||
<pre><code>pip install onedrivesdk | ||
</code></pre> | ||
Next, include the SDK in your python project by adding | ||
|
||
<pre><code>import onedrivesdk</code></pre> | ||
|
||
Authentication | ||
============== | ||
|
||
To interact with the OneDrive API, you must authenticate. You can use the following code sample to do so. | ||
|
||
<pre><code>import onedrivesdk | ||
from onedrivesdk.helpers import GetAuthCodeServer | ||
|
||
redirect_uri = "http://localhost:8080/" | ||
client_secret = "your_app_secret" | ||
|
||
client = onedrivesdk.get_default_client(client_id='your_client_id', | ||
scopes=['wl.signin', | ||
'wl.offline_access', | ||
'onedrive.readwrite']) | ||
|
||
auth_url = client.auth_provider.get_auth_url(redirect_uri) | ||
|
||
#this will block until we have the code | ||
code = GetAuthCodeServer.get_auth_code(auth_url, redirect_uri) | ||
|
||
client.auth_provider.authenticate(code, redirect_uri, client_secret) | ||
</code></pre> | ||
|
||
Once you are authenticated, you should have access to the OneDrive API, and | ||
can begin making calls using the SDK! | ||
|
||
Examples | ||
======== | ||
|
||
NOTE: All examples assume that the | ||
[Authentication](#authentication) has already occured. | ||
|
||
Upload an Item | ||
-------------- | ||
|
||
<pre><code>returned_item = client.item(drive="me", id="root").children["newfile.txt"].upload("./path_to_file.txt")</code></pre> | ||
|
||
Download an Item | ||
---------------- | ||
|
||
<pre><code>root_folder = client.item(drive="me", id="root").children.get() | ||
id_of_file = root_folder[0].id | ||
|
||
client.item(drive="me", id=id_of_file).download("./path_to_download_to.txt") | ||
</code></pre> | ||
|
||
Add a Folder | ||
------------ | ||
|
||
<pre><code>f = onedrivesdk.Folder() | ||
i = onedrivesdk.Item() | ||
i.name = "New Folder" | ||
i.folder = f | ||
|
||
returned_item = client.item(drive="me", id="root").children.add(i) | ||
</code></pre> | ||
|
||
Copying an Item | ||
--------------- | ||
|
||
<pre><code>from onedrivesdk.item_reference import ItemReference | ||
|
||
ref = ItemReference() | ||
ref.id = "yourparent!id" #path also supported | ||
|
||
copy_operation = client.item(drive="me", id="youritemtocopy!id").copy(name="new copied name", parent_reference=ref).post() | ||
|
||
#copy_operation.item will return None until the copy has completed. | ||
#If you would like to block until the operation has been completed | ||
#and copy_operation.item is no longer None | ||
copy_operation.poll_until_complete() | ||
|
||
</code></pre> | ||
|
||
Renaming an Item | ||
---------------- | ||
|
||
<pre><code>renamed_item = onedrivesdk.Item() | ||
renamed_item.name = "NewItemName" | ||
renamed_item.id = "youritemtorename!id" | ||
|
||
new_item = client.item(drive="me", id=renamed_item.id).update(renamed_item) | ||
</code></pre> | ||
|
||
Paging through a Collection | ||
--------------------------- | ||
|
||
<pre><code>#get the top 3 elements of root, leaving the next page for more elements | ||
collection = client.item(drive="me", id="root").children.request(top=3).get() | ||
|
||
#get the first item in the collection | ||
item = collection[0] | ||
|
||
#get next page of 3 elements, if none exist, returns None | ||
collection2 = collection.next_page_request.get() | ||
</code></pre> | ||
|
||
Async operations | ||
---------------- | ||
|
||
<p> | ||
For async operations, you create an asyncio.coroutine which | ||
implements asyncio.ascompleted, and execute it with | ||
loop.run\_until\_complete. | ||
|
||
<pre><code>import asyncio | ||
|
||
@asyncio.coroutine | ||
def run_gets(client): | ||
coroutines = [client.drive("me").request().get_async() for i in range(3)] | ||
for future in asyncio.as_completed(coroutines): | ||
drive = yield from future | ||
print(drive.id) | ||
|
||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(run_gets(client)) | ||
</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
environment: | ||
|
||
global: | ||
# SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the | ||
# /E:ON and /V:ON options are not enabled in the batch script intepreter | ||
# See: http://stackoverflow.com/a/13751649/163740 | ||
WITH_COMPILER: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_compiler.cmd" | ||
|
||
matrix: | ||
|
||
- PYTHON: "C:\\Python27" | ||
PYTHON_VERSION: "2.7.x" # currently 2.7.9 | ||
PYTHON_ARCH: "32" | ||
|
||
- PYTHON: "C:\\Python33" | ||
PYTHON_VERSION: "3.3.x" # currently 3.3.5 | ||
PYTHON_ARCH: "32" | ||
|
||
- PYTHON: "C:\\Python34" | ||
PYTHON_VERSION: "3.4.x" # currently 3.4.3 | ||
PYTHON_ARCH: "32" | ||
|
||
- PYTHON: "C:\\Python27-x64" | ||
PYTHON_VERSION: "2.7.x" # currently 2.7.9 | ||
PYTHON_ARCH: "64" | ||
WINDOWS_SDK_VERSION: "v7.0" | ||
|
||
- PYTHON: "C:\\Python33-x64" | ||
PYTHON_VERSION: "3.3.x" # currently 3.3.5 | ||
PYTHON_ARCH: "64" | ||
WINDOWS_SDK_VERSION: "v7.1" | ||
|
||
- PYTHON: "C:\\Python34-x64" | ||
PYTHON_VERSION: "3.4.x" # currently 3.4.3 | ||
PYTHON_ARCH: "64" | ||
WINDOWS_SDK_VERSION: "v7.1" | ||
|
||
init: | ||
- "ECHO %PYTHON% %PYTHON_VERSION% %PYTHON_ARCH%" | ||
|
||
install: | ||
- "powershell appveyor\\install.ps1" | ||
- "%PYTHON%/python -m pip install Mock" | ||
- "%PYTHON%/python setup.py install" | ||
|
||
build: off | ||
|
||
test_script: | ||
- "%WITH_COMPILER% %PYTHON%/python setup.py test" | ||
|
||
after_test: | ||
- "%WITH_COMPILER% %PYTHON%/python setup.py bdist_wheel" | ||
|
||
artifacts: | ||
- path: dist\* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Sample script to install Python and pip under Windows | ||
# Authors: Olivier Grisel and Kyle Kastner | ||
# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/ | ||
|
||
$BASE_URL = "https://www.python.org/ftp/python/" | ||
$GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py" | ||
$GET_PIP_PATH = "C:\get-pip.py" | ||
|
||
|
||
function DownloadPython ($python_version, $platform_suffix) { | ||
$webclient = New-Object System.Net.WebClient | ||
$filename = "python-" + $python_version + $platform_suffix + ".msi" | ||
$url = $BASE_URL + $python_version + "/" + $filename | ||
|
||
$basedir = $pwd.Path + "\" | ||
$filepath = $basedir + $filename | ||
if (Test-Path $filename) { | ||
Write-Host "Reusing" $filepath | ||
return $filepath | ||
} | ||
|
||
# Download and retry up to 5 times in case of network transient errors. | ||
Write-Host "Downloading" $filename "from" $url | ||
$retry_attempts = 3 | ||
for($i=0; $i -lt $retry_attempts; $i++){ | ||
try { | ||
$webclient.DownloadFile($url, $filepath) | ||
break | ||
} | ||
Catch [Exception]{ | ||
Start-Sleep 1 | ||
} | ||
} | ||
Write-Host "File saved at" $filepath | ||
return $filepath | ||
} | ||
|
||
|
||
function InstallPython ($python_version, $architecture, $python_home) { | ||
Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home | ||
if (Test-Path $python_home) { | ||
Write-Host $python_home "already exists, skipping." | ||
return $false | ||
} | ||
if ($architecture -eq "32") { | ||
$platform_suffix = "" | ||
} else { | ||
$platform_suffix = ".amd64" | ||
} | ||
$filepath = DownloadPython $python_version $platform_suffix | ||
Write-Host "Installing" $filepath "to" $python_home | ||
$args = "/qn /i $filepath TARGETDIR=$python_home" | ||
Write-Host "msiexec.exe" $args | ||
Start-Process -FilePath "msiexec.exe" -ArgumentList $args -Wait -Passthru | ||
Write-Host "Python $python_version ($architecture) installation complete" | ||
return $true | ||
} | ||
|
||
|
||
function InstallPip ($python_home) { | ||
$pip_path = $python_home + "/Scripts/pip.exe" | ||
$python_path = $python_home + "/python.exe" | ||
if (-not(Test-Path $pip_path)) { | ||
Write-Host "Installing pip..." | ||
$webclient = New-Object System.Net.WebClient | ||
$webclient.DownloadFile($GET_PIP_URL, $GET_PIP_PATH) | ||
Write-Host "Executing:" $python_path $GET_PIP_PATH | ||
Start-Process -FilePath "$python_path" -ArgumentList "$GET_PIP_PATH" -Wait -Passthru | ||
} else { | ||
Write-Host "pip already installed." | ||
} | ||
} | ||
|
||
function InstallPackage ($python_home, $pkg) { | ||
$pip_path = $python_home + "/Scripts/pip.exe" | ||
& $pip_path install $pkg | ||
} | ||
|
||
function main () { | ||
InstallPython $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON | ||
InstallPip $env:PYTHON | ||
InstallPackage $env:PYTHON wheel | ||
} | ||
|
||
main |
Oops, something went wrong.