Skip to content

Commit 6361653

Browse files
committed
Merge pull request #4 from moogar0880/master
Refactored Python SDK
2 parents 130acec + ff6b06d commit 6361653

35 files changed

+2097
-1201
lines changed

HISTORY.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
Release History
22
---------------
3+
1.0.0 (2014-08-05)
4+
++++++++++++++++++
5+
6+
* Revamed how sessions are structured to support the new SessionEngine interface
7+
* Message Management is now out of BETA due to many bug fixes and additional testing
8+
* You can now have one SessionEngine instance (Singleton) per Thread
9+
* Added File Encoding definitions to source code
10+
* Updated dyn.mm docs to actually include code samples
11+
* Adding some general information on sessions, primarily for my own sanity
12+
* Added EMail subclasses for easier formatting/sending of EMail messages
13+
* mm.session.session and tm.session.session functions have been replaced by the SessionEngine get_session class method
14+
* Completed the dyn.mm.reports module
15+
* Misc MM related bug fixes
16+
17+
0.9.11 (2014-07-25)
18+
+++++++++++++++++++
19+
20+
* Fixed a bug with how calls to ``get_all_zones`` created ``Zone`` objects
21+
* Tackled a possible bug also stemming from ``get_all_zones`` calls where a ``Zone``'s ``contact`` and ``ttl`` attributes could always be ``None``
22+
323
0.9.10 (2014-07-07)
424
+++++++++++++++++++
525

README.rst

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,3 @@ services.
77
Requires Python 2.6 or higher, or the "simplejson" package.
88

99
For full documentation and examples see the dyn module on `Read The Docs <http://dyn.readthedocs.org>`_.
10-
11-
Dyn Inc, Integration Team Deliverable
12-
"Copyright © 2014, Dyn Inc.
13-
All rights reserved.
14-
15-
Redistribution and use in source and binary forms, with or without
16-
modification, are permitted provided that the following conditions are
17-
met:
18-
19-
* Redistribution of source code must retain the above copyright notice,
20-
this list of conditions and the following disclaimer.
21-
22-
* Redistribution in binary form must reproduce the above copyright
23-
notice, this list of conditions and the following disclaimer in the
24-
documentation and/or other materials provided with the distribution.
25-
26-
* Neither the name of Dynamic Network Services, Inc. nor the names of
27-
its contributors may be used to endorse or promote products derived
28-
from this software without specific prior written permission.
29-
30-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32-
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33-
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
34-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
37-
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38-
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39-
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
40-
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
41-
42-
--------------------------------------------------------------------------

docs/core.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. _core-index:
2+
3+
Core
4+
====
5+
The :mod:`dyn.core` module contains functionality that is core to the behavior
6+
of the rest of the library. In particular this is where a lot of the "heavy lifting"
7+
for sessions is done.
8+
9+
10+
Singleton
11+
---------
12+
.. autoclass:: dyn.core.Singleton
13+
:members:
14+
:undoc-members:
15+
16+
SessionEngine
17+
-------------
18+
.. autoclass:: dyn.core.SessionEngine
19+
:members:
20+
:undoc-members:

docs/index.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
contain the root `toctree` directive.
55
66
7-
dyn: The Dyn API Python Wrapper
8-
===============================
7+
dyn: The Dyn Python SDK
8+
=======================
99

1010
Release v\ |version|. (:ref:`Installation <install>`)
1111

12-
With the latest release of this dyn wrapper, it's now even easier to manage
13-
both your Dyn Traffic Management and Message Management services.
12+
With the latest release of this sdk, it's now even easier to manage both your
13+
Dyn Traffic Management and Message Management services.
1414

1515
::
1616

@@ -37,6 +37,7 @@ Contents:
3737
quickstart
3838
tm
3939
mm
40+
sessions
4041

4142

4243
Indices and tables

docs/mm.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
.. _dyn-mm:
22

3-
dyn.mm (Message Management) (BETA) Module
4-
=========================================
5-
WARNING: The dyn.mm module is still very much in development and is not complete
6-
and has not been thuroughly tested.
7-
3+
dyn.mm (Message Management) Module
4+
==================================
85
The dyn.mm (MM) module provides access to all of the Message Management
96
resources provided by
107
`Dyn's Message Management REST API <https://help.dynect.net/api/>`_.

docs/mm/accounts.rst

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,105 @@
22

