From 9fc01b219c411ec7269e4174baf20d791147828d Mon Sep 17 00:00:00 2001 From: Eibriel Date: Tue, 21 Apr 2015 17:30:22 -0300 Subject: [PATCH] WIP support fs.files --- attractsdk/__init__.py | 1 + attractsdk/binary_files.py | 28 ++++++++++++++++++++++++++++ attractsdk/files.py | 28 ---------------------------- attractsdk/nodes.py | 26 -------------------------- 4 files changed, 29 insertions(+), 54 deletions(-) create mode 100755 attractsdk/binary_files.py diff --git a/attractsdk/__init__.py b/attractsdk/__init__.py index 2eeaccd..9e759e5 100644 --- a/attractsdk/__init__.py +++ b/attractsdk/__init__.py @@ -3,5 +3,6 @@ from .nodes import Node from .nodes import NodeType from .users import User from .files import File +from .binary_files import binaryFile from .exceptions import ResourceNotFound, UnauthorizedAccess, MissingConfig from .config import __version__, __pypi_packagename__ diff --git a/attractsdk/binary_files.py b/attractsdk/binary_files.py new file mode 100755 index 0000000..3133733 --- /dev/null +++ b/attractsdk/binary_files.py @@ -0,0 +1,28 @@ +from .resource import List +from .resource import Find +from .resource import Create +from .resource import Post +from .resource import Update +from .resource import Delete +from .resource import Replace + +from . import utils + + +class binaryFile(List, Find, Create, Post, Update, Delete, Replace): + """binaryFile class wrapping the REST binary_files endpoint + """ + path = "binary_files" + + def post_file(self, file_, api=None): + """Stores a file on the database. + :param file: A file object + """ + api = api or self.api + url = utils.join_url(self.path) + files = {'data': file_} + print (files) + new_attributes = api.post(url, {}, {}, files) + # self.error = None + self.merge(new_attributes) + return self.success() diff --git a/attractsdk/files.py b/attractsdk/files.py index 824923f..9e97fa8 100755 --- a/attractsdk/files.py +++ b/attractsdk/files.py @@ -6,36 +6,8 @@ from .resource import Update from .resource import Delete from .resource import Replace -from . import utils - class File(List, Find, Create, Post, Update, Delete, Replace): """Node class wrapping the REST nodes endpoint """ path = "files" - - def replace_picture(self, picture_file, api=None): - """Replaces the picture field in the node. - :param picture_file: A file object - """ - api = api or self.api - attributes = self.to_dict() - etag = attributes['_etag'] - attributes.pop('_id') - attributes.pop('_etag') - attributes.pop('_created') - attributes.pop('_updated') - attributes.pop('_links') - if 'parent' in attributes: - attributes.pop('parent') - if 'properties' not in attributes: - attributes['properties'] = {} - url = utils.join_url(self.path, str(self['_id'])) - headers = utils.merge_dict( - self.http_headers(), - {'If-Match': str(etag)}) - files = {'picture': picture_file} - new_attributes = api.patch(url, attributes, headers, files) - self.error = None - self.merge(new_attributes) - return self.success() diff --git a/attractsdk/nodes.py b/attractsdk/nodes.py index 52a57f1..bd4d017 100755 --- a/attractsdk/nodes.py +++ b/attractsdk/nodes.py @@ -14,32 +14,6 @@ class Node(List, Find, Create, Post, Update, Delete, Replace): """ path = "nodes" - def replace_picture(self, picture_file, api=None): - """Replaces the picture field in the node. - :param picture_file: A file object - """ - api = api or self.api - attributes = self.to_dict() - etag = attributes['_etag'] - attributes.pop('_id') - attributes.pop('_etag') - attributes.pop('_created') - attributes.pop('_updated') - attributes.pop('_links') - if 'parent' in attributes: - attributes.pop('parent') - if 'properties' not in attributes: - attributes['properties'] = {} - url = utils.join_url(self.path, str(self['_id'])) - headers = utils.merge_dict( - self.http_headers(), - {'If-Match': str(etag)}) - files = {'picture': picture_file} - new_attributes = api.patch(url, attributes, headers, files) - self.error = None - self.merge(new_attributes) - return self.success() - class NodeType(List, Find, Create, Post, Delete): """NodeType class wrapping the REST node_types endpoint