Exemplo n.º 1
0
    def get_all(cls):
        """
        Gets all programs
        
        :return: 
        """
        all_programs = []
        select = 1000
        skip = 0

        response = connection.get(cls.end_point,
                                  query_params={
                                      'Select': select,
                                      'Skip': skip
                                  })
        programs = [cls(**entry) for entry in response]
        num_of_programs = len(programs)

        while num_of_programs > 0:
            all_programs.extend(programs)

            if num_of_programs < select:
                break

            skip += select
            response = connection.get(cls.end_point,
                                      query_params={
                                          'Select': select,
                                          'Skip': skip
                                      })
            programs = [cls(**entry) for entry in response]
            num_of_programs = len(programs)

        return programs
Exemplo n.º 2
0
 def get_multiple(cls, select=1000, skip=0):
     response = connection.get(cls.end_point,
                               query_params={
                                   'select': select,
                                   'skip': skip
                               })
     return [cls(**entry) for entry in response]
Exemplo n.º 3
0
    def get_stats(cls, since_date, end_date, aggregate_by):
        """
        This operation retrieves your transactional email reporting 
        statistics (number sent, delivered, opens, clicks, ISP 
        complaints and bounces) for a specified time period.

        This time period can be set with a specific end date, or 
        statistics can be aggregated by all time, week, month or day.
        
        :param since_date: A date/datetime object which represents the
            start date for which transactional email reporting 
            statistics will be returned.
        :param end_date: A date/datetime object which represents the end
            date up to which transactional email reporting wil be 
            returned (inclusive). 
        :param aggregate_by: The data aggregation period for 
            transactional email reporting statistics
            
        :return: 
        """

        return connection.get(
            '{}/stats/since-date/{}'.format(
                cls.end_point, since_date.strftime('%Y-%m-%d')
            ),
            query_params={
                'EndDate': end_date.strftime('%Y-%m-%d'),
                'AggregatedBy': aggregate_by
            }
        )
Exemplo n.º 4
0
    def get_multiple(cls, select=1000, skip=0):
        """
        Gets all address books within the specified limits.  This function
        performs a query to return all the address books, limited by the
        select and skip values.  To easily get all the address books
        associated with the account call :func:`~AddressBook.get_all`.

        :param select: The select parameter requires a number between 1
        and 1000 (0 is not a valid number). You may only select a maximum
        of 1000 results in a single request. This parameter goes within
        the URL.
        :param skip: The skip parameter should be used in tandem with the
        select parameter when wanting to iterate through a whole data set.
        If you want to select the next 1000 records you should set the
        select parameter to 1000 and the skip parameter to 1000, which will
        return records 1001 to 2000. You should continue to do this until
        0 records are returned to retrieve the whole data set. This
        parameter goes within the URL.
        :return:
        """
        # TODO: Add some validation in for the parameter data types
        response = connection.get(cls.end_point,
                                  query_params={
                                      'Select': select,
                                      'Skip': skip
                                  })
        return [cls(**entry) for entry in response]
Exemplo n.º 5
0
 def get(cls, select=1000, skip=0):
     response = connection.get('{}'.format(cls.end_point),
                               query_params={
                                   'select': select,
                                   'skip': skip
                               })
     return [Segment(**entry) for entry in response]
Exemplo n.º 6
0
    def get_all(cls):
        """Gets all campaigns

        :return: List of Campaigns
        """
        all_campaigns = []
        select = 1000
        skip = 0

        while True:
            response = connection.get(cls.end_point,
                                      query_params={
                                          'Select': select,
                                          'Skip': skip
                                      })
            campaigns = [cls(**campaign) for campaign in response]
            all_campaigns.extend(campaigns)

            if len(campaigns) < select:
                # This means there are no more campaigns to fetch.
                break

            skip += select

        return all_campaigns
Exemplo n.º 7
0
    def get_by_id(cls, id):
        id = int(id)

        if id < 1:
            raise Exception()

        response = connection.get('{}/{}'.format(cls.end_point, id))
        return cls(**response)
Exemplo n.º 8
0
 def get_scores_modified_since(cls, date, select, skip):
     response = connection.get('{}/score/modified-since/{}'.format(
         cls.end_point, date.strftime('%Y-%m-%d')),
                               query_params={
                                   'Select': select,
                                   'Skip': skip
                               })
     return [ContactScore(**entry) for entry in response]
