diff --git a/README.md b/README.md index a2670d6..3adb772 100644 --- a/README.md +++ b/README.md @@ -60,14 +60,17 @@ access key can be found Simply add `count` and `offset` arguments in your function. The count is how many records to return, the offset is how many records to skip. For endpoints that allow the pagination parameters, the all() method -has an additional boolean `get_all` argument that will loop through all -records until the API no longer returns any to get all records without -manually performing an additional query. By default, count is 10 and -offset is 0 for all endpoints that support it. The `get_all` parameter -on the all() method on any endpoint defaults to false, which follows -the values that are provided in the call, and using `get_all=True` will -ignore the provided count and offset to ensure that all records are -returned. When using get_all, the count will be 5000, to fetch large +has two additional booleans: `get_all` and `iterate`. By default +`count` defaults to 10 and `offset` to 0. Setting either `get_all` or +`iterate` to true will ignore both `count` and `offset`. Setting +`iterate` and `get_all` both to true will result in a `ValueError`. + +The `iterate` argument will cause the method to return a generator +allowing the caller to iterate over each page without having to handle +the pagination. + +The `get_all` will collect all values and return them as a single result. +When using get_all, the count will be 5000, to fetch large numbers of records without flooding the system with requests. The large size of count should not impact calls which are expected to return a very small number of records, and should improve performance for calls diff --git a/README.rst b/README.rst index e992fba..e1a4851 100644 --- a/README.rst +++ b/README.rst @@ -67,22 +67,25 @@ access key can be found Pagination ~~~~~~~~~~ -Simply add ``count`` and ``offset`` arguments in your function. The -count is how many records to return, the offset is how many records to -skip. For endpoints that allow the pagination parameters, the all() -method has an additional boolean ``get_all`` argument that will loop -through all records until the API no longer returns any to get all -records without manually performing an additional query. By default, -count is 10 and offset is 0 for all endpoints that support it. The -``get_all`` parameter on the all() method on any endpoint defaults to -false, which follows the values that are provided in the call, and using -``get_all=True`` will ignore the provided count and offset to ensure -that all records are returned. When using get_all, the count will be -5000, to fetch large numbers of records without flooding the system with -requests. The large size of count should not impact calls which are -expected to return a very small number of records, and should improve -performance for calls where fetching 5000 records would only provide a -fraction by preventing the delay of making a huge number of requests. +Simply add ``count`` and ``offset`` arguments in your function. The count +is how many records to return, the offset is how many records to skip. +For endpoints that allow the pagination parameters, the all() method +has two additional booleans: ``get_all`` and ``iterate``. By default +``count`` defaults to 10 and ``offset`` to 0. Setting either ``get_all`` or +``iterate`` to true will ignore both ``count`` and ``offset``. Setting +``iterate`` and ``get_all`` both to true will result in a ``ValueError``. + +The ``iterate`` argument will cause the method to return a generator +allowing the caller to iterate over each page without having to handle +the pagination. + +The ``get_all`` will collect all values and return them as a single result. +When using get_all, the count will be 5000, to fetch large +numbers of records without flooding the system with requests. The large +size of count should not impact calls which are expected to return a +very small number of records, and should improve performance for calls +where fetching 5000 records would only provide a fraction by preventing +the delay of making a huge number of requests. :: diff --git a/mailchimp3/baseapi.py b/mailchimp3/baseapi.py index 39aadfd..5ff34f8 100644 --- a/mailchimp3/baseapi.py +++ b/mailchimp3/baseapi.py @@ -33,9 +33,27 @@ def _build_path(self, *args): """ return '/'.join(chain((self.endpoint,), map(str, args))) + def _list_result(self, url, get_all, iterate, **queryparams): + """ + Simplify list by returning the single page, all pages or iterates. + + :param get_all: Should the query get all results + :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` + """ + if get_all and iterate: + raise ValueError("Both get_all and iterate can't be True.") + if get_all: + return self._all(url=url, **queryparams) + elif iterate: + return self._iterate(url=url, **queryparams) + else: + return self._mc_client._get(url=url, **queryparams) + def _iterate(self, url, **queryparams): """ - Iterate over all pages for the given url. Feed in the result of self._build_path as the url. + Iterate over pages for the given url. Feed in the result of self._build_path as the url. :param url: The url of the endpoint :type url: :py:class:`str` @@ -57,17 +75,36 @@ def _iterate(self, url, **queryparams): queryparams.pop("offset", None) queryparams.pop("count", None) # Fetch results from mailchimp, up to first 1000 - result = self._mc_client._get(url=url, offset=0, count=1000, **queryparams) + page_size = 1000 + result = self._mc_client._get(url=url, offset=0, count=page_size, **queryparams) total = result['total_items'] # Fetch further results if necessary - if total > 1000: - for offset in range(1, int(total / 1000) + 1): - result = merge_results(result, self._mc_client._get( + if total > page_size: + yield result + for offset in range(1, int(total / page_size)): + yield self._mc_client._get( url=url, - offset=int(offset * 1000), - count=1000, + offset=int(offset * page_size), + count=page_size, **queryparams - )) - return result + ) else: # Further results not necessary - return result + yield result + + def _all(self, url, **queryparams): + """ + Iterate over all pages for the given url and return a single collection. + Feed in the result of self._build_path as the url. + + :param url: The url of the endpoint + :type url: :py:class:`str` + :param queryparams: The query string parameters + queryparams['fields'] = [] + queryparams['exclude_fields'] = [] + queryparams['count'] = integer + queryparams['offset'] = integer + """ + result = {} + for page in self._iterate(url, **queryparams): + result = merge_results(result, page) + return result diff --git a/mailchimp3/entities/authorizedapps.py b/mailchimp3/entities/authorizedapps.py index 24a9d52..9bac435 100644 --- a/mailchimp3/entities/authorizedapps.py +++ b/mailchimp3/entities/authorizedapps.py @@ -44,12 +44,14 @@ def create(self, data): return self._mc_client._post(url=self._build_path(), data=data) - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get a list of an account’s registered, connected applications. :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -57,10 +59,7 @@ def all(self, get_all=False, **queryparams): queryparams['offset'] = integer """ self.app_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) def get(self, app_id, **queryparams): diff --git a/mailchimp3/entities/automationemails.py b/mailchimp3/entities/automationemails.py index 1d31950..5d88f21 100644 --- a/mailchimp3/entities/automationemails.py +++ b/mailchimp3/entities/automationemails.py @@ -31,7 +31,7 @@ def __init__(self, *args, **kwargs): # Paid feature - def all(self, workflow_id, get_all=False, **queryparams): + def all(self, workflow_id, get_all=False, iterate=False, **queryparams): """ Get a summary of the emails in an Automation workflow. @@ -39,16 +39,16 @@ def all(self, workflow_id, get_all=False, **queryparams): :type workflow_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: the query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] """ self.workflow_id = workflow_id self.email_id = None - if get_all: - return self._iterate(url=self._build_path(workflow_id, 'emails'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(workflow_id, 'emails'), **queryparams) + url = self._build_path(workflow_id, 'emails') + return self._list_result(url, get_all, iterate, **queryparams) # Paid feature diff --git a/mailchimp3/entities/automations.py b/mailchimp3/entities/automations.py index 2b23993..e933ee5 100644 --- a/mailchimp3/entities/automations.py +++ b/mailchimp3/entities/automations.py @@ -34,21 +34,20 @@ def __init__(self, *args, **kwargs): # Paid feature - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get a summary of an account’s Automations. :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: the query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] """ self.workflow_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) # Paid feature diff --git a/mailchimp3/entities/batchoperations.py b/mailchimp3/entities/batchoperations.py index 2592977..8d5a161 100644 --- a/mailchimp3/entities/batchoperations.py +++ b/mailchimp3/entities/batchoperations.py @@ -53,12 +53,14 @@ def create(self, data): return self._mc_client._post(url=self._build_path(), data=data) - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get a summary of batch requests that have been made. :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -67,10 +69,7 @@ def all(self, get_all=False, **queryparams): """ self.batch_id = None self.operation_status = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) def get(self, batch_id, **queryparams): diff --git a/mailchimp3/entities/batchwebhooks.py b/mailchimp3/entities/batchwebhooks.py index 101f8eb..8a91d73 100644 --- a/mailchimp3/entities/batchwebhooks.py +++ b/mailchimp3/entities/batchwebhooks.py @@ -43,12 +43,14 @@ def create(self, data): return response - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get all webhooks that have been configured for batches. :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -56,10 +58,7 @@ def all(self, get_all=False, **queryparams): queryparams['offset'] = integer """ self.batch_webhook_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) def get(self, batch_webhook_id, **queryparams): diff --git a/mailchimp3/entities/campaignfeedback.py b/mailchimp3/entities/campaignfeedback.py index 65f8b34..f4395d7 100644 --- a/mailchimp3/entities/campaignfeedback.py +++ b/mailchimp3/entities/campaignfeedback.py @@ -51,7 +51,7 @@ def create(self, campaign_id, data, **queryparams): return response - def all(self, campaign_id, get_all=False, **queryparams): + def all(self, campaign_id, get_all=False, iterate=False, **queryparams): """ Get team feedback while you’re working together on a MailChimp campaign. @@ -60,16 +60,17 @@ def all(self, campaign_id, get_all=False, **queryparams): :type campaign_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] """ self.campaign_id = campaign_id self.feedback_id = None - if get_all: - return self._iterate(url=self._build_path(campaign_id, 'feedback'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(campaign_id, 'feedback'), **queryparams) + + url = self._build_path(campaign_id, 'feedback') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, campaign_id, feedback_id, **queryparams): diff --git a/mailchimp3/entities/campaignfolders.py b/mailchimp3/entities/campaignfolders.py index 6a50e0d..3617abe 100644 --- a/mailchimp3/entities/campaignfolders.py +++ b/mailchimp3/entities/campaignfolders.py @@ -43,12 +43,14 @@ def create(self, data): return response - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get all folders used to organize campaigns. :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -56,10 +58,7 @@ def all(self, get_all=False, **queryparams): queryparams['offset'] = integer """ self.folder_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) def get(self, folder_id, **queryparams): diff --git a/mailchimp3/entities/campaigns.py b/mailchimp3/entities/campaigns.py index 67ced35..0a1cc0d 100755 --- a/mailchimp3/entities/campaigns.py +++ b/mailchimp3/entities/campaigns.py @@ -106,7 +106,7 @@ def create(self, data): return response - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get all campaigns in an account. @@ -117,6 +117,8 @@ def all(self, get_all=False, **queryparams): :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -134,10 +136,7 @@ def all(self, get_all=False, **queryparams): queryparams['sort_dir'] = string """ self.campaign_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) def get(self, campaign_id, **queryparams): diff --git a/mailchimp3/entities/conversations.py b/mailchimp3/entities/conversations.py index 55905a5..a1f8549 100644 --- a/mailchimp3/entities/conversations.py +++ b/mailchimp3/entities/conversations.py @@ -29,12 +29,14 @@ def __init__(self, *args, **kwargs): # Paid feature - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get a list of conversations for the account. :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -45,10 +47,7 @@ def all(self, get_all=False, **queryparams): queryparams['campaign_id'] = string """ self.conversation_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) # Paid feature diff --git a/mailchimp3/entities/filemanagerfiles.py b/mailchimp3/entities/filemanagerfiles.py index 44cdf26..bfc67dc 100644 --- a/mailchimp3/entities/filemanagerfiles.py +++ b/mailchimp3/entities/filemanagerfiles.py @@ -48,12 +48,14 @@ def create(self, data): return response - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get a list of available images and files stored in the File Manager for the account. :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -67,10 +69,7 @@ def all(self, get_all=False, **queryparams): queryparams['sort_dir'] = string """ self.file_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) def get(self, file_id, **queryparams): diff --git a/mailchimp3/entities/filemanagerfolders.py b/mailchimp3/entities/filemanagerfolders.py index 64c22e3..90b5a4d 100755 --- a/mailchimp3/entities/filemanagerfolders.py +++ b/mailchimp3/entities/filemanagerfolders.py @@ -45,12 +45,14 @@ def create(self, data): return response - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get a list of all folders in the File Manager. :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -61,10 +63,7 @@ def all(self, get_all=False, **queryparams): queryparams['since_created_at'] = string """ self.folder_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) def get(self, folder_id, **queryparams): diff --git a/mailchimp3/entities/listabusereports.py b/mailchimp3/entities/listabusereports.py index 5b3a234..1269c38 100644 --- a/mailchimp3/entities/listabusereports.py +++ b/mailchimp3/entities/listabusereports.py @@ -25,7 +25,7 @@ def __init__(self, *args, **kwargs): self.report_id = None - def all(self, list_id, get_all=False, **queryparams): + def all(self, list_id, get_all=False, iterate=False, **queryparams): """ Get all abuse reports for a specific list. @@ -33,6 +33,8 @@ def all(self, list_id, get_all=False, **queryparams): :type list_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -41,10 +43,8 @@ def all(self, list_id, get_all=False, **queryparams): """ self.list_id = list_id self.report_id = None - if get_all: - return self._iterate(url=self._build_path(list_id, 'abuse-reports'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(list_id, 'abuse-reports'), **queryparams) + url = self._build_path(list_id, 'abuse-reports') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, list_id, report_id, **queryparams): diff --git a/mailchimp3/entities/listgrowthhistory.py b/mailchimp3/entities/listgrowthhistory.py index 2849a65..26e267d 100644 --- a/mailchimp3/entities/listgrowthhistory.py +++ b/mailchimp3/entities/listgrowthhistory.py @@ -24,7 +24,7 @@ def __init__(self, *args, **kwargs): self.month = None - def all(self, list_id, get_all=False, **queryparams): + def all(self, list_id, get_all=False, iterate=False, **queryparams): """ Get a month-by-month summary of a specific list’s growth activity. @@ -32,6 +32,8 @@ def all(self, list_id, get_all=False, **queryparams): :type list_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -40,10 +42,8 @@ def all(self, list_id, get_all=False, **queryparams): """ self.list_id = list_id self.month = None - if get_all: - return self._iterate(url=self._build_path(list_id, 'growth-history'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(list_id, 'growth-history'), **queryparams) + url = self._build_path(list_id, 'growth-history') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, list_id, month, **queryparams): diff --git a/mailchimp3/entities/listinterestcategories.py b/mailchimp3/entities/listinterestcategories.py index 65f2b2a..3e769d9 100644 --- a/mailchimp3/entities/listinterestcategories.py +++ b/mailchimp3/entities/listinterestcategories.py @@ -58,7 +58,7 @@ def create(self, list_id, data): return response - def all(self, list_id, get_all=False, **queryparams): + def all(self, list_id, get_all=False, iterate=False, **queryparams): """ Get information about a list’s interest categories. @@ -66,6 +66,8 @@ def all(self, list_id, get_all=False, **queryparams): :type list_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -75,10 +77,8 @@ def all(self, list_id, get_all=False, **queryparams): """ self.list_id = list_id self.category_id = None - if get_all: - return self._iterate(url=self._build_path(list_id, 'interest-categories'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(list_id, 'interest-categories'), **queryparams) + url = self._build_path(list_id, 'interest-categories') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, list_id, category_id, **queryparams): diff --git a/mailchimp3/entities/listinterestcategoryinterest.py b/mailchimp3/entities/listinterestcategoryinterest.py index 5b89bb4..80b0861 100644 --- a/mailchimp3/entities/listinterestcategoryinterest.py +++ b/mailchimp3/entities/listinterestcategoryinterest.py @@ -60,7 +60,7 @@ def create(self, list_id, category_id, data): return response - def all(self, list_id, category_id, get_all=False, **queryparams): + def all(self, list_id, category_id, get_all=False, iterate=False, **queryparams): """ Get a list of this category’s interests. @@ -70,6 +70,8 @@ def all(self, list_id, category_id, get_all=False, **queryparams): :type category_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -79,13 +81,8 @@ def all(self, list_id, category_id, get_all=False, **queryparams): self.list_id = list_id self.category_id = category_id self.interest_id = None - if get_all: - return self._iterate(url=self._build_path(list_id, 'interest-categories', category_id, 'interests'), **queryparams) - else: - return self._mc_client._get( - url=self._build_path(list_id, 'interest-categories', category_id, 'interests'), - **queryparams - ) + url = self._build_path(list_id, 'interest-categories', category_id, 'interests') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, list_id, category_id, interest_id, **queryparams): diff --git a/mailchimp3/entities/listmembernotes.py b/mailchimp3/entities/listmembernotes.py index 1e22f7b..2fd7226 100644 --- a/mailchimp3/entities/listmembernotes.py +++ b/mailchimp3/entities/listmembernotes.py @@ -58,7 +58,7 @@ def create(self, list_id, subscriber_hash, data): return response - def all(self, list_id, subscriber_hash, get_all=False, **queryparams): + def all(self, list_id, subscriber_hash, get_all=False, iterate=False, **queryparams): """ Get recent notes for a specific list member. @@ -69,6 +69,8 @@ def all(self, list_id, subscriber_hash, get_all=False, **queryparams): :type subscriber_hash: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -79,11 +81,8 @@ def all(self, list_id, subscriber_hash, get_all=False, **queryparams): self.list_id = list_id self.subscriber_hash = subscriber_hash self.note_id = None - if get_all: - return self._iterate(url=self._build_path(list_id, 'members', subscriber_hash, 'notes'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(list_id, 'members', subscriber_hash, 'notes'), **queryparams) - + url = self._build_path(list_id, 'members', subscriber_hash, 'notes') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, list_id, subscriber_hash, note_id, **queryparams): """ diff --git a/mailchimp3/entities/listmembers.py b/mailchimp3/entities/listmembers.py index edda605..1fc4a22 100644 --- a/mailchimp3/entities/listmembers.py +++ b/mailchimp3/entities/listmembers.py @@ -63,7 +63,7 @@ def create(self, list_id, data): return response - def all(self, list_id, get_all=False, **queryparams): + def all(self, list_id, get_all=False, iterate=False, **queryparams): """ Get information about members in a specific MailChimp list. @@ -71,6 +71,8 @@ def all(self, list_id, get_all=False, **queryparams): :type list_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -90,10 +92,8 @@ def all(self, list_id, get_all=False, **queryparams): """ self.list_id = list_id self.subscriber_hash = None - if get_all: - return self._iterate(url=self._build_path(list_id, 'members'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(list_id, 'members'), **queryparams) + url = self._build_path(list_id, 'members') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, list_id, subscriber_hash, **queryparams): diff --git a/mailchimp3/entities/listmergefields.py b/mailchimp3/entities/listmergefields.py index 96999cc..1b46322 100644 --- a/mailchimp3/entities/listmergefields.py +++ b/mailchimp3/entities/listmergefields.py @@ -50,7 +50,7 @@ def create(self, list_id, data): return response - def all(self, list_id, get_all=False, **queryparams): + def all(self, list_id, get_all=False, iterate=False, **queryparams): """ Get a list of all merge fields (formerly merge vars) for a list. @@ -58,6 +58,8 @@ def all(self, list_id, get_all=False, **queryparams): :type list_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -68,10 +70,8 @@ def all(self, list_id, get_all=False, **queryparams): """ self.list_id = list_id self.merge_id = None - if get_all: - return self._iterate(url=self._build_path(list_id, 'merge-fields'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(list_id, 'merge-fields'), **queryparams) + url = self._build_path(list_id, 'merge-fields') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, list_id, merge_id): diff --git a/mailchimp3/entities/lists.py b/mailchimp3/entities/lists.py index 3113114..30dc591 100644 --- a/mailchimp3/entities/lists.py +++ b/mailchimp3/entities/lists.py @@ -163,12 +163,14 @@ def update_members(self, list_id, data): return self._mc_client._post(url=self._build_path(list_id), data=data) - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get information about all lists in the account. :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -183,10 +185,7 @@ def all(self, get_all=False, **queryparams): queryparams['sort_dir'] = string (Must be one of 'ASC' or 'DESC') """ self.list_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) def get(self, list_id, **queryparams): diff --git a/mailchimp3/entities/listsegmentmembers.py b/mailchimp3/entities/listsegmentmembers.py index be4c8af..3a369c6 100644 --- a/mailchimp3/entities/listsegmentmembers.py +++ b/mailchimp3/entities/listsegmentmembers.py @@ -64,7 +64,7 @@ def create(self, list_id, segment_id, data): return response - def all(self, list_id, segment_id, get_all=False, **queryparams): + def all(self, list_id, segment_id, get_all=False, iterate=False, **queryparams): """ Get information about members in a saved segment. @@ -74,6 +74,8 @@ def all(self, list_id, segment_id, get_all=False, **queryparams): :type segment_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -83,10 +85,8 @@ def all(self, list_id, segment_id, get_all=False, **queryparams): self.list_id = list_id self.segment_id = segment_id self.subscriber_hash = None - if get_all: - return self._iterate(url=self._build_path(list_id, 'segments', segment_id, 'members'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(list_id, 'segments', segment_id, 'members'), **queryparams) + url = self._build_path(list_id, 'segments', segment_id, 'members') + return self._list_result(url, get_all, iterate, **queryparams) def delete(self, list_id, segment_id, subscriber_hash): diff --git a/mailchimp3/entities/listsegments.py b/mailchimp3/entities/listsegments.py index d721744..a6b65ed 100644 --- a/mailchimp3/entities/listsegments.py +++ b/mailchimp3/entities/listsegments.py @@ -51,7 +51,7 @@ def create(self, list_id, data): return response - def all(self, list_id, get_all=False, **queryparams): + def all(self, list_id, get_all=False, iterate=False, **queryparams): """ Get information about all available segments for a specific list. @@ -59,6 +59,8 @@ def all(self, list_id, get_all=False, **queryparams): :type list_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -72,10 +74,8 @@ def all(self, list_id, get_all=False, **queryparams): """ self.list_id = list_id self.segment_id = None - if get_all: - return self._iterate(url=self._build_path(list_id, 'segments'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(list_id, 'segments'), **queryparams) + url = self._build_path(list_id, 'segments') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, list_id, segment_id, **queryparams): diff --git a/mailchimp3/entities/reportclickdetailmembers.py b/mailchimp3/entities/reportclickdetailmembers.py index 8c65ec9..6166843 100644 --- a/mailchimp3/entities/reportclickdetailmembers.py +++ b/mailchimp3/entities/reportclickdetailmembers.py @@ -27,7 +27,7 @@ def __init__(self, *args, **kwargs): self.subscriber_hash = None - def all(self, campaign_id, link_id, get_all=False, **queryparams): + def all(self, campaign_id, link_id, get_all=False, iterate=False, **queryparams): """ Get information about list members who clicked on a specific link in a campaign. @@ -38,6 +38,8 @@ def all(self, campaign_id, link_id, get_all=False, **queryparams): :type link_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -47,13 +49,8 @@ def all(self, campaign_id, link_id, get_all=False, **queryparams): self.campaign_id = campaign_id self.link_id = link_id self.subscriber_hash = None - if get_all: - return self._iterate(url=self._build_path(campaign_id, 'click-details', link_id, 'members'), **queryparams) - else: - return self._mc_client._get( - url=self._build_path(campaign_id, 'click-details', link_id, 'members'), - **queryparams - ) + url = self._build_path(campaign_id, 'click-details', link_id, 'members') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, campaign_id, link_id, subscriber_hash, **queryparams): diff --git a/mailchimp3/entities/reportclickdetailreports.py b/mailchimp3/entities/reportclickdetailreports.py index e81db63..453af3b 100644 --- a/mailchimp3/entities/reportclickdetailreports.py +++ b/mailchimp3/entities/reportclickdetailreports.py @@ -26,7 +26,7 @@ def __init__(self, *args, **kwargs): self.members = ReportClickDetailMembers(self) - def all(self, campaign_id, get_all=False, **queryparams): + def all(self, campaign_id, get_all=False, iterate=False, **queryparams): """ Get information about clicks on specific links in your MailChimp campaigns. @@ -35,6 +35,8 @@ def all(self, campaign_id, get_all=False, **queryparams): :type campaign_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -43,10 +45,8 @@ def all(self, campaign_id, get_all=False, **queryparams): """ self.campaign_id = campaign_id self.link_id = None - if get_all: - return self._iterate(url=self._build_path(campaign_id, 'click-details'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(campaign_id, 'click-details'), **queryparams) + url = self._build_path(campaign_id, 'click-details') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, campaign_id, link_id, **queryparams): diff --git a/mailchimp3/entities/reportemailactivity.py b/mailchimp3/entities/reportemailactivity.py index 576bd72..f0042e3 100644 --- a/mailchimp3/entities/reportemailactivity.py +++ b/mailchimp3/entities/reportemailactivity.py @@ -25,7 +25,7 @@ def __init__(self, *args, **kwargs): self.subscriber_hash = None - def all(self, campaign_id, get_all=False, **queryparams): + def all(self, campaign_id, get_all=False, iterate=False, **queryparams): """ Get a list of member’s subscriber activity in a specific campaign. @@ -33,6 +33,8 @@ def all(self, campaign_id, get_all=False, **queryparams): :type campaign_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -41,10 +43,8 @@ def all(self, campaign_id, get_all=False, **queryparams): """ self.campaign_id = campaign_id self.subscriber_hash = None - if get_all: - return self._iterate(url=self._build_path(campaign_id, 'email-activity'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(campaign_id, 'email-activity'), **queryparams) + url = self._build_path(campaign_id, 'email-activity') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, campaign_id, subscriber_hash, **queryparams): diff --git a/mailchimp3/entities/reportgoogleanalytics.py b/mailchimp3/entities/reportgoogleanalytics.py index 79586ef..ea6629c 100644 --- a/mailchimp3/entities/reportgoogleanalytics.py +++ b/mailchimp3/entities/reportgoogleanalytics.py @@ -22,7 +22,7 @@ def __init__(self, *args, **kwargs): self.campaign_id = None self.profile_id = None - def all(self, campaign_id, get_all=False, **queryparams): + def all(self, campaign_id, get_all=False, iterate=False, **queryparams): """ Get a summary of Google Analytics reports for a specific campaign. @@ -35,10 +35,8 @@ def all(self, campaign_id, get_all=False, **queryparams): queryparams['exclude_fields'] = [] """ self.campaign_id = campaign_id - if get_all: - return self._iterate(url=self._build_path(campaign_id, 'google-analytics'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(campaign_id, 'google-analytics'), **queryparams) + url = self._build_path(campaign_id, 'google-analytics') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, campaign_id, profile_id, **queryparams): """ diff --git a/mailchimp3/entities/reportlocations.py b/mailchimp3/entities/reportlocations.py index 7a9c631..fbc3bb0 100644 --- a/mailchimp3/entities/reportlocations.py +++ b/mailchimp3/entities/reportlocations.py @@ -23,7 +23,7 @@ def __init__(self, *args, **kwargs): self.campaign_id = None - def all(self, campaign_id, get_all=False, **queryparams): + def all(self, campaign_id, get_all=False, iterate=False, **queryparams): """ Get top open locations for a specific campaign. @@ -31,6 +31,8 @@ def all(self, campaign_id, get_all=False, **queryparams): :type campaign_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -38,7 +40,5 @@ def all(self, campaign_id, get_all=False, **queryparams): queryparams['offset'] = integer """ self.campaign_id = campaign_id - if get_all: - return self._iterate(url=self._build_path(campaign_id, 'locations'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(campaign_id, 'locations'), **queryparams) + url = self._build_path(campaign_id, 'locations') + return self._list_result(url, get_all, iterate, **queryparams) diff --git a/mailchimp3/entities/reportopendetails.py b/mailchimp3/entities/reportopendetails.py index 846438e..92e365a 100644 --- a/mailchimp3/entities/reportopendetails.py +++ b/mailchimp3/entities/reportopendetails.py @@ -22,7 +22,7 @@ def __init__(self, *args, **kwargs): self.campaign_id = None - def all(self, campaign_id, get_all=False, **queryparams): + def all(self, campaign_id, get_all=False, iterate=False, **queryparams): """ Get detailed information about any campaign emails that were opened by a list member. @@ -30,6 +30,8 @@ def all(self, campaign_id, get_all=False, **queryparams): :type campaign_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -38,10 +40,8 @@ def all(self, campaign_id, get_all=False, **queryparams): queryparams['since'] = str """ self.campaign_id = campaign_id - if get_all: - return self._iterate(url=self._build_path(campaign_id, 'open-details'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(campaign_id, 'open-details'), **queryparams) + url = self._build_path(campaign_id, 'open-details') + return self._list_result(url, get_all, iterate, **queryparams) class ReportOpenDetails(OpenDetails): diff --git a/mailchimp3/entities/reports.py b/mailchimp3/entities/reports.py index e198f84..daeea18 100644 --- a/mailchimp3/entities/reports.py +++ b/mailchimp3/entities/reports.py @@ -45,7 +45,7 @@ def __init__(self, *args, **kwargs): self.unsubscribes = ReportUnsubscribes(self) - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get campaign reports. @@ -56,6 +56,8 @@ def all(self, get_all=False, **queryparams): :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -66,10 +68,7 @@ def all(self, get_all=False, **queryparams): queryparams['since_send_time'] = string """ self.campaign_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) def get(self, campaign_id, **queryparams): diff --git a/mailchimp3/entities/reportsentto.py b/mailchimp3/entities/reportsentto.py index a9d2f60..f58434a 100644 --- a/mailchimp3/entities/reportsentto.py +++ b/mailchimp3/entities/reportsentto.py @@ -25,7 +25,7 @@ def __init__(self, *args, **kwargs): self.subscriber_hash = None - def all(self, campaign_id, get_all=False, **queryparams): + def all(self, campaign_id, get_all=False, iterate=False, **queryparams): """ Get information about campaign recipients. @@ -33,6 +33,8 @@ def all(self, campaign_id, get_all=False, **queryparams): :type campaign_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -41,10 +43,8 @@ def all(self, campaign_id, get_all=False, **queryparams): """ self.campaign_id = campaign_id self.subscriber_hash = None - if get_all: - return self._iterate(url=self._build_path(campaign_id, 'sent-to'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(campaign_id, 'sent-to'), **queryparams) + url = self._build_path(campaign_id, 'sent-to') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, campaign_id, subscriber_hash, **queryparams): diff --git a/mailchimp3/entities/reportunsubscribes.py b/mailchimp3/entities/reportunsubscribes.py index 8d4b132..de70eeb 100644 --- a/mailchimp3/entities/reportunsubscribes.py +++ b/mailchimp3/entities/reportunsubscribes.py @@ -22,7 +22,7 @@ def __init__(self, *args, **kwargs): self.subscriber_hash = None - def all(self, campaign_id, get_all=False, **queryparams): + def all(self, campaign_id, get_all=False, iterate=False, **queryparams): """ Get information about members who have unsubscribed from a specific campaign. @@ -31,6 +31,8 @@ def all(self, campaign_id, get_all=False, **queryparams): :type campaign_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -39,10 +41,8 @@ def all(self, campaign_id, get_all=False, **queryparams): """ self.campaign_id = campaign_id self.subscriber_hash = None - if get_all: - return self._iterate(url=self._build_path(campaign_id, 'unsubscribed'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(campaign_id, 'unsubscribed'), **queryparams) + url = self._build_path(campaign_id, 'unsubscribed') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, campaign_id, subscriber_hash, **queryparams): diff --git a/mailchimp3/entities/storecartlines.py b/mailchimp3/entities/storecartlines.py index 08ce624..7858563 100644 --- a/mailchimp3/entities/storecartlines.py +++ b/mailchimp3/entities/storecartlines.py @@ -64,7 +64,7 @@ def create(self, store_id, cart_id, data): return response - def all(self, store_id, cart_id, get_all=False, **queryparams): + def all(self, store_id, cart_id, get_all=False, iterate=False, **queryparams): """ Get information about a cart’s line items. @@ -74,6 +74,8 @@ def all(self, store_id, cart_id, get_all=False, **queryparams): :type cart_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -83,10 +85,8 @@ def all(self, store_id, cart_id, get_all=False, **queryparams): self.store_id = store_id self.cart_id = cart_id self.line_id = None - if get_all: - return self._iterate(url=self._build_path(store_id, 'carts', cart_id, 'lines'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(store_id, 'carts', cart_id, 'lines'), **queryparams) + url = self._build_path(store_id, 'carts', cart_id, 'lines') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, store_id, cart_id, line_id, **queryparams): diff --git a/mailchimp3/entities/storecarts.py b/mailchimp3/entities/storecarts.py index 363f47c..be68a8a 100644 --- a/mailchimp3/entities/storecarts.py +++ b/mailchimp3/entities/storecarts.py @@ -92,7 +92,7 @@ def create(self, store_id, data): return response - def all(self, store_id, get_all=False, **queryparams): + def all(self, store_id, get_all=False, iterate=False, **queryparams): """ Get information about a store’s carts. @@ -100,6 +100,8 @@ def all(self, store_id, get_all=False, **queryparams): :type store_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -108,10 +110,8 @@ def all(self, store_id, get_all=False, **queryparams): """ self.store_id = store_id self.cart_id = None - if get_all: - return self._iterate(url=self._build_path(store_id, 'carts'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(store_id, 'carts'), **queryparams) + url = self._build_path(store_id, 'carts') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, store_id, cart_id, **queryparams): diff --git a/mailchimp3/entities/storecustomers.py b/mailchimp3/entities/storecustomers.py index dd790b3..7734f58 100644 --- a/mailchimp3/entities/storecustomers.py +++ b/mailchimp3/entities/storecustomers.py @@ -60,7 +60,7 @@ def create(self, store_id, data): return response - def all(self, store_id, get_all=False, **queryparams): + def all(self, store_id, get_all=False, iterate=False, **queryparams): """ Get information about a store’s customers. @@ -68,6 +68,8 @@ def all(self, store_id, get_all=False, **queryparams): :type store_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -77,10 +79,8 @@ def all(self, store_id, get_all=False, **queryparams): """ self.store_id = store_id self.customer_id = None - if get_all: - return self._iterate(url=self._build_path(store_id, 'customers'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(store_id, 'customers'), **queryparams) + url = self._build_path(store_id, 'customers') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, store_id, customer_id, **queryparams): diff --git a/mailchimp3/entities/storeorderlines.py b/mailchimp3/entities/storeorderlines.py index 38535b5..9e3c2b9 100644 --- a/mailchimp3/entities/storeorderlines.py +++ b/mailchimp3/entities/storeorderlines.py @@ -64,7 +64,7 @@ def create(self, store_id, order_id, data): return response - def all(self, store_id, order_id, get_all=False, **queryparams): + def all(self, store_id, order_id, get_all=False, iterate=False, **queryparams): """ Get information about an order’s line items. @@ -74,6 +74,8 @@ def all(self, store_id, order_id, get_all=False, **queryparams): :type order_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -83,11 +85,8 @@ def all(self, store_id, order_id, get_all=False, **queryparams): self.store_id = store_id self.order_id = order_id self.line_id = None - if get_all: - return self._iterate(url=self._build_path(store_id, 'orders', order_id, 'lines'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(store_id, 'orders', order_id, 'lines'), **queryparams) - + url = self._build_path(store_id, 'orders', order_id, 'lines') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, store_id, order_id, line_id, **queryparams): """ diff --git a/mailchimp3/entities/storeorders.py b/mailchimp3/entities/storeorders.py index 0fd8b6d..8c6d379 100644 --- a/mailchimp3/entities/storeorders.py +++ b/mailchimp3/entities/storeorders.py @@ -109,7 +109,7 @@ def create(self, store_id, data): return response - def all(self, store_id, get_all=False, **queryparams): + def all(self, store_id, get_all=False, iterate=False, **queryparams): """ Get information about a store’s orders. @@ -117,6 +117,8 @@ def all(self, store_id, get_all=False, **queryparams): :type store_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -126,10 +128,8 @@ def all(self, store_id, get_all=False, **queryparams): """ self.store_id = store_id self.order_id = None - if get_all: - return self._iterate(url=self._build_path(store_id, 'orders'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(store_id, 'orders'), **queryparams) + url = self._build_path(store_id, 'orders') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, store_id, order_id, **queryparams): diff --git a/mailchimp3/entities/storeproductimages.py b/mailchimp3/entities/storeproductimages.py index a9e9dc9..2c33e11 100644 --- a/mailchimp3/entities/storeproductimages.py +++ b/mailchimp3/entities/storeproductimages.py @@ -54,7 +54,7 @@ def create(self, store_id, product_id, data): return response - def all(self, store_id, product_id, get_all=False, **queryparams): + def all(self, store_id, product_id, get_all=False, iterate=False, **queryparams): """ Get information about a product’s images. @@ -64,6 +64,8 @@ def all(self, store_id, product_id, get_all=False, **queryparams): :type product_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -73,10 +75,8 @@ def all(self, store_id, product_id, get_all=False, **queryparams): self.store_id = store_id self.product_id = product_id self.image_id = None - if get_all: - return self._iterate(url=self._build_path(store_id, 'products', product_id, 'images'), **queryparams) - else: - return self._mc_client._post(url=self._build_path(store_id, 'products', product_id, 'images'), **queryparams) + url = self._build_path(store_id, 'products', product_id, 'images') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, store_id, product_id, image_id, **queryparams): diff --git a/mailchimp3/entities/storeproducts.py b/mailchimp3/entities/storeproducts.py index 72da84f..fdff05d 100644 --- a/mailchimp3/entities/storeproducts.py +++ b/mailchimp3/entities/storeproducts.py @@ -70,7 +70,7 @@ def create(self, store_id, data): return response - def all(self, store_id, get_all=False, **queryparams): + def all(self, store_id, get_all=False, iterate=False, **queryparams): """ Get information about a store’s products. @@ -78,6 +78,8 @@ def all(self, store_id, get_all=False, **queryparams): :type store_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -86,10 +88,8 @@ def all(self, store_id, get_all=False, **queryparams): """ self.store_id = store_id self.product_id = None - if get_all: - return self._iterate(url=self._build_path(store_id, 'products'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(store_id, 'products'), **queryparams) + url = self._build_path(store_id, 'products') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, store_id, product_id, **queryparams): diff --git a/mailchimp3/entities/storeproductvariants.py b/mailchimp3/entities/storeproductvariants.py index fceafb8..d33eaf4 100644 --- a/mailchimp3/entities/storeproductvariants.py +++ b/mailchimp3/entities/storeproductvariants.py @@ -56,7 +56,7 @@ def create(self, store_id, product_id, data): return response - def all(self, store_id, product_id, get_all=False, **queryparams): + def all(self, store_id, product_id, get_all=False, iterate=False, **queryparams): """ Get information about a product’s variants. @@ -66,6 +66,8 @@ def all(self, store_id, product_id, get_all=False, **queryparams): :type product_id: :py:class:`str` :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -75,13 +77,8 @@ def all(self, store_id, product_id, get_all=False, **queryparams): self.store_id = store_id self.product_id = product_id self.variant_id = None - if get_all: - return self._iterate(url=self._build_path(store_id, 'products', product_id, 'variants'), **queryparams) - else: - return self._mc_client._get( - url=self._build_path(store_id, 'products', product_id, 'variants'), - **queryparams - ) + url = self._build_path(store_id, 'products', product_id, 'variants') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, store_id, product_id, variant_id, **queryparams): diff --git a/mailchimp3/entities/storepromocodes.py b/mailchimp3/entities/storepromocodes.py index 83a7137..8bbc322 100644 --- a/mailchimp3/entities/storepromocodes.py +++ b/mailchimp3/entities/storepromocodes.py @@ -52,7 +52,7 @@ def create(self, store_id, promo_rule_id, data): if response is not None: return response - def all(self, store_id, promo_rule_id, get_all=False, **queryparams): + def all(self, store_id, promo_rule_id, get_all=False, iterate=False, **queryparams): """ Get information about a store’s promo codes. @@ -70,10 +70,8 @@ def all(self, store_id, promo_rule_id, get_all=False, **queryparams): """ self.store_id=store_id self.promo_rule_id=promo_rule_id - if get_all: - return self._iterate(url=self._build_path(store_id, 'promo-rules', promo_rule_id, 'promo-codes'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(store_id, 'promo-rule', promo_rule_id), **queryparams) + url = self._build_path(store_id, 'promo-rules', promo_rule_id, 'promo-codes') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, store_id, promo_rule_id, promo_code_id, **queryparams): """ diff --git a/mailchimp3/entities/storepromorules.py b/mailchimp3/entities/storepromorules.py index b955944..9c89c67 100644 --- a/mailchimp3/entities/storepromorules.py +++ b/mailchimp3/entities/storepromorules.py @@ -58,7 +58,7 @@ def create(self, store_id, data): if response is not None: return response - def all(self, store_id, get_all=False, **queryparams): + def all(self, store_id, get_all=False, iterate=False, **queryparams): """ Get information about a store’s promo rules. @@ -73,10 +73,8 @@ def all(self, store_id, get_all=False, **queryparams): queryparams['offset'] = integer """ self.store_id = store_id - if get_all: - return self._iterate(url=self._build_path(store_id, 'promo-rules'), **queryparams) - else: - return self._mc_client._get(url=self._build_path(store_id, 'promo-rule'), **queryparams) + url = self._build_path(store_id, 'promo-rules') + return self._list_result(url, get_all, iterate, **queryparams) def get(self, store_id, promo_rule_id, **queryparams): """ diff --git a/mailchimp3/entities/stores.py b/mailchimp3/entities/stores.py index 51aa118..f94dad1 100644 --- a/mailchimp3/entities/stores.py +++ b/mailchimp3/entities/stores.py @@ -70,12 +70,14 @@ def create(self, data): return response - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get information about all stores in the account. :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -83,10 +85,7 @@ def all(self, get_all=False, **queryparams): queryparams['offset'] = integer """ self.store_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) def get(self, store_id, **queryparams): diff --git a/mailchimp3/entities/templatefolders.py b/mailchimp3/entities/templatefolders.py index 2434c60..805c73d 100755 --- a/mailchimp3/entities/templatefolders.py +++ b/mailchimp3/entities/templatefolders.py @@ -43,12 +43,14 @@ def create(self, data): return response - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get all folders used to organize templates. :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -56,10 +58,7 @@ def all(self, get_all=False, **queryparams): queryparams['offset'] = integer """ self.folder_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) def get(self, folder_id, **queryparams): diff --git a/mailchimp3/entities/templates.py b/mailchimp3/entities/templates.py index 71d81a1..d4e094b 100644 --- a/mailchimp3/entities/templates.py +++ b/mailchimp3/entities/templates.py @@ -50,12 +50,14 @@ def create(self, data): return response - def all(self, get_all=False, **queryparams): + def all(self, get_all=False, iterate=False, **queryparams): """ Get a list of an account’s available templates. :param get_all: Should the query get all results :type get_all: :py:class:`bool` + :param iterate: Should the query iterate over each page. + :type iterate: :py:class:`bool` :param queryparams: The query string parameters queryparams['fields'] = [] queryparams['exclude_fields'] = [] @@ -68,10 +70,7 @@ def all(self, get_all=False, **queryparams): queryparams['folder_id'] = string """ self.template_id = None - if get_all: - return self._iterate(url=self._build_path(), **queryparams) - else: - return self._mc_client._get(url=self._build_path(), **queryparams) + return self._list_result(self._build_path(), get_all, iterate, **queryparams) def get(self, template_id, **queryparams):