From 732f42e69079323f7b0d4f84823b7499041d0e36 Mon Sep 17 00:00:00 2001 From: Florian Roessler Date: Thu, 21 Dec 2017 14:05:15 +0000 Subject: [PATCH] adding a function to documents that allows to create a document from a requests response --- mendeley/resources/documents.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mendeley/resources/documents.py b/mendeley/resources/documents.py index 4fa8bea..9ee394b 100644 --- a/mendeley/resources/documents.py +++ b/mendeley/resources/documents.py @@ -99,6 +99,25 @@ def create_from_file(self, path): return UserAllDocument(self.session, rsp.json()) + def create_pdf_from_requests(self, f, filename,): + """ + Creates a new document from a pdf get requests response. + + :f: requests.content from get request of a pdf + :filename: name of the file. + :return: a :class:`UserDocument `. + """ + headers = { + 'content-disposition': 'attachment; filename=%s' % filename, + 'content-type': 'application/pdf', + 'accept': UserDocument.content_type + } + + # with open(path, 'rb') as f: + rsp = self.session.post('/documents', data=f, headers=headers) + + return UserAllDocument(self.session, rsp.json()) + def search(self, query, view=None): """ Searches the logged-in user's library for documents.