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

Commit

Permalink
Merge pull request #25 from aweber/add-schedule-brodcast-feature
Browse files Browse the repository at this point in the history
Add schedule brodcast feature
  • Loading branch information
djt5019 committed Nov 13, 2014
2 parents 3b85b46 + e8ca320 commit e593540
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 16 additions & 0 deletions aweber_api/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='aweber_api',
version='1.1.4',
version='1.2.0',
author='AWeber Dev Team',
author_email='[email protected]',
maintainer='AWeber API Team',
Expand Down
11 changes: 11 additions & 0 deletions tests/mock_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
50 changes: 50 additions & 0 deletions tests/test_aweber_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit e593540

Please sign in to comment.