def _request(self, url, method='GET', data=None, ok_statuses=None):
"""
Issue an HTTP request using the authorized Http object, handle bad responses, set the Meta object from the
response content, and return the data as JSON.
:param url: endpoint to send the request
:param method: HTTP method (e.g. GET, POST, etc.), defaults to GET
:return: JSON data
"""
#
# TODO: clean up the ability to send a POST and add unit tests.
#
if data is None:
req_body = None
else:
req_body = urllib.urlencode(data)
self.resp, self.content = self.http.request(url, method, body=req_body)
if ok_statuses is None:
ok_statuses = [httplib.OK]
self._raise_for_status(ok_statuses)
resp_json = json.loads(self.content)
self.meta = upapi.meta.Meta(**resp_json['meta'])
return resp_json['data']
评论列表
文章目录