diff --git a/README.md b/README.md index 8af40b6..bf46275 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,7 @@ Then, you do not need to precise it in your code: ```python >>> api.subscribers.activity(id='1343965485') +>>> api.subscribers.activity(id='1343965485', limit=50, offset=1, atype='clicks') ``` #### Create subscriber diff --git a/mailerlite/subscriber.py b/mailerlite/subscriber.py index 76c0792..904ccbf 100644 --- a/mailerlite/subscriber.py +++ b/mailerlite/subscriber.py @@ -356,7 +356,8 @@ def groups(self, as_json=False, **identifier): all_groups = [Group(**res) for res in res_json] return all_groups - def activity(self, as_json=False, atype=None, **identifier): + def activity(self, as_json=False, atype=None, limit=100, + offset=0, **identifier): """Get activities (clicks, opens, etc) of selected subscriber. More informations: @@ -379,6 +380,10 @@ def activity(self, as_json=False, atype=None, **identifier): * unsubscribes * forwards * sendings + limit : int, optional + How many subscribers you want, default 100 + offset : int, optional + page index, default 0 Returns ------- @@ -386,6 +391,7 @@ def activity(self, as_json=False, atype=None, **identifier): all subscriber activities. More informations : https://developers.mailerlite.com/v2/reference#activity-of-single-subscriber """ + params = {'limit': limit, 'offset': offset} path = get_id_or_email_identifier(**identifier) if path is None: raise IOError('An identifier must be define') @@ -399,7 +405,7 @@ def activity(self, as_json=False, atype=None, **identifier): ' be {0}'.format(possible_atype)) args.append(atype) - url = client.build_url(*args) + url = client.build_url(*args, **params) _, res_json = client.get(url, headers=self.headers) diff --git a/mailerlite/tests/test_subscriber.py b/mailerlite/tests/test_subscriber.py index 93c2c56..52874f1 100644 --- a/mailerlite/tests/test_subscriber.py +++ b/mailerlite/tests/test_subscriber.py @@ -137,7 +137,7 @@ def test_subscribers_crud(header): groups = subscriber.groups(email=mail) assert len(groups) in [0, 1] - activity = subscriber.activity(email=mail) + activity = subscriber.activity(email=mail, limit=50, offset=1) assert len(activity) in [0, 1] with pytest.raises(IOError):