forked from Huddle/Python-Huddle-Api-Example
/
ExampleCreateFile.py
38 lines (29 loc) · 1.37 KB
/
ExampleCreateFile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import oAuth
import huddleApi
import document
import os
import folder
huddleAuthServer = "http://FOO.COM"
huddleApiServer = "http://BAR.COM"
consumer_key = "foo"
redirect_uri = "bar"
def run_example():
#first lets get the auth code from the client
request_token_url = huddleAuthServer + "request?response_type=code" + "&client_id=" + consumer_key + "&redirect_uri=" + redirect_uri
print "Get Your Authorization Code and paste it back into python\n" + request_token_url
code = raw_input('--> ')
auth = oAuth.oAuth(huddleAuthServer, code, consumer_key, redirect_uri)
#store our access token
tokenStore = auth.handleAccessToken()
#now we can make calls to the api
#we only have the uri for what folder we want to create the file in so first of all lets find the upload uri of that
api = huddleApi.huddleApi(huddleApiServer, tokenStore)
getFolder = folder.folder(api.getFolder("http://api.huddle.dev/files/folders/1237980/"))
print getFolder.getLinksWithRel("create-document")
getDocument = document.document(api.createFile("foo", "bar", getFolder.getLinksWithRel("create-document")))
#time to upload the contents
api.uploadToFile("C:\\Users\\adam.flax\\Documents\\foo.txt", getDocument.getLinkWithRel("upload"))
os.system("pause")
if __name__ == '__main__':
run_example()
print 'Done.'