-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhuddleApi.py
More file actions
45 lines (36 loc) · 1.89 KB
/
huddleApi.py
File metadata and controls
45 lines (36 loc) · 1.89 KB
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
39
40
41
42
43
44
45
import oAuth
import token
import urllib2
import json
from poster.encode import multipart_encode # You can find the lib at: http://pypi.python.org/pypi/poster/0.4
from poster.streaminghttp import register_openers
class huddleApi:
def __init__(self, HuddleAuthServer, tokenStore):
self.HuddleAuthServer = HuddleAuthServer
self.tokenStore = tokenStore
def getUser(self):
headers = {'Accept': 'application/vnd.huddle.data+json', 'Authorization': 'OAuth2' + self.tokenStore.getAccessToken()}
uri = "http://api.huddle.net/" + "entry/"
req = urllib2.Request(uri, headers=headers)
response = urllib2.urlopen(req)
return response
def getFolder(self, uri):
headers = {'Accept': 'application/vnd.huddle.data+json', 'Authorization': 'OAuth2' + self.tokenStore.getAccessToken()}
req = urllib2.Request(uri, headers=headers)
response = urllib2.urlopen(req)
return response
def createFile(self, name, desc, uri):
headers = {'Accept': 'application/vnd.huddle.data+json', 'Authorization': 'OAuth2 ' + self.tokenStore.getAccessToken(), 'Content-Type': 'application/json'}
body = "{title:" + "\"" + name + "\"" + " ,description:" + "\"" + desc + "\"" + "}"
req = urllib2.Request(uri, body, headers)
response = urllib2.urlopen(req)
return response
def uploadToFile(self, document, uri):
register_openers()
values = {'filename': open(document)}
data, headers = multipart_encode(values)
#add our headers
headers['Authorization'] = 'OAuth2 ' + self.tokenStore.getAccessToken()
request = urllib2.Request(uri, data, headers)
request.unverifiable = True
urllib2.urlopen(request)