Exemplo n.º 9
0
    def get_account_information():
        """
        Gets a summary of information about the current status of the
        account

        :return:
        """
        return connection.get('/v2/account-info')
Exemplo n.º 10
0
 def get_score_by_id(cls, id):
     """
     Gets contact scoring for a contact by ID
     
     :param id: 
     :return: 
     """
     response = connection.get('{}/{}/score'.format(cls.end_point, id))
     return ContactScore(**response)
Exemplo n.º 11
0
    def get_by_email(cls, email):
        """
        Gets a contact by email address

        :param email:
        :return:
        """
        response = connection.get(cls.end_point + '/' + email)
        return cls(**response)
Exemplo n.º 12
0
 def get_contact_import_report(cls, id):
     """
     Gets a report with statistics about what was successfully 
     imported, and what was unable to be imported.
     
     :param id: 
     :return: 
     """
     return connection.get('{}/import/{}/report'.format(cls.end_point, id))
Exemplo n.º 13
0
    def get_score_by_email(cls, email):
        """
        Gets contact scoring for a contact by email address

        :param email: 
        :return: 
        """
        response = connection.get('{}/{}/score'.format(cls.end_point, email))
        return ContactScore(**response)
Exemplo n.º 14
0
    def get_by_id(cls, id):
        """
        Gets a program enrolment by ID

        :param id: The ID of the enrolment.  This ID is a GUID and 
            looking something like b0ff06d6-af04-4af8-a299-51bcbad94c1c
        :return: 
        """
        response = connection.get('{}/{}'.format(cls.end_point, id))
        return cls(**response)
Exemplo n.º 15
0
 def get_contact_import_status(cls, id):
     """
     Gets the import status of a previously started contact import.
     
     :param id: The bulk upload ID value returned when you submitted
      a bulk upload request.  The ID is a GUID and should look similar
      to 842d81e8-c619-457f-bb77-ab6c4a17da39.
     :return: A dictionary that contains an the keys 'id' and 'status'.
     """
     return connection.get('{}/imports/{}'.format(cls.end_point, id))
Exemplo n.º 16
0
    def get_by_id(cls, id):
        """
        Gets a contact by ID

        :param id:
        :return:
        """
        # TODO: Add some type checking in to make sure that the value supplied is actually an int
        response = connection.get('{}/{}'.format(cls.end_point, id))
        return cls(**response)
Exemplo n.º 17
0
 def get_survey_fields(cls, id):
     """
     Gets a list of survey pages, each containing a list of the 
     fields on that page
     
     :param id: 
     :return: 
     """
     response = connection.get('{}/{}/fields'.format(cls.end_point, id))
     return response
Exemplo n.º 18
0
    def get_multiple_custom_from_addresses(select=1000, skip=0):
        """
        Gets all custom from addresses which can be used in a campaign

        :return:
        """
        return connection.get('/v2/custom-from-addresses',
                              query_params={
                                  'Select': select,
                                  'Skip': skip
                              })
Exemplo n.º 19
0
 def get_faults(cls, id):
     """
     Gets all contacts that were not successfully enrolled, by 
     enrolment ID
     
     :param id: The ID of the enrolment.  This ID is a GUID and 
         looking something like b0ff06d6-af04-4af8-a299-51bcbad94c1c
     :return: 
     """
     response = connection.get('{}/{}/report-faults'.format(
         cls.end_point, id))
     return response
Exemplo n.º 20
0
def get_server_time():
    """
    Gets the UTC time as set on the server.
    
    This function returns the UTC time as set on the server so you 
    can be sure that any dateTime dependent calls that you make are 
    going to happen at the time you think they will.
    
    :return: The time on the server represented as a DateTime object
     with the correct timezone applied.
    """
    return date_parser(connection.get('/v2/server-time'))