33
MM Accounts
44
===========
5+
The :mod:`~dyn.mm.accounts` module contains interfaces for all of the various Account
6+
management features offered by the dyn Message Management REST API
57

6-
dyn.mm.accounts module
7-
----------------------
8+
Search/List Functions
9+
---------------------
10+
The following functions return a single ``list`` containing class representations
11+
of their respective types. For instance
12+
:func:`get_all_users` returns a ``list`` of :class:`User` objects.
813

9-
.. automodule:: dyn.mm.accounts
14+
.. autofunction:: dyn.mm.accounts.get_all_accounts
15+
16+
.. autofunction:: dyn.mm.accounts.get_all_senders
17+
18+
.. autofunction:: dyn.mm.accounts.get_all_suppressions
19+
20+
21+
Account
22+
-------
23+
24+
.. autoclass:: dyn.mm.accounts.Account
25+
:members:
26+
:undoc-members:
27+
28+
Create a new Account
29+
^^^^^^^^^^^^^^^^^^^^
30+
The following example shows how to create a new :class:`~dyn.mm.accounts.Account`
31+
on the Dyn Message Management system::
32+
33+
>>> from dyn.mm.accounts import Account
34+
>>> new_account = Account('username', 'password', 'companyname', '1 (603) 867-5309')
35+
>>> new_account
36+
<MM Account>: username
37+
>>> new_account.xheaders
38+
{}
39+
40+
41+
Using an Existing Account
42+
^^^^^^^^^^^^^^^^^^^^^^^^^
43+
The following example shows how to get an do some simple manipulation of an existing
44+
dyn Message Management account::
45+
46+
>>> from dyn.mm.accounts import Account
47+
>>> new_account = Account('username')
48+
>>> new_account.apikey
49+
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
50+
>>> new_account.generate_new_apikey()
51+
>>> new_account.apikey
52+
'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
53+
>>> new_account.xheaders
54+
{'xheader1': '', 'xheader2': '', 'xheader3': '', 'xheader4': ''}
55+
>>> # The following creates a new xheader for the account
56+
>>> new_account.xheaders['xheader3'] = 'X-header3_data'
57+
58+
59+
Approved Sender
60+
---------------
61+
62+
.. autoclass:: dyn.mm.accounts.ApprovedSender
1063
:members:
1164
:undoc-members:
1265

66+
Create a new Approved Sender
67+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68+
Approved senders are pretty straightforward as far as functionality goes but here
69+
we'll see how to create a new :class:`~dyn.mm.accounts.ApprovedSender`::
70+
71+
>>> from dyn.mm.accounts import ApprovedSender
72+
>>> sender = ApprovedSender('[email protected]', seeding=0)
73+
>>> sender.status
74+
1
75+
>>> sender.seeding
76+
0
77+
>>> sender.seeding = 1
78+
79+
Recipient
80+
---------
81+
82+
.. autoclass:: dyn.mm.accounts.Recipient
83+
:members:
84+
:undoc-members:
85+
86+
Creating/Using Recipients
87+
^^^^^^^^^^^^^^^^^^^^^^^^^
88+
Recipients are the one model you'll find in this library that don't have an intuitive
89+
way to distinguish what you're trying to accomplish simply from the arguments you provide
90+
at create time. Because of this, you'll need to pass a method type, either GET or POST,
91+
to the Recipient when you create it::
92+
93+
>>> from dyn.mm.accounts import Recipient
94+
>>> recipient = Recipient('[email protected]', method='POST')
95+
>>> recipient.status
96+
'inactive'
97+
>>> recipient.activate()
98+
>>> recipient.status
99+
'active'
100+
101+
Suppression
102+
-----------
103+
104+
.. autoclass:: dyn.mm.accounts.Suppression
105+
:members:
106+
:undoc-members:

docs/mm/errors.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
MM Errors
44
=========
5+
Below are the various errors you may see be raised while using the dyn.mm module
6+
along with brief descriptions about when those exceptions are raised.
57

68
dyn.mm.errors module
79
--------------------

docs/mm/message.rst

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,105 @@
22

33
Messages
44
========
5+
The dyn.mm.message module is where you'll find the ability to easily automate the
6+
sending of messages.
57

6-
dyn.mm.message module
7-
---------------------
8+
send_message
9+
------------
10+
The :func:`~dyn.mm.message.send_message` function allows a user to quickly fire off
11+
an email via the Message Management API
812

9-
.. automodule:: dyn.mm.message
13+
.. autofunction:: dyn.mm.message.send_message
14+
15+
Using send_message
16+
^^^^^^^^^^^^^^^^^^
17+
Below is just a quick example on how to use :func:`~dyn.mm.message.send_message`::
18+
19+
>>> from dyn.mm.message import send_message
20+
>>> from_email = '[email protected]'
21+
>>> to_email = '[email protected]'
22+
>>> subject = 'A Demo Email'
23+
>>> content = 'Hello User, thank you for registering at http://mysite.com!'
24+
>>> send_message(from_email, to_email, subject, body=content)
25+
26+
27+
EMail
28+
-----
29+
30+
.. autoclass:: dyn.mm.message.EMail
31+
:members:
32+
:undoc-members:
33+
34+
Using the EMail Base class
35+
^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
The ability to be able to customize your messages become far more apparent with
37+
the use of the :class:`~dyn.mm.message.EMail` class as you can see in the example
38+
below it's very easy to use this class for templating, or even subclassing to make
39+
sending emails quick and easy::
40+
41+
>>> from dyn.mm.message import EMail
42+
>>> from_email = '[email protected]'
43+
>>> to_email = '[email protected]'
44+
>>> subject = 'A Demo Email'
45+
>>> content = 'Hello %s, thank you for registering at http://mysite.com!'
46+
>>> mailer = EMail(from_email, to_email, subject)
47+
>>> user_names = ['Jon', 'Ray', 'Carol', 'Margaret']
48+
>>> for user_name in user_names:
49+
... mailer.body = content % user_name
50+
... mailer.send()
51+
52+
53+
EMail Subclasses
54+
----------------
55+
Below are some :class:`~dyn.mm.message.EMail` subclasses which provide some additional
56+
formatting and, hopefully, helpful features.
57+
58+
.. autoclass:: dyn.mm.message.HTMLEMail
1059
:members:
1160
:undoc-members:
1261

62+
.. autoclass:: dyn.mm.message.TemplateEMail
63+
:members:
64+
:undoc-members:
65+
66+
.. autoclass:: dyn.mm.message.HTMLTemplateEMail
67+
:members:
68+
:undoc-members:
69+
70+
Using the EMail Subclasses
71+
^^^^^^^^^^^^^^^^^^^^^^^^^^
72+
The :class:`~dyn.mm.message.HTMLEMail` class is identical to the :class:`~dyn.mm.message.EMail`
73+
class, with the only difference being that content passed to it's send method will
74+
be added as the messages HTML content, rather than text content.
75+
76+
The Templating subclasses behave slightly differently. For the :class:`~dyn.mm.message.TemplateEmail`
77+
class, you provide it a template at construction time, and an iterable with the content
78+
to substitute into the template at send time. For example::
79+
80+
>>> from dyn.mm.message import TemplateEmail
81+
>>> from_email = '[email protected]'
82+
>>> to_email = '[email protected]'
83+
>>> subject = 'A Demo Email'
84+
>>> template = 'Hello %s, thank you for registering at http://mysite.com!'
85+
>>> mailer = TemplateEmail(from_email, to_email, subject, body=template)
86+
>>> parameters = ['Jon', 'Ray', 'Carol', 'Margaret']
87+
>>> mailer.send(parameters)
88+
89+
Similarly you can use the :class:`~dyn.mm.message.HTMLTemplateEMail` class to template out and send
90+
multiple HTML formatted emails easily. Let's go over a slightly more complex for that class::
91+
92+
>>> from textwrap import dedent
93+
>>> from dyn.mm.message import TemplateEmail
94+
>>> from_email = '[email protected]'
95+
>>> to_email = '[email protected]'
96+
>>> subject = 'A Demo Email'
97+
>>> template = """
98+
<html>
99+
<h1>What... is the air-speed velocity of an unladen swallow?</h1>
100+
<h2>What do you mean? An %(choice1) or %(choice2) swallow?</h2>
101+
</html>"""
102+
>>> template = dedent(template)
103+
>>> mailer = HTMLTemplateEmail(from_email, to_email, subject, html=template)
104+
>>> parameters = {'choice1': 'African', 'choice2': 'European'}
105+
>>> mailer.send(parameters)
106+

0 commit comments

Comments
 (0)