diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f3111ae..e045fd6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,5 +1,8 @@ Changelog --------- +2014-11-13: v1.2.0 + * Add a new endpoint to schedule broadcast + 2013-01-03: v1.1.4 * Support version 1.0.17 of the API. (Broadcast Stats) * See https://labs.aweber.com/docs/changelog for details diff --git a/aweber_api/entry.py b/aweber_api/entry.py index f716338..75a5060 100644 --- a/aweber_api/entry.py +++ b/aweber_api/entry.py @@ -121,6 +121,22 @@ def findSubscribers(self, **kwargs): collection._data['total_size'] = self._get_total_size(url) return collection + def schedule_broadcast(self, bc_id, scheduled_for): + """Invoke the API method to schedule the given broadcast. + + * Note: + This method only works on List Entry resources and + requires access to subscriber information. Please + refer to the AWeber API Reference Documentation at + https://labs.aweber.com/docs/reference/1.0#account + for more details on how to call this method. + + """ + self._method_for('list') + body = {'scheduled_for': scheduled_for} + url = '{0}/broadcasts/{1}/schedule'.format(self.url, bc_id) + return self.adapter.request('POST', url, body, response='status') + def _get_total_size(self, uri, **kwargs): """Get actual total size number from total_size_link.""" total_size_uri = '{0}&ws.show=total_size'.format(uri) diff --git a/setup.py b/setup.py index f522db8..6c19d05 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='aweber_api', - version='1.1.4', + version='1.2.0', author='AWeber Dev Team', author_email='api@aweber.com', maintainer='AWeber API Team', diff --git a/tests/mock_adapter.py b/tests/mock_adapter.py index 022b3df..3fae144 100644 --- a/tests/mock_adapter.py +++ b/tests/mock_adapter.py @@ -61,6 +61,17 @@ '/accounts/1/lists/303449/subscribers/1': ({ 'status': '201', 'location': '/accounts/1/lists/505454/subscribers/3'}, None), + '/accounts/1/lists/303449/broadcasts/2/schedule': ({ + 'status': '201', + 'location': '/accounts/1/lists/303449/broadcasts/2/schedule'}, + None + ), + '/accounts/1/lists/303449/broadcasts/3/schedule': ({ + 'status': '400', + 'location': '/accounts/1/lists/303449/broadcasts/3/schedule'}, + 'error' + ), + }, 'PATCH' : { '/accounts/1/lists/303449/subscribers/1': ({'status': '209'}, None), diff --git a/tests/test_aweber_entry.py b/tests/test_aweber_entry.py index 2ce7fd9..cf6f3c6 100644 --- a/tests/test_aweber_entry.py +++ b/tests/test_aweber_entry.py @@ -41,6 +41,14 @@ def setUp(self): self.account = self.aweber.load_from_url('/accounts/1') +class ListTestCase(TestCase): + + def setUp(self): + self.aweber = AWeberAPI('1', '2') + self.aweber.adapter = MockAdapter() + self.list_ = self.aweber.load_from_url('/accounts/1/lists/303449') + + class TestAWeberAccountEntry(AccountTestCase): def test_should_be_an_entry(self): @@ -110,6 +118,48 @@ def test_should_support_find_method(self): 'https://api.aweber.com/1.0/accounts/1/lists/303449/subscribers/1' +class TestListScheduleBroadcast(ListTestCase): + + def setUp(self): + super(TestListScheduleBroadcast, self).setUp() + self.aweber.adapter.requests = [] + self.status = self.list_.schedule_broadcast( + bc_id=2, scheduled_for='2014-09-06 18:55:00') + self.request = self.aweber.adapter.requests[0] + + def test_should_return_status(self): + self.assertEqual(int(self.status), 201) + + def test_should_make_post_request(self): + self.assertEqual(self.request['method'], 'POST') + + def test_should_build_correct_url(self): + self.assertEqual(self.request['url'], + '/accounts/1/lists/303449/broadcasts/2/schedule' + ) + + def test_should_pass_scheduled_for_date(self): + self.assertEqual(self.request['data'], + {'scheduled_for': '2014-09-06 18:55:00'} + ) + + +class TestListScheduleBroadcastError(ListTestCase): + + def setUp(self): + super(TestListScheduleBroadcastError, self).setUp() + self.list_ = self.aweber.load_from_url('/accounts/1/lists/303449') + self.aweber.adapter.requests = [] + + def test_should_raise_exception_when_failing(self): + self.assertRaises( + APIException, + self.list_.schedule_broadcast, + bc_id=3, + scheduled_for='2014-09-06 18:55:00', + ) + + class SubscriberTestCase(TestCase): def setUp(self):