Exemplo n.º 21
0
    def get_all(cls):
        """
        Attempt to get a list of all the templates that you have associated
        with your account.
        
        This function continues to request for more templates until the 
        server doesn't return any more templates.
        
        :return: A list containing :class:`Template` objects that \
        represents all the templates that are associated with your account        
        """
        all_templates = []
        select = 1000
        skip = 0

        response = connection.get(cls.end_point,
                                  query_params={
                                      'Select': select,
                                      'Skip': skip
                                  })
        templates = [cls(**entry) for entry in response]
        num_of_templates = len(templates)

        while num_of_templates > 0:
            all_templates.extend(templates)

            if num_of_templates < select:
                break

            skip += select
            response = connection.get(cls.end_point,
                                      query_params={
                                          'Select': select,
                                          'Skip': skip
                                      })

            templates = [cls(**entry) for entry in response]
            num_of_templates = len(templates)

        return all_templates
Exemplo n.º 22
0
 def get_scoring(cls, select, skip):
     """
     
     :param select: 
     :param skip: 
     :return: 
     """
     response = connection.get('{}/score/'.format(cls.end_point),
                               query_params={
                                   'Select': select,
                                   'Skip': skip
                               })
     return [ContactScore(**entry) for entry in response]
Exemplo n.º 23
0
 def get_contacts_from_address_book(cls,
                                    address_book,
                                    with_full_data=True,
                                    select=1000,
                                    skip=0):
     response = connection.get('/v2/address-books/{}/contacts'.format(
         address_book.id),
                               query_params={
                                   'withFullData': with_full_data,
                                   'select': select,
                                   'skip': skip
                               })
     return [Contact(**entry) for entry in response]
Exemplo n.º 24
0
 def get_modified_contacts_since(cls,
                                 date,
                                 with_full_data=True,
                                 select=1000,
                                 skip=0):
     response = connection.get('{}/modified-since/{}'.format(
         cls.end_point, date.strftime('%Y-%m-%d')),
                               query_params={
                                   'withFullData': with_full_data,
                                   'select': select,
                                   'skip': skip
                               })
     return [Contact(**entry) for entry in response]
Exemplo n.º 25
0
    def get_all(cls):
        response = connection.get('{}'.format(cls.end_point))

        def _recursive_convert(entity):
            folder = cls(**entity)
            child_folders = entity.get('child_folders')
            if child_folders is not None and child_folders != []:
                folder.child_folders = []
                for child in child_folders:
                    folder.child_folders.append(_recursive_convert(child))
            return folder

        return [_recursive_convert(entry) for entry in response]
Exemplo n.º 26
0
    def get_public(cls, select=1000, skip=0):
        """
        Gets all public address books

        :param select:
        :param skip:
        :return:
        """
        # TODO: Add some validation in for the parameter data types
        response = connection.get(
            cls.end_point + '/public',
            query_params={'Select': select, 'Skip':skip}
        )
        return [cls(**entry) for entry in response]
Exemplo n.º 27
0
    def get_contact_fields(cls):
        """
        Lists all contact data fields within the account

        This operation returns a list of all the contact data fields within your 
        account.
        
        :return: 
        """
        response = connection.get(cls.end_point)
        custom_data_fields = []
        for entry in response:
            custom_data_fields.append(cls(**entry))
        return custom_data_fields
Exemplo n.º 28
0
    def get_by_id(cls, id):
        """
        Gets a program by ID

        :param id: The ID of the program
        :return: 
        """
        id = int(id)

        if id < 1:
            raise Exception()

        response = connection.get('{}/{}'.format(cls.end_point, id))
        return cls(**response)
Exemplo n.º 29
0
    def get_multiple(cls, select=1000, skip=0):
        """
        Gets a list of all contacts in the account

        :param select:
        :param skip:
        :return:
        """
        # TODO: Add some validation in for the parameter data types
        response = connection.get(cls.end_point,
                                  query_params={
                                      'Select': select,
                                      'Skip': skip
                                  })
        return [cls(**entry) for entry in response]
Exemplo n.º 30
0
 def get_modified_contacts_from_address_book_since(cls,
                                                   address_book,
                                                   date,
                                                   with_full_data=True,
                                                   select=1000,
                                                   skip=0):
     response = connection.get(
         '/v2/address-books/{}/contacts/modified-since/{}'.format(
             address_book.id, date.strftime('%Y-%m-%d')),
         query_params={
             'withFullData': with_full_data,
             'select': select,
             'skip': skip
         })
     return [Contact(**entry) for entry in response]