Skip to content
This repository was archived by the owner on Aug 29, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions aweber_api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class AWeberBase(object):
'broadcast_campaign' : ['links', 'messages'],
'followup_campaign' : ['links', 'messages'],
'link' : ['clicks'],
'list' : ['campaigns', 'subscribers', 'web_forms',
'web_form_split_tests'],
'list' : ['campaigns', 'custom_fields', 'subscribers',
'web_forms', 'web_form_split_tests'],
'message' : ['opens', 'tracked_events'],
'subscriber' : [],
'web_form': [],
Expand Down
13 changes: 13 additions & 0 deletions aweber_api/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ def _get_page_params(self, offset):
start = page_number * self.page_size
return { 'ws.start' : start, 'ws.size' : self.page_size }

def create(self, **kwargs):
params = {'ws.op': 'create'}
params.update(kwargs)

response = self.adapter.request('POST', self.url, params,
response='headers')
if response['status'] != '201':
return False
new_resource = response['location']
self._diff = {}
self._data = self.adapter.request('GET', new_resource)
return True

def find(self, **kwargs):
params = {'ws.op': 'find'}
params.update(kwargs)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='aweber_api',
version='1.0.1',
version='1.0.3',
packages=find_packages(exclude=['tests']),
url='https://github.com/aweber/AWeber-API-Python-Library',
install_requires = ['oauth2 >= 1.2'],
Expand Down
1 change: 1 addition & 0 deletions tests/data/custom_fields/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "Favorite Color", "is_subscriber_updateable": true, "https_etag": "\"356a192b7913b04c54574d18c28d46e6395428ab-cf46a99b7a9ec9059c21044110a3528be7b0a5de\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/1", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 1}
1 change: 1 addition & 0 deletions tests/data/custom_fields/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name": "COLOR", "is_subscriber_updateable": true, "https_etag": "\"da4b9237bacccdf19c0760cab7aec4a8359010b0-94bc2de8c0247784c42763ddb76e2b05405199d8\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/2", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 2}
1 change: 1 addition & 0 deletions tests/data/custom_fields/303449.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"total_size": 25, "start": 0, "resource_type_link": "https://api.aweber.com/1.0/#custom_field-page-resource", "entries": [{"name": "Favorite Color", "is_subscriber_updateable": true, "https_etag": "\"356a192b7913b04c54574d18c28d46e6395428ab-cf46a99b7a9ec9059c21044110a3528be7b0a5de\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/1", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 1}, {"name": "COLOR", "is_subscriber_updateable": true, "https_etag": "\"da4b9237bacccdf19c0760cab7aec4a8359010b0-94bc2de8c0247784c42763ddb76e2b05405199d8\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/2", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 2}, {"name": "Walruses", "is_subscriber_updateable": false, "https_etag": "\"77de68daecd823babbb58edb1c8e14d7106e83bb-8cf140eeac0798552baaf7727b75087a2a1c0b4b\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/3", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 3}, {"name": "test", "is_subscriber_updateable": false, "https_etag": "\"1b6453892473a467d07372d45eb05abc2031647a-515a2e84687be77dfd27567617d2cbbdd45a8898\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/4", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 4}, {"name": "MyAwesomeCustomField", "is_subscriber_updateable": true, "https_etag": "\"ac3478d69a3c81fa62e60f5c3696165a4e5e6ac4-2b4f2b8465b462fc6b6dfc3cec6ea068a03c4f4f\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/5", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 5}, {"name": "what is my quest", "is_subscriber_updateable": true, "https_etag": "\"c1dfd96eea8cc2b62785275bca38ac261256e278-ca36c26645bb470234ec4a9011fbf709c11bb7bc\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/6", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 6}, {"name": "What do i Seek", "is_subscriber_updateable": true, "https_etag": "\"902ba3cda1883801594b6e1b452790cc53948fda-0cd181dcc074c11cd3a9e9a53f867b7410606f62\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/7", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 7}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"fe5dbbcea5ce7e2988b8c69bcfdfde8904aabc1f-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/8", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 8}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"0ade7c2cf97f75d009975f4d720d1fa6c19f4897-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/9", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 9}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"b1d5781111d84f7b3fe45a0852e59758cd7a87e5-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/10", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 10}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"17ba0791499db908433b80f37c5fbc89b870084b-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/11", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 11}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"7b52009b64fd0a2a49e6d8a939753077792b0554-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/12", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 12}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"bd307a3ec329e10a2cff8fb87480823da114f8f4-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/13", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 13}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"fa35e192121eabf3dabf9f5ea6abdbcbc107ac3b-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/14", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 14}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"f1abd670358e036c31296e66b3b66c382ac00812-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/15", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 15}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"1574bddb75c78a6fd2251d61e2993b5146201319-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/16", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 16}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"0716d9708d321ffb6a00818614779e779925365c-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/17", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 17}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"9e6a55b6b4563e652a23be9d623ca5055c356940-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/18", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 18}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"b3f0c7f6bb763af1be91d9e74eabfeb199dc1f1f-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/19", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 19}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"91032ad7bbcb6cf72875e8e8207dcfba80173f7c-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/20", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 20}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"472b07b9fcf2c2451e8781e944bf5f77cd8457c8-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/21", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 21}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"12c6fc06c99a462375eeb3f43dfd832b08ca9e17-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/22", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 22}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"d435a6cdd786300dff204ee7c2ef942d3e9034e2-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/23", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 23}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"4d134bc072212ace2df385dae143139da74ec0ef-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/24", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 24}, {"name": null, "is_subscriber_updateable": false, "https_etag": "\"f6e1126cedebf23e1463aee73f9df08783640400-f8cbecaf9f2b0d467aebe3909b23a65d1e7c7a82\"", "self_link": "https://api.aweber.com/1.0/accounts/1/lists/303449/custom_fields/25", "resource_type_link": "https://api.aweber.com/1.0/#custom_field", "id": 25}]}
6 changes: 6 additions & 0 deletions tests/mock_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
'/accounts/1/lists/303449': ({}, 'lists/303449'),
'/accounts/1/lists/505454': ({}, 'lists/505454'),
'/accounts/1/lists/303449/campaigns': ({}, 'campaigns/303449'),
'/accounts/1/lists/303449/custom_fields': ({}, 'custom_fields/303449'),
'/accounts/1/lists/303449/custom_fields/1': ({}, 'custom_fields/1'),
'/accounts/1/lists/303449/custom_fields/2': ({}, 'custom_fields/2'),
'/accounts/1/lists/303449/subscribers': ({}, 'subscribers/page1'),
'/accounts/1/lists/303449/subscribers/1': ({}, 'subscribers/1'),
'/accounts/1/lists/303449/subscribers/2': ({}, 'subscribers/2'),
Expand All @@ -30,6 +33,9 @@
'ws.show=total_size': ({}, 'subscribers/find_ts'),
},
'POST' : {
'/accounts/1/lists/303449/custom_fields': ({
'status': '201',
'location': '/accounts/1/lists/303449/custom_fields/2'}, None),
'/accounts/1/lists/303449/subscribers/1': ({
'status': '201',
'location': '/accounts/1/lists/505454/subscribers/3'}, None),
Expand Down
35 changes: 35 additions & 0 deletions tests/test_aweber_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,38 @@ def test_find_should_handle_errors(self):
assert subscribers == False
assert request['url'] == \
'{0}?ws.op=find&name=joe'.format(base_url)


class TestCreatingCustomFields(TestCase):

def setUp(self):
self.aweber = AWeberAPI('1', '2')
self.aweber.adapter = MockAdapter()
cf_url = '/accounts/1/lists/303449/custom_fields'
self.cf = self.aweber.load_from_url(cf_url)

self.aweber.adapter.requests = []
self.resp = self.cf.create(name='Wedding Song')
self.create_req = self.aweber.adapter.requests[0]
self.get_req = self.aweber.adapter.requests[1]

def test_returned_true(self):
self.assertTrue(self.resp)

def test_should_have_requested_create_with_post(self):
self.assertEqual(self.create_req['method'], 'POST')

def test_should_have_requested_create_on_cf(self):
self.assertEqual(self.create_req['url'] , self.cf.url)

def test_should_have_requested_move_with_correct_parameters(self):
expected_params = {'ws.op': 'create', 'name': 'Wedding Song'}
self.assertEqual(self.create_req['data'], expected_params)

def test_should_make_two_requests(self):
self.assertEqual(len(self.aweber.adapter.requests), 2)

def test_should_refresh_cf_resource(self):
self.assertEqual(self.get_req['method'], 'GET')
self.assertEqual(self.get_req['url'] ,
'/accounts/1/lists/303449/custom_fields/2')