Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7456f0f

Browse filesBrowse files
committed
fill out HTTPBackend. add support for POST requests
1 parent 310a5b9 commit 7456f0f
Copy full SHA for 7456f0f

File tree

1 file changed

+36
-1
lines changed
Filter options

1 file changed

+36
-1
lines changed

‎zencoder/zencoder.py

Copy file name to clipboardExpand all lines: zencoder/zencoder.py
+36-1Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,49 @@ class ZencoderError(Exception):
1212
class HTTPBackend(object):
1313
"""
1414
Abstracts out an HTTP backend, but defaults to httplib2
15+
16+
@FIXME: Build in support for supplying arbitrary backends
1517
"""
16-
def __init__(self):
18+
def __init__(self, as_xml=False):
1719
"""
1820
Creates an HTTPBackend object, which abstracts out some of the
1921
library specific HTTP stuff.
2022
"""
2123
self.base_url = 'https://app.zencoder.com/api/'
2224
self.http = httplib2.Http()
25+
self.as_xml = as_xml
26+
27+
if self.as_xml:
28+
self.headers = {}
29+
else:
30+
self.headers = {'Content-Type': 'application/json',
31+
'Accepts': 'application/json'}
32+
33+
def decode(self, raw_body):
34+
"""
35+
Returns the raw_body as json (the default) or XML
36+
"""
37+
if not self.as_xml:
38+
return json.loads(raw_body)
39+
40+
def post(self, url, body=None):
41+
"""
42+
Execute a HTTP POST request for the given URL
43+
"""
44+
response, content = self.http.request(url, method="POST",
45+
body=body,
46+
headers=self.headers)
47+
48+
return self.process(response, content)
49+
50+
def process(self, http_response, content):
51+
"""
52+
Returns HTTP backend agnostic Response data
53+
"""
54+
code = http_response.status
55+
body = self.decode(content)
56+
response = Response(code, body, content, http_response)
57+
return response
2358

2459
class Zencoder(object):
2560
""" This is the entry point to the Zencoder API """

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.