===================
Mailman REST Client
===================
>>> from pprint import pprint
# The test framework starts out with an example domain, so let's delete
# that first.
>>> from mailman.interfaces.domain import IDomainManager
>>> from zope.component import getUtility
>>> domain_manager = getUtility(IDomainManager)
>>> domain_manager.remove('example.com')
<Domain example.com...>
>>> transaction.commit()
First let's get an instance of MailmanRESTClient.
>>> from mailmanclient.rest import MailmanRESTClient, MailmanRESTClientError
>>> client = MailmanRESTClient('localhost:8001')
So far there are no lists.
>>> client.get_lists()
[]
Domains
=======
In order to add new lists first a new domain has to be added.
>>> new_domain = client.create_domain('example.com')
>>> pprint(new_domain.info)
{u'base_url': u'http://example.com',
u'contact_address': u'postmaster@example.com',
u'description': None,
u'email_host': u'example.com',
u'http_etag': u'"6b1ccf042e8f76138a0bd37e8509f364da92a5c5"',
u'self_link': u'http://localhost:8001/3.0/domains/example.com',
u'url_host': u'example.com'}
Later the domain object can be instantiated using get_domain()
>>> my_domain = client.get_domain('example.com')
Mailing lists
=============
Now let's add s mailing list called 'test-one'.
>>> new_list = my_domain.create_list('test-one')
Let's add another list and get some information on the list.
>>> another_list = my_domain.create_list('test-two')
>>> pprint(another_list.info)
{u'fqdn_listname': u'test-two@example.com',
u'host_name': u'example.com',
u'http_etag': u'"a05542c9faa07cbe2b8fdf8a1655a2361ab365f2"',
u'list_name': u'test-two',
u'real_name': u'Test-two',
u'self_link': u'http://localhost:8001/3.0/lists/test-two@example.com'}
Later the new list can be instantiated using get_list():
>>> some_list = client.get_list('test-one@example.com')
Also a ``config`` dictionary is populated with some default list configuration options
>>> pprint(some_list.config)
{u'acceptable_aliases': [],
...
u'description': u'',
...
u'real_name': u'Test-one',
...
You can change these options:
>>> data = dict(real_name='Fnorg',
... description='Discuss all things Fnorg')
>>> some_list.update_config(data)
200
>>> some_list.config['real_name']
u'Fnorg'
>>> some_list.config['description']
u'Discuss all things Fnorg'
New instances of the list also show these changes:
>>> some_list = client.get_list('test-one@example.com')
>>> pprint(some_list.config)
{u'acceptable_aliases': [],
...
u'description': u'Discuss all things Fnorg',
...
u'real_name': u'Fnorg',
...
The lists have been added and get_lists() returns a list of dicts, sorted
by fqdn_listname.
>>> pprint(client.get_lists())
[{u'fqdn_listname': u'test-one@example.com',
u'host_name': u'example.com',
...
u'list_name': u'test-one',
u'real_name': u'Fnorg',
u'self_link': u'http://localhost:8001/3.0/lists/test-one@example.com'},
{u'fqdn_listname': u'test-two@example.com',
u'host_name': u'example.com',
...
u'list_name': u'test-two',
u'real_name': u'Test-two',
u'self_link': u'http://localhost:8001/3.0/lists/test-two@example.com'}]
Membership
==========
Since we now have a list we should add some members to it (.subscribe()
returns an HTTP status code, ideally 201)
>>> new_list.subscribe('jack@example.com', 'Jack')
201
>>> new_list.subscribe('meg@example.com', 'Meg')
201
>>> another_list.subscribe('jack@example.com', 'Jack')
201
We can get a list of all members:
>>> pprint(client.get_members())
[{u'http_etag': u'"320f9e380322cafbbf531c11eab1ec9d38b3bb99"',
u'self_link': u'http://localhost:8001/3.0/lists/test-one@example.com/member/jack@example.com'},
{u'http_etag': u'"cd75b7e93216a022573534d948511edfbfea06cd"',
u'self_link': u'http://localhost:8001/3.0/lists/test-one@example.com/member/meg@example.com'},
{u'http_etag': u'"13399f5ebbab8c474926a7ad0ccfda28d717e398"',
u'self_link': u'http://localhost:8001/3.0/lists/test-two@example.com/member/jack@example.com'}]
Or just the members of a specific list:
>>> pprint(new_list.get_members())
[{u'http_etag': u'"320f9e380322cafbbf531c11eab1ec9d38b3bb99"',
u'self_link': u'http://localhost:8001/3.0/lists/test-one@example.com/member/jack@example.com'},
{u'http_etag': u'"cd75b7e93216a022573534d948511edfbfea06cd"',
u'self_link': u'http://localhost:8001/3.0/lists/test-one@example.com/member/meg@example.com'}]
After a while Meg decides to unsubscribe from the mailing list (like
.subscribe() .unsubscribe() returns an HTTP status code, ideally 200).
>>> new_list.unsubscribe('meg@example.com')
200
You can delete lists via their domain:
>>> my_domain.delete_list('test-two')
204