Skip to content
This repository was archived by the owner on Aug 29, 2019. It is now read-only.

Commit 98daedb

Browse files
Kelly O'BrienVraj Mohan
authored andcommitted
Add get_broadcasts
1 parent 4a6d37e commit 98daedb

File tree

5 files changed

+63
-6
lines changed

5 files changed

+63
-6
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Changelog
2+
---------
3+
2014-12-29: v1.4.0
4+
Add a new endpoint to get broadcasts by list_id and status
5+
16
2014-11-17: v1.3.0
27
* Add a new endpoint to cancel scheduled broadcast
38

aweber_api/entry.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def schedule_broadcast(self, bc_id, scheduled_for):
126126
127127
* Note:
128128
This method only works on List Entry resources and
129-
requires access to subscriber information. Please
129+
requires send broadcast email permissions. Please
130130
refer to the AWeber API Reference Documentation at
131131
https://labs.aweber.com/docs/reference/1.0#broadcast_scheduler
132132
for more details on how to call this method.
@@ -137,16 +137,37 @@ def schedule_broadcast(self, bc_id, scheduled_for):
137137
url = '{0}/broadcasts/{1}/schedule'.format(self.url, bc_id)
138138
return self.adapter.request('POST', url, body, response='status')
139139

140+
def get_broadcasts(self, status, **kwargs):
141+
"""Invoke the API method to retrieve broadcasts by status.
142+
143+
* Note:
144+
This method only works on List Entry resources. Please
145+
refer to the AWeber API Reference Documentation at
146+
https://labs.aweber.com/docs/reference/1.0#get_broadcasts
147+
for more details on how to call this method.
148+
149+
"""
150+
self._method_for('list')
151+
params = {'status': status}
152+
params.update(kwargs)
153+
query_string = urlencode(params)
154+
url = '{0.url}/broadcasts?{1}'.format(self, query_string)
155+
156+
data = self.adapter.request('GET', url)
157+
collection = aweber_api.AWeberCollection(url, data, self.adapter)
158+
collection._data['total_size'] = self._get_broadcast_count(
159+
query_string)
160+
return collection
161+
140162
def cancel_broadcast(self, bc_id):
141163
"""Invoke the API method to cancel the given scheduled broadcast.
142164
143165
* Note:
144166
This method only works on List Entry resources and
145-
requires access to subscriber and send broadcast
146-
information. Please refer to the AWeber API Reference
147-
Documentation at
167+
requires send broadcast email permissions. Please refer
168+
to the AWeber API Reference Documentation at
148169
https://labs.aweber.com/docs/reference/1.0#cancel_broadcast
149-
more details on how to call this method.
170+
for more details on how to call this method.
150171
151172
"""
152173
self._method_for('list')
@@ -158,6 +179,12 @@ def _get_total_size(self, uri, **kwargs):
158179
total_size_uri = '{0}&ws.show=total_size'.format(uri)
159180
return int(self.adapter.request('GET', total_size_uri))
160181

182+
def _get_broadcast_count(self, query_string):
183+
"""Get actual total size number from total_size_link."""
184+
total_size_uri = '{0.url}/broadcasts/total?{1}'.format(
185+
self, query_string)
186+
return int(self.adapter.request('GET', total_size_uri)['total_size'])
187+
161188
def get_parent_entry(self):
162189
"""Return the parent entry of this entry
163190

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name='aweber_api',
11-
version='1.3.0',
11+
version='1.4.0',
1212
author='AWeber Dev Team',
1313
author_email='api@aweber.com',
1414
maintainer='AWeber API Team',

tests/mock_adapter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
'email=joe%40example.com': ({}, 'subscribers/find'),
4949
'/accounts/1/lists/303449/subscribers?ws.show=total_size&ws.op=find&' \
5050
'email=joe%40example.com': ({}, 'subscribers/find_ts'),
51+
'/accounts/1/lists/303449/broadcasts/total?status=sent': (
52+
{'total_size': 10}, 'campaigns/303449'),
53+
'/accounts/1/lists/303449/broadcasts?status=sent': (
54+
{'total_size': 10}, 'campaigns/303449'),
5155
},
5256
'POST' : {
5357
'/accounts/1/lists/303449/any_collection': ({

tests/test_aweber_entry.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,27 @@ def test_should_raise_exception_when_failing(self):
198198
)
199199

200200

201+
class TestListGetBroadcasts(ListTestCase):
202+
203+
def setUp(self):
204+
super(TestListGetBroadcasts, self).setUp()
205+
self.aweber.adapter.requests = []
206+
self.broadcasts = self.list_.get_broadcasts(status='sent')
207+
self.request = self.aweber.adapter.requests[0]
208+
209+
def test_should_return_collection(self):
210+
self.assertEqual(type(self.broadcasts), AWeberCollection)
211+
212+
def test_should_make_get_request(self):
213+
self.assertEqual(self.request['method'], 'GET')
214+
215+
def test_should_build_correct_url(self):
216+
self.assertEqual(
217+
self.request['url'],
218+
'/accounts/1/lists/303449/broadcasts?status=sent'
219+
)
220+
221+
201222
class SubscriberTestCase(TestCase):
202223

203224
def setUp(self):

0 commit comments

Comments
 (0)