Пример #1
0
    def delete_multiple_contacts(self, id_list):
        """
        Deletes multiple contacts from an address book

        :param id_list:
        :return:
        """
        self.validate_id('Sorry, unable to delete contacts from this address '
                         'book, as no ID value has been defined for the '
                         'address book.')
        connection.post(
            '{}/{}/contacts/delete'.format(self.end_point, self.id), id_list)
Пример #2
0
    def bulk_create(cls, filedata):
        """
        Bulk creates, or bulk updates, contacts.
        
        This function allows you to upload a bulk number of contacts to 
        the server.  The contact data must be in either a CSV or Excel
        format, and it must include one column that is called 'Email' or
        equivalent if your account is using a language other than 
        English.  All other columns will be mapped to your custom contact
        data fields.
        
        Currently DotMailer place a file upload limit of 10MB.  If your
        data is larger than this then you will need to split it into
        small chunks.
        
        The API will return an ID for the import, and the current status.
        You can re-query the import status later, by using the unique
        ID value.
        
        :param filedata:  Either a file or filepath which can be read from 
        :return: 
        """

        url = '{}/import'.format(cls.end_point)

        return connection.post(url, {}, files={'file': filedata})
Пример #3
0
    def bulk_create_in_address_book(cls, address_book, filedata):
        """
        Bulk creates, or bulk updates, contacts in an address book.
        
        Similar to the bulk create verions, this function can be used to
        create a bulk number of contacts in one go.  However, this
        version will also automatically associate the contact with the
        address book that has been specified.  The contact data must be 
        in either a CSV or Excel format, and it must include one column 
        that is called 'Email' or equivalent if your account is using a 
        language other than English.  All other columns will be mapped 
        to your custom contact data fields.
        
        Currently DotMailer place a file upload limit of 10MB.  If your
        data is larger than this then you will need to split it into
        small chunks.
        
        The API will return an ID for the import, and the current status.
        You can re-query the import status later, by using the unique
        ID value.
        
        :param address_book: 
        :param filedata: 
        :return: 
        """

        url = '/v2/address-books/{}/contacts/import'.format(address_book.id)

        return connection.post(url, {}, files={'file': filedata})
Пример #4
0
    def send_time_optimised(self, address_book_ids=None, contact_ids=None):
        """
        Sends a specified campaign to one or more address books,
        segments or contacts at the most appropriate time based upon
        their previous opens.

        :param address_book_ids:
        :param contact_ids:
        :return:
        """
        self.validate_id('Unable to send campaign, as no ID is defined for the'
                         'campaign')

        # TODO: Add some validation to the when value before proceeding to use it
        payload = {}

        if address_book_ids is not None:
            payload['AddressBookIDs'] = address_book_ids
        if contact_ids is not None:
            payload['ContactIDs'] = contact_ids

        # If no possible contact address have been specified then raise
        # an exception, as the caller is trying to send a campaing to
        # no-one.
        if payload == {}:
            raise Exception
        response = connection.post('{}/send'.format(self.end_point), payload)

        send = CampaignSends(**response)
        self.sends[send.id] = send
        return self
Пример #5
0
 def send(self):
     print self.param_dict()
     response = connection.post(
         self.end_point,
         self.param_dict()
     )
     return response
Пример #6
0
    def send_transactional_triggered_campaign(cls, to_addresses, campaign_id, personalisation_values=None):
        """
        
        :param to_addresses: A list of email addresses which the campaign should be sent to.
        :param campaign_id: The DotMailer ID value of the campaign you wish to trigger.
        :param personalisation_values: A dictionary of any personalisation values that should be used to fill in the
         email.
        :return: 
        """


        # TODO: Waiting to hear back from DotMailer to find out if you send multiple recipients how personalisation values are handled
        param_data = {
            'toAddresses': to_addresses,
            'campaignId': campaign_id
        }
        if personalisation_values is not None:
            param_data['personalizationValues'] = [
                {'Name': key, 'Value': value} for key, value in personalisation_values.items()
            ]

        return connection.post(
            '{}/triggered-campaign'.format(cls.end_point),
            param_data
        )
Пример #7
0
 def _create(self, folder):
     if self.local_path is None:
         raise Exception('No local path to the file')
     with open(self.local_path, 'r') as file_data:
         response = connection.post(self.end_point.format(folder.id),
                                    files={'file': file_data})
         response['local_path'] = None
         return self._update_values(response)
Пример #8
0
    def create(self):
        """
        Creates a contact

        :return:
        """
        response = connection.post(self.end_point, self.param_dict())
        self._update_values(response)
