Skip to content

Commit 6dfac5b

Browse files
rowedonaldeFederico Delgado
authored andcommitted
Added JSON building for v2 requests
1 parent 2f8aa9c commit 6dfac5b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

ox3apiclient/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,17 @@ def request(self, url, method='GET', headers={}, data=None, sign=False):
175175

176176
# Stringify data.
177177
if data:
178-
# Everything needs to be UTF-8 for urlencode:
178+
# Everything needs to be UTF-8 for urlencode and json:
179179
data_utf8 = req.get_data()
180180
for i in data_utf8:
181181
data_utf8[i] = data_utf8[i].encode('utf-8')
182-
req.add_data(urllib.urlencode(data_utf8))
182+
if self.api_path == API_PATH_V1:
183+
req.add_data(urllib.urlencode(data_utf8))
184+
elif self.api_path == API_PATH_V2:
185+
req.add_data(json.dumps(data_utf8))
186+
else:
187+
raise UnknownAPIFormatError(
188+
'Unrecognized API path: %s' % self.api_path)
183189

184190
# In 2.4 and 2.5, urllib2 throws errors for all non 200 status codes.
185191
# The OpenX API uses 201 create responses and 204 for delete respones.

0 commit comments

Comments
 (0)