Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #40 from skoudoro/improve-activity
Browse files Browse the repository at this point in the history
Add parameter to subscriber activity.
  • Loading branch information
skoudoro authored Jan 13, 2022
2 parents 5873f8d + 97ee737 commit a88e6d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions mailerlite/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -379,13 +380,18 @@ 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
-------
activities: list
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')
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion mailerlite/tests/test_subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a88e6d5

Please sign in to comment.