Пример #9
0
 def create(self):
     """
     Create a new DotMailer template.
     
     This function will issue the create request to DotMailer's API,
     passing through all the information you have defined. 
     """
     response = connection.post(self.end_point, self.param_dict())
     self._update_values(response)
Пример #10
0
 def unsubscribe(cls, email):
     """
     Unsubscribes contact from account
     
     :param email: 
     :return: 
     """
     return connection.post('{}/unsubscribe'.format(cls.end_point),
                            {'Email': email})
Пример #11
0
    def create(self):
        """
        Create a campaign

        :return:
        """

        # TODO: Confirm that if I send "null" values that campaign will still be created correctly
        response = connection.post(self.end_point, self.param_dict())
        self._update_values(response)
        return self
Пример #12
0
    def copy(cls, id):
        """
        Copies a given campaign, returning the new campaign

        :param id:
        :return:
        """
        id = int(id)
        if id < 1:
            raise Exception()

        response = connection.post('{}/{}'.format(cls.end_point, id))
        return cls(**response)
Пример #13
0
    def resubscribe(cls,
                    email,
                    preferred_local=None,
                    return_url_to_use_if_challenged=None):
        payload = {'UnsubscribedContact': {'Email': email}}
        if preferred_local is not None:
            payload['PreferredLocale'] = preferred_local
        if return_url_to_use_if_challenged is not None:
            payload[
                'ReturnUrlToUseIfChallenged'] = return_url_to_use_if_challenged

        response = connection.post('{}/resubscribe'.format(cls.end_point),
                                   payload)
        return Contact(**response['contact']), response['status']
Пример #14
0
    def add_contact(self, contact):
        """
        Adds a contact to a given address book

        :param contact:
        :return:
        """

        self.validate_id('Sorry, unable to add contact to the address book '
                         'as no ID value has been defined for the address '
                         'book.')

        response = connection.post(
            '{}/{}/contacts'.format(self.end_point, self.id),
            contact.param_dict())
        contact._update_values(response)
Пример #15
0
    def create(self):
        """
        Creates an address book.  If the current instance is associated
        with a DotMailer ID then an exception will be raised.
        
        :return: 
        """

        if not self.valid_name(self.name):
            raise Exception('Invalid address book name.')

        if self.id is not None:
            raise Exception('This address book already has a DotMailer ID')

        response = connection.post(self.end_point, self.param_dict())
        self._update_values(response)
Пример #16
0
    def send(self, when=None, address_book_ids=None, contact_ids=None):
        """
        Sends a specified campaign to one or more address books,
        segments or contacts, either as an immediate or scheduled send

        :param when: A date time object which should define when the
        campaign should be sent.  If None then it will be sent
        immediately.
        :param address_book_ids:
        :param contact_ids:
        :return:
        """
        self.validate_id('Unable to send campaign, as no ID is defined for the'
                         'campaign')

        # TODO: Add some validation to the when value before proceeding to use it
        payload = {}

        if address_book_ids is not None:
            payload['AddressBookIDs'] = address_book_ids
        if contact_ids is not None:
            payload['ContactIDs'] = contact_ids

        # If no possible contact address have been specified then raise
        # an exception, as the caller is trying to send a campaing to
        # no-one.
        if payload == {}:
            raise Exception

        if when is not None:
            payload['SendDate'] = self.strftime(when)

        response = connection.post('{}/send'.format(self.end_point), payload)

        send = CampaignSends(**response)
        self.sends[send.id] = send
        return self
Пример #17
0
    def create(self):
        """
        Creates a contact data field within the account.
        
        This operation can be used to create a contact data field within your 
        account.  
        
        You can't create a contact data field that already exists. If you are 
        unsure which data fields currently exist, please call 
        get_contact_fields.

        The contact data field's name can only be up to 20 characters in length 
        and must consist of alphanumeric characters only, with hyphens and 
        underscores if required. The contact data field that is created will be 
        private by default. The amount of contact data fields you can create 
        will be limited by the account type you have.
        
        :return: 
        """
        if not self.valid_name(self.name):
            raise Exception(self.invalid_name_msg)

        response = connection.post(self.end_point, self.param_dict())
        self._update_values(response)
Пример #18
0
 def create(self):
     response = connection.post(
         '{}/{}'.format(self.end_point, self.parent_id), self.param_dict())
     self._update_values(response)
Пример #19
0
 def refresh(self):
     response = connection.post('{}/refresh/{}'.format(
         self.end_point, self.id))
     self._update_values(response)