Commit 7f651474 by Raphael Lullis

The code was doing request using the master key as a parameter for the request.…

The code was doing request using the master key as a parameter for the request. This was completely wrong. The correct key is API_KEY. Fixed.
parent 6bdb2866
...@@ -18,12 +18,14 @@ import json ...@@ -18,12 +18,14 @@ import json
import datetime import datetime
import collections import collections
import re import re
import logging
API_ROOT = 'https://api.parse.com/1/classes' API_ROOT = 'https://api.parse.com/1/classes'
APPLICATION_ID = '' APPLICATION_ID = ''
MASTER_KEY = '' API_KEY = ''
log = logging.getLogger(__name__)
class ParseBinaryDataWrapper(str): class ParseBinaryDataWrapper(str):
pass pass
...@@ -37,14 +39,18 @@ class ParseBase(object): ...@@ -37,14 +39,18 @@ class ParseBase(object):
request.add_header('Content-type', 'application/json') request.add_header('Content-type', 'application/json')
request.add_header('X-Parse-Application-Id', APPLICATION_ID) request.add_header('X-Parse-Application-Id', APPLICATION_ID)
request.add_header('X-Parse-REST-API-Key', MASTER_KEY) request.add_header('X-Parse-REST-API-Key', API_KEY)
request.get_method = lambda: http_verb request.get_method = lambda: http_verb
# TODO: add error handling for server response # TODO: add error handling for server response
try:
response = urllib2.urlopen(request) response = urllib2.urlopen(request)
response_body = response.read() except urllib2.HTTPError, why:
return json.loads(response_body) #log.error(why)
return None
return json.loads(response.read())
def _ISO8601ToDatetime(self, date_string): def _ISO8601ToDatetime(self, date_string):
...@@ -161,8 +167,7 @@ class ParseObject(ParseBase): ...@@ -161,8 +167,7 @@ class ParseObject(ParseBase):
elif value['__type'] == 'Date': elif value['__type'] == 'Date':
value = self._ISO8601ToDatetime(value['iso']) value = self._ISO8601ToDatetime(value['iso'])
elif value['__type'] == 'Bytes': elif value['__type'] == 'Bytes':
value = ParseBinaryDataWrapper(base64.b64decode( value = ParseBinaryDataWrapper(base64.b64decode(value['base64']))
value['base64']))
elif value['__type'] == 'GeoPoint': elif value['__type'] == 'GeoPoint':
value = 'POINT(%s %s)' % (value['longitude'], value = 'POINT(%s %s)' % (value['longitude'],
value['latitude']) value['latitude'])
...@@ -172,22 +177,11 @@ class ParseObject(ParseBase): ...@@ -172,22 +177,11 @@ class ParseObject(ParseBase):
return (key, value) return (key, value)
def _getJSONProperties(self): def _getJSONProperties(self):
# filter properties that start with an underscore, and convert them.
properties_list = self.__dict__.items() return json.dumps(dict([
self._convertToParseType(p) for p in self.__dict__.items()
# filter properties that start with an underscore if p[0][0] != '_'
properties_list = filter(lambda prop: prop[0][0] != '_', ]))
properties_list)
#properties_list = [(key, value) for key, value
# in self.__dict__.items() if key[0] != '_']
properties_list = map(self._convertToParseType, properties_list)
properties_dict = dict(properties_list)
json_properties = json.dumps(properties_dict)
return json_properties
def _create(self): def _create(self):
# URL: /1/classes/<className> # URL: /1/classes/<className>
......
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