Beispiel #1
0
    def sync_lead(self, marketo_id=None, email=None, marketo_cookie=None, foreign_id=None, attributes=None):
        """
        This function will insert or update a single lead record.
                When updating an existing lead, the lead can be identified with one of the following keys:

        If an existing match is found, the call will perform an update.
        If not, it will insert and create a new lead.
        Anonymous leads can be updated using the Marketo Cookie ID.
        http://developers.marketo.com/documentation/soap/synclead/

        :param marketo_id:
        :param email:
        :param marketo_cookie:
        :param foreign_id:
        :param attributes:
        :return: :raise exceptions.unwrap:
        """
        if not (marketo_id or email or marketo_cookie or foreign_id):
            raise ValueError('Must supply at least one id for the lead.')

        if not attributes:
            raise ValueError('Must supply attributes as a non empty iterable object.')

        body = sync_lead.wrap(marketo_id=marketo_id,
                              email=email,
                              marketo_cookie=marketo_cookie,
                              foreign_id=foreign_id,
                              attributes=attributes)

        response = self.request(body)

        if response.status_code == 200:
            return sync_lead.unwrap(response.text.encode("utf-8"))
        else:
            raise exceptions.unwrap(response.text)
Beispiel #2
0
    def test_non_xml_message(self):
        exception_message = 'Non XML message'
        exception_instance = exceptions.unwrap(exception_message)

        self.assertTrue(isinstance(exception_instance,
                                   exceptions.MktException))
        self.assertEqual(exception_instance.args,
                         ("Marketo exception message parsing error: %s" %
                          exception_message, ))
Beispiel #3
0
    def test_fault_without_details(self):
        exception_message = '<?xml version="1.0" encoding="UTF-8"?>' \
                            '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">' \
                            '<SOAP-ENV:Body>' \
                            '<SOAP-ENV:Fault>' \
                            '<faultcode>SOAP-ENV:Client</faultcode>' \
                            '<faultstring>Bad Request</faultstring>' \
                            '</SOAP-ENV:Fault>' \
                            '</SOAP-ENV:Body>' \
                            '</SOAP-ENV:Envelope>'
        exception_instance = exceptions.unwrap(exception_message)

        self.assertTrue(isinstance(exception_instance, exceptions.MktException))
        self.assertEqual(exception_instance.args, ("Bad Request", ))
Beispiel #4
0
    def get_lead(self,
                 idnum=None,
                 cookie=None,
                 email=None,
                 sfdcleadid=None,
                 leadowneremail=None,
                 sfdcaccountid=None,
                 sfdccontactid=None,
                 sfdcleadownerid=None,
                 sfdcopptyid=None,
                 **kwargs):
        """
        This function retrieves a single lead record from Marketo.
        If the lead exists based on the input parameters, the lead record attributes will be returned in the result.
        http://developers.marketo.com/documentation/soap/getlead/

        :param idnum: The Marketo ID
        :param cookie: The value generated by the Munchkin Javascript
        :param email: The email address associated with the lead
        :param sfdcleadid: The lead ID from SalesForce
        :param leadowneremail: The Lead Owner Email
        :param sfdcaccountid: The Account ID from SalesForce
        :param sfdccontactid: The Contact ID from SalesForce
        :param sfdcleadownerid: The Lead owner ID from SalesForce
        :param sfdcopptyid: The Opportunity ID from SalesForce
        :param kwargs: For other keytypes in the future...
        :return: :raise exceptions.unwrap:
        """
        # collect all keyword arguments
        key_types = locals().copy()
        del key_types["self"]
        del key_types["kwargs"]
        key_types.update(kwargs)
        for each in key_types.keys():
            if not key_types[each]:
                del key_types[each]

        if len(key_types) != 1:
            raise exceptions.MktException(
                "get_leads() takes exactly 1 keyword argument (%d given)" %
                len(key_types))

        body = get_lead.wrap(*(key_types.items()[0]))

        response = self.request(body)

        if response.status_code == 200:
            return get_lead.unwrap(response.text.encode("utf-8"))
        else:
            raise exceptions.unwrap(response.text)
Beispiel #5
0
    def test_fault_without_details(self):
        exception_message = '<?xml version="1.0" encoding="UTF-8"?>' \
                            '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">' \
                            '<SOAP-ENV:Body>' \
                            '<SOAP-ENV:Fault>' \
                            '<faultcode>SOAP-ENV:Client</faultcode>' \
                            '<faultstring>Bad Request</faultstring>' \
                            '</SOAP-ENV:Fault>' \
                            '</SOAP-ENV:Body>' \
                            '</SOAP-ENV:Envelope>'
        exception_instance = exceptions.unwrap(exception_message)

        self.assertTrue(isinstance(exception_instance,
                                   exceptions.MktException))
        self.assertEqual(exception_instance.args, ("Bad Request", ))
Beispiel #6
0
    def test_fault_with_details(self):
        exception_message = '<?xml version="1.0" encoding="UTF-8"?>' \
                            '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">' \
                            '<SOAP-ENV:Body>' \
                            '<SOAP-ENV:Fault>' \
                            '<faultcode>SOAP-ENV:Client</faultcode>' \
                            '<faultstring>20103 - Lead not found</faultstring>' \
                            '<detail>' \
                            '<ns1:serviceException xmlns:ns1="http://www.marketo.com/mktows/">' \
                            '<name>mktServiceException</name>' \
                            '<message>No lead found with EMAIL = [email protected] (20103)</message>' \
                            '<code>20103</code>' \
                            '</ns1:serviceException>' \
                            '</detail>' \
                            '</SOAP-ENV:Fault>' \
                            '</SOAP-ENV:Body>' \
                            '</SOAP-ENV:Envelope>'
        exception_instance = exceptions.unwrap(exception_message)

        self.assertTrue(isinstance(exception_instance, exceptions.MktLeadNotFound))
        self.assertEqual(exception_instance.args, ("No lead found with EMAIL = [email protected] (20103)", ))
Beispiel #7
0
    def get_lead(self, idnum=None, cookie=None, email=None, sfdcleadid=None, leadowneremail=None,
                 sfdcaccountid=None, sfdccontactid=None, sfdcleadownerid=None, sfdcopptyid=None, **kwargs):
        """
        This function retrieves a single lead record from Marketo.
        If the lead exists based on the input parameters, the lead record attributes will be returned in the result.
        http://developers.marketo.com/documentation/soap/getlead/

        :param idnum: The Marketo ID
        :param cookie: The value generated by the Munchkin Javascript
        :param email: The email address associated with the lead
        :param sfdcleadid: The lead ID from SalesForce
        :param leadowneremail: The Lead Owner Email
        :param sfdcaccountid: The Account ID from SalesForce
        :param sfdccontactid: The Contact ID from SalesForce
        :param sfdcleadownerid: The Lead owner ID from SalesForce
        :param sfdcopptyid: The Opportunity ID from SalesForce
        :param kwargs: For other keytypes in the future...
        :return: :raise exceptions.unwrap:
        """
        # collect all keyword arguments
        key_types = locals().copy()
        del key_types["self"]
        del key_types["kwargs"]
        key_types.update(kwargs)
        for each in key_types.keys():
            if not key_types[each]:
                del key_types[each]

        if len(key_types) != 1:
            raise exceptions.MktException("get_leads() takes exactly 1 keyword argument (%d given)" % len(key_types))

        body = get_lead.wrap(*(key_types.items()[0]))

        response = self.request(body)

        if response.status_code == 200:
            return get_lead.unwrap(response.text.encode("utf-8"))
        else:
            raise exceptions.unwrap(response.text)
Beispiel #8
0
    def test_fault_with_details(self):
        exception_message = '<?xml version="1.0" encoding="UTF-8"?>' \
                            '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">' \
                            '<SOAP-ENV:Body>' \
                            '<SOAP-ENV:Fault>' \
                            '<faultcode>SOAP-ENV:Client</faultcode>' \
                            '<faultstring>20103 - Lead not found</faultstring>' \
                            '<detail>' \
                            '<ns1:serviceException xmlns:ns1="http://www.marketo.com/mktows/">' \
                            '<name>mktServiceException</name>' \
                            '<message>No lead found with EMAIL = [email protected] (20103)</message>' \
                            '<code>20103</code>' \
                            '</ns1:serviceException>' \
                            '</detail>' \
                            '</SOAP-ENV:Fault>' \
                            '</SOAP-ENV:Body>' \
                            '</SOAP-ENV:Envelope>'
        exception_instance = exceptions.unwrap(exception_message)

        self.assertTrue(
            isinstance(exception_instance, exceptions.MktLeadNotFound))
        self.assertEqual(exception_instance.args,
                         ("No lead found with EMAIL = [email protected] (20103)", ))
Beispiel #9
0
    def test_non_xml_message(self):
        exception_message = 'Non XML message'
        exception_instance = exceptions.unwrap(exception_message)

        self.assertTrue(isinstance(exception_instance, exceptions.MktException))
        self.assertEqual(exception_instance.args, ("Marketo exception message parsing error: %s" % exception_message, ))