Ejemplo n.º 1
0
 def buyer(self):
     '''
     Gets the buyer.
     @return: Buyer
     '''
     buyer_uri = (self._get_attribute("buyer") or {}).get("uri", None)
     return self.client.seller.buyers[extract_id_from_uri(buyer_uri)]
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
 def company(self):
     """
     Gets the seller's company info.
     @return: greendizer.resources.Company
     """
     company_id = extract_id_from_uri(self._get_attribute("companyURI"))
     return Company(self.__email, company_id)
Ejemplo n.º 4
0
 def seller(self):
     """
     Gets the seller with which the thread was opened.
     @return: Company
     """
     seller_id = extract_id_from_uri(self._get_attribute("sellerURI"))
     return Seller(self.client, seller_id)
Ejemplo n.º 5
0
 def seller(self):
     """
     Gets the seller who sent the invoice.
     @return: Seller
     """
     seller_id = extract_id_from_uri(self._get_attribute("sellerURI"))
     return Seller(self.email, seller_id)
Ejemplo n.º 6
0
 def buyer(self):
     '''
     Gets the buyer.
     @return: Buyer
     '''
     if not self.is_from_current_user:
         buyer_id = extract_id_from_uri(self._get_attribute("buyerURI"))
         return self.thread.seller.buyers[buyer_id]
Ejemplo n.º 7
0
    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"]))