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

Commit e593540

Browse files
committed
Merge pull request #25 from aweber/add-schedule-brodcast-feature
Add schedule brodcast feature
2 parents 3b85b46 + e8ca320 commit e593540

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Changelog
22
---------
3+
2014-11-13: v1.2.0
4+
* Add a new endpoint to schedule broadcast
5+
36
2013-01-03: v1.1.4
47
* Support version 1.0.17 of the API. (Broadcast Stats)
58
* See https://labs.aweber.com/docs/changelog for details

aweber_api/entry.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@ def findSubscribers(self, **kwargs):
121121
collection._data['total_size'] = self._get_total_size(url)
122122
return collection
123123

124+
def schedule_broadcast(self, bc_id, scheduled_for):
125+
"""Invoke the API method to schedule the given broadcast.
126+
127+
* Note:
128+
This method only works on List Entry resources and
129+
requires access to subscriber information. Please
130+
refer to the AWeber API Reference Documentation at
131+
https://labs.aweber.com/docs/reference/1.0#account
132+
for more details on how to call this method.
133+
134+
"""
135+
self._method_for('list')
136+
body = {'scheduled_for': scheduled_for}
137+
url = '{0}/broadcasts/{1}/schedule'.format(self.url, bc_id)
138+
return self.adapter.request('POST', url, body, response='status')
139+
124140
def _get_total_size(self, uri, **kwargs):
125141
"""Get actual total size number from total_size_link."""
126142
total_size_uri = '{0}&ws.show=total_size'.format(uri)

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.1.4',
11+
version='1.2.0',
1212
author='AWeber Dev Team',
1313
author_email='api@aweber.com',
1414
maintainer='AWeber API Team',

tests/mock_adapter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@
6161
'/accounts/1/lists/303449/subscribers/1': ({
6262
'status': '201',
6363
'location': '/accounts/1/lists/505454/subscribers/3'}, None),
64+
'/accounts/1/lists/303449/broadcasts/2/schedule': ({
65+
'status': '201',
66+
'location': '/accounts/1/lists/303449/broadcasts/2/schedule'},
67+
None
68+
),
69+
'/accounts/1/lists/303449/broadcasts/3/schedule': ({
70+
'status': '400',
71+
'location': '/accounts/1/lists/303449/broadcasts/3/schedule'},
72+
'error'
73+
),
74+
6475
},
6576
'PATCH' : {
6677
'/accounts/1/lists/303449/subscribers/1': ({'status': '209'}, None),

tests/test_aweber_entry.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ def setUp(self):
4141
self.account = self.aweber.load_from_url('/accounts/1')
4242

4343

44+
class ListTestCase(TestCase):
45+
46+
def setUp(self):
47+
self.aweber = AWeberAPI('1', '2')
48+
self.aweber.adapter = MockAdapter()
49+
self.list_ = self.aweber.load_from_url('/accounts/1/lists/303449')
50+
51+
4452
class TestAWeberAccountEntry(AccountTestCase):
4553

4654
def test_should_be_an_entry(self):
@@ -110,6 +118,48 @@ def test_should_support_find_method(self):
110118
'https://api.aweber.com/1.0/accounts/1/lists/303449/subscribers/1'
111119

112120

121+
class TestListScheduleBroadcast(ListTestCase):
122+
123+
def setUp(self):
124+
super(TestListScheduleBroadcast, self).setUp()
125+
self.aweber.adapter.requests = []
126+
self.status = self.list_.schedule_broadcast(
127+
bc_id=2, scheduled_for='2014-09-06 18:55:00')
128+
self.request = self.aweber.adapter.requests[0]
129+
130+
def test_should_return_status(self):
131+
self.assertEqual(int(self.status), 201)
132+
133+
def test_should_make_post_request(self):
134+
self.assertEqual(self.request['method'], 'POST')
135+
136+
def test_should_build_correct_url(self):
137+
self.assertEqual(self.request['url'],
138+
'/accounts/1/lists/303449/broadcasts/2/schedule'
139+
)
140+
141+
def test_should_pass_scheduled_for_date(self):
142+
self.assertEqual(self.request['data'],
143+
{'scheduled_for': '2014-09-06 18:55:00'}
144+
)
145+
146+
147+
class TestListScheduleBroadcastError(ListTestCase):
148+
149+
def setUp(self):
150+
super(TestListScheduleBroadcastError, self).setUp()
151+
self.list_ = self.aweber.load_from_url('/accounts/1/lists/303449')
152+
self.aweber.adapter.requests = []
153+
154+
def test_should_raise_exception_when_failing(self):
155+
self.assertRaises(
156+
APIException,
157+
self.list_.schedule_broadcast,
158+
bc_id=3,
159+
scheduled_for='2014-09-06 18:55:00',
160+
)
161+
162+
113163
class SubscriberTestCase(TestCase):
114164

115165
def setUp(self):

0 commit comments

Comments
 (0)