Skip to content

Commit c913b86

Browse files
committed
Merge pull request #1 from ryanrdetzel/master
fixes so get content work and update content work
2 parents 2767915 + 6ad8bd7 commit c913b86

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

hackpad.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_pad_content(self, padId, revision='', response_format='txt', asUser=''):
2828
api_link = 'pad/%s/content' % padId
2929
if revision != '':
3030
api_link += revision
31-
api_link += '.%s' % format
31+
api_link += '.%s' % response_format
3232
params = {}
3333
if asUser != '':
3434
params['asUser'] = asUser
@@ -115,6 +115,7 @@ def site_options(self):
115115
return self.do_api_request(api_link, 'GET')
116116

117117
def do_api_request(self, path, method, post_data={}, body='', content_type='text/plain'):
118+
method = method.upper()
118119
hackpad = {}
119120
try:
120121
api_method = urljoin('https://%s.hackpad.com/api/1.0/' % self.sub_domain, path)
@@ -127,7 +128,7 @@ def do_api_request(self, path, method, post_data={}, body='', content_type='text
127128
params[key] = post_data[key]
128129
consumer = oauth2.Consumer(self.consumer_key, self.consumer_secret)
129130
params['oauth_consumer_key'] = consumer.key
130-
req = oauth2.Request(method='GET', url=api_method, parameters=params)
131+
req = oauth2.Request(method=method, url=api_method, parameters=params)
131132
signature_method = oauth2.SignatureMethod_HMAC_SHA1()
132133
req.sign_request(signature_method, consumer, None)
133134
api_link = req.to_url()
@@ -138,7 +139,7 @@ def do_api_request(self, path, method, post_data={}, body='', content_type='text
138139
headers={'Content-Type': content_type},
139140
verify=False
140141
)
141-
hackpad = r.json
142+
hackpad = r.json()
142143
else:
143144
if len(post_data.keys()) > 0:
144145
r = requests.get(
@@ -153,7 +154,10 @@ def do_api_request(self, path, method, post_data={}, body='', content_type='text
153154
headers={'Content-Type': 'text/plain'},
154155
verify=False
155156
)
156-
hackpad = r.json
157+
try:
158+
hackpad = r.json()
159+
except:
160+
hackpad = r.content
157161
except:
158162
print sys.exc_info()[0]
159163

0 commit comments

Comments
 (0)