Permalink
Browse files

working!

  • Loading branch information...
1 parent 1be9e32 commit e50c813b0b7492f182032a98d9389d2bd8070561 @kennethreitz kennethreitz committed Sep 11, 2011
Showing with 17 additions and 6 deletions.
  1. +17 −6 resources/core.py
View
23 resources/core.py
@@ -53,6 +53,12 @@ def __init__(self, resource=None):
super(Collection, self).__init__()
+ def __repr__(self):
+ return '<collection \'{0}:{1}\'>'.format(
+ self.resource.name,
+ self.ri or self.uuid
+ )
+
def content(content_type):
pass
@@ -111,6 +117,11 @@ def __init__(self, resource=None, collection=None):
super(Element, self).__init__()
+ def __repr__(self):
+ return '<element \'{0}:{1}\'>'.format(
+ self.resource.name,
+ self.ri or self.uuid
+ )
def content(content_type):
pass
@@ -162,8 +173,6 @@ def delete(self, **options):
class Interface(object):
"""The RESTful API Interface."""
- resource = Resource()
-
def __init__(self):
self.resources = dict()
self.uuid = uuid4().hex
@@ -179,23 +188,25 @@ def __getattribute__(self, key):
pass
if key in self.resources:
- return self.resources.get(key)
+ return self.resources.get(key).contains
return object.__getattribute__(self, key)
+
def map(self, key, resource=None, is_collection=True):
"""Maps a given resource to the given namespace.
If map is None (not provided), returns decorator.
"""
if resource:
- self.resources[key] = resource(interface=self, name=key)
+ new_resource = resource(interface=self, name=key)
+ self.resources[key] = new_resource
if is_collection:
- self.resources[key].contains = Collection(resource=self)
+ self.resources[key].contains = Collection(resource=new_resource)
else:
- self.resources[key].contains = Element(resource=self)
+ self.resources[key].contains = Element(resource=new_resource)
else:
# Assume decorator usage.

0 comments on commit e50c813

Please sign in to comment.