Added User resource, catching errors on requests

small fix
This commit is contained in:
Eibriel
2015-04-15 09:52:06 -03:00
parent ddb7089d74
commit b6de87bc0e
4 changed files with 23 additions and 4 deletions
+1
View File
@@ -1,5 +1,6 @@
from .api import Api
from .nodes import Node
from .nodes import NodeType
from .users import User
from .exceptions import ResourceNotFound, UnauthorizedAccess, MissingConfig
from .config import __version__, __pypi_packagename__
+10 -2
View File
@@ -124,8 +124,16 @@ class Api(object):
"""
response = requests.request(method, url, **kwargs)
# logging.info("Response[{0}]: {1}".format(response.status_code, response.reason))
return self.handle_response(response, response.content.decode('utf-8'))
# logging.info("Response[{0}]: {1}".format(response.status_code, reisponse.reason))
try:
error = self.handle_response(response,
response.content.decode('utf-8'))
except:
print (response.content)
raise
return error
def handle_response(self, response, content):
"""Check HTTP response codes
-2
View File
@@ -180,8 +180,6 @@ class Update(Resource):
attributes.pop('_created')
attributes.pop('_updated')
attributes.pop('_links')
if 'parent' in attributes:
attributes.pop('parent')
url = utils.join_url(self.path, str(self['_id']))
headers = utils.merge_dict(
self.http_headers(),
+12
View File
@@ -0,0 +1,12 @@
from .resource import List
from .resource import Find
from .resource import Create
from .resource import Post
from .resource import Update
from .resource import Delete
class User(List, Find, Create, Post, Update, Delete):
"""User class wrapping the REST nodes endpoint
"""
path = "users"