Commit a39d44df by Daniel Robinson

Merge pull request #138 from milesrichardson/master

work with self-hosted parse server
parents bfb76788 8dddd840
about the fork
=========
- Forked from https://github.com/dgrtwo/ParsePy on 3/28 by @milesrichardson
- upstream seems to be no longer maintained
- major fixes in fork:
- (improvement) Work with self-hosted parse-server
- (improvement) Work with self-hosted parse-server and batch_save
- (bugfix) batch_save calls response callback on ALL responses, even if some contain errors, and raises ParseBatchError([error1, error2, error3]) with list of all errors encountered during batch operation
(See https://github.com/dgrtwo/ParsePy/pull/138 for PR)
parse_rest
==========
......
......@@ -13,13 +13,16 @@
from six.moves.urllib.request import Request, urlopen
from six.moves.urllib.error import HTTPError
from six.moves.urllib.parse import urlencode
from six.moves.urllib.parse import urlencode, urlparse
import json
from parse_rest import core
API_ROOT = 'https://api.parse.com/1'
import os
API_ROOT = os.environ.get('PARSE_API_ROOT') or 'https://api.parse.com/1'
ACCESS_KEYS = {}
......@@ -87,7 +90,8 @@ class ParseBase(object):
command.
"""
if batch:
ret = {"method": http_verb, "path": uri.split("parse.com", 1)[1]}
urlsplitter = urlparse(API_ROOT).netloc
ret = {"method": http_verb, "path": uri.split(urlsplitter, 1)[1]}
if kw:
ret["body"] = kw
return ret
......@@ -179,11 +183,16 @@ class ParseBatcher(ParseBase):
responses = self.execute("", "POST", requests=queries)
# perform the callbacks with the response data (updating the existing
# objets, etc)
batched_errors = []
for callback, response in zip(callbacks, responses):
if "success" in response:
callback(response["success"])
else:
raise core.ParseError(response["error"])
batched_errors.append(response["error"])
if batched_errors:
raise core.ParseBatchError(batched_errors)
def batch_save(self, objects):
"""save a list of objects in one operation"""
......
......@@ -16,6 +16,9 @@ class ParseError(Exception):
'''Base exceptions from requests made to Parse'''
pass
class ParseBatchError(Exception):
''' Error in batching operation... should take a list. '''
pass
class ResourceRequestBadRequest(ParseError):
'''Request returns a 400'''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment