def open(self, recipient_id, subject, message): ''' Opens a new conversation thread. @param recipient:str ID of the recipient @param subject:str Subject of the thread @param message:str Message ''' if is_empty_or_none(recipient_id): raise ValueError("Invalid recipient ID") if is_empty_or_none(subject): raise ValueError("Invalid subject") if is_empty_or_none(message): raise ValueError("Invalid message") data = {"recipient":recipient_id, "subject":subject, "message":message} request = Request(self.__seller.client, method="POST", uri=self.get_uri(), data=data) response = request.get_response() if response.get_status_code() == 201: thread_id = extract_id_from_uri(response["Location"]) thread = self[thread_id] thread.sync(response.data, response["Etag"]) return thread
def send(self, xmli, signature=True): ''' Sends an invoice @param xmli:str Invoice XML representation. @return: InvoiceReport ''' xmli = to_byte_string(xmli) if not xmli: raise ValueError("Invalid XMLi") ''' XMLdsig: required PyCrypto + lxml ''' private_key, public_key = self.email.client.keys if signature and private_key and public_key: from greendizer import xmldsig xmli = xmldsig.sign(xmli, private_key, public_key) size = 0 try: from os import sys size = sys.getsizeof(xmli) except AttributeError: import base64 #2.5 and older... size = len(base64.encodestring(xmli)) #1 ASCII = 1 byte if size > MAX_CONTENT_LENGTH: raise ValueError("XMLi's size is limited to %skb." % MAX_CONTENT_LENGTH / 1024) request = Request(self.email.client, method="POST", data=xmli, uri=self._uri, content_type="application/xml") response = request.get_response() if response.status_code == 202: #Accepted return InvoiceReport(self.email, extract_id_from_uri(response["Location"]))