Commit 2133c3e7 by Paul Kastner

little fixes

parent b24d08f8
ParsePy ParsePy
======= =======
**ParsePy** is a Python client for the [Parse REST API](https://www.parse.com/docs/rest). It provides Python object mapping for Parse objects with methods to save, update, and delete objects, as well as an interface for quering stored objects. **ParsePy** is a Python client for the [Parse REST API](https://www.parse.com/docs/rest). It provides Python object mapping for Parse objects with methods to save, update, and delete objects, as well as an interface for querying stored objects.
Basic Usage Basic Usage
----------- -----------
...@@ -23,7 +23,7 @@ To create a new object of the Parse class _GameScore_: ...@@ -23,7 +23,7 @@ To create a new object of the Parse class _GameScore_:
>>> gameScore.cheatMode = False >>> gameScore.cheatMode = False
~~~~~ ~~~~~
As you can see, we add new properties simply by assining values to our _ParseObject_'s attributes. Supported data types are any type that can be serialized by JSON and Python's _datetime.datetime_ object. (Binary data and references to other _ParseObject_'s are also supported, as we'll see in a minute.) As you can see, we add new properties simply by assigning values to our _ParseObject_'s attributes. Supported data types are any type that can be serialized by JSON and Python's _datetime.datetime_ object. (Binary data and references to other _ParseObject_'s are also supported, as we'll see in a minute.)
To save our new object, just call the save() method: To save our new object, just call the save() method:
...@@ -38,6 +38,12 @@ If we want to make an update, just call save() again after modifying an attribut ...@@ -38,6 +38,12 @@ If we want to make an update, just call save() again after modifying an attribut
>>> gameScore.save() >>> gameScore.save()
~~~~~ ~~~~~
Now that we've done all that work creating our first Parse object, let's delete it:
~~~~~ {python}
>>> gameScore.delete()
~~~~~
That's it! You're ready to start saving data on Parse. That's it! You're ready to start saving data on Parse.
Object Metadata Object Metadata
...@@ -69,6 +75,7 @@ We can store a reference to another ParseObject by assigning it to an attribute: ...@@ -69,6 +75,7 @@ We can store a reference to another ParseObject by assigning it to an attribute:
>>> collectedItem = ParsePy.ParseObject("CollectedItem") >>> collectedItem = ParsePy.ParseObject("CollectedItem")
>>> collectedItem.type = "Sword" >>> collectedItem.type = "Sword"
>>> collectedItem.isAwesome = True >>> collectedItem.isAwesome = True
>>> collectedItem.save() # we have to save it before it can be referenced
>>> gameScore.item = collectedItem >>> gameScore.item = collectedItem
~~~~~ ~~~~~
...@@ -111,4 +118,4 @@ We can also order the results using: ...@@ -111,4 +118,4 @@ We can also order the results using:
* **Order** * **Order**
* order(_parameter_name_, _decending_=False) * order(_parameter_name_, _decending_=False)
That's it! This is a first try at a Python library for Parse, and is probably not bug-free. If you run into any bugs, please get in touch -- parsepy@paulkastner.com. Thanks! That's it! This is a first try at a Python library for Parse, and is probably not bug-free. If you run into any issues, please get in touch -- parsepy@paulkastner.com. Thanks!
...@@ -35,6 +35,7 @@ class ParseBase(object): ...@@ -35,6 +35,7 @@ class ParseBase(object):
request.add_header('Content-type', 'application/json') request.add_header('Content-type', 'application/json')
# we could use urllib2's authentication system, but it seems like overkill for this
auth_header = "Basic %s" % base64.b64encode('%s:%s' % (APPLICATION_ID, MASTER_KEY)) auth_header = "Basic %s" % base64.b64encode('%s:%s' % (APPLICATION_ID, MASTER_KEY))
request.add_header("Authorization", auth_header) request.add_header("Authorization", auth_header)
...@@ -68,10 +69,10 @@ class ParseObject(ParseBase): ...@@ -68,10 +69,10 @@ class ParseObject(ParseBase):
return self._object_id return self._object_id
def updatedAt(self): def updatedAt(self):
return self._updated_at return self._upddated_at and self._ISO8601ToDatetime(self._updated_at) or None
def createdAt(self): def createdAt(self):
return self._created_at return self._created_at and self._ISO8601ToDatetime(self._created_at) or None
def save(self): def save(self):
if self._object_id: if self._object_id:
...@@ -91,8 +92,8 @@ class ParseObject(ParseBase): ...@@ -91,8 +92,8 @@ class ParseObject(ParseBase):
def _populateFromDict(self, attrs_dict): def _populateFromDict(self, attrs_dict):
self._object_id = attrs_dict['objectId'] self._object_id = attrs_dict['objectId']
self._created_at = self._ISO8601ToDatetime(attrs_dict['createdAt']) self._created_at = attrs_dict['createdAt']
self._updated_at = self._ISO8601ToDatetime(attrs_dict['updatedAt']) self._updated_at = attrs_dict['updatedAt']
del attrs_dict['objectId'] del attrs_dict['objectId']
del attrs_dict['createdAt'] del attrs_dict['createdAt']
......
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