Skip to content

Commit bdccfa9

Browse files
author
caberos
committed
add new email feature
1 parent 7b2d070 commit bdccfa9

File tree

10 files changed

+228
-0
lines changed

10 files changed

+228
-0
lines changed

SoftLayer/CLI/email/__init__.py

Whitespace-only changes.

SoftLayer/CLI/email/detail.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""Get details for an image."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
from SoftLayer.CLI import environment
7+
from SoftLayer.CLI import formatting
8+
from SoftLayer.managers.account import AccountManager
9+
from SoftLayer.managers.email import EmailManager
10+
from SoftLayer import utils
11+
12+
13+
@click.command()
14+
@environment.pass_env
15+
def cli(env):
16+
""""""
17+
manager = AccountManager(env.client)
18+
email_manager = EmailManager(env.client)
19+
result = manager.get_Network_Message_Delivery_Accounts()
20+
21+
table = formatting.KeyValueTable(['name', 'value'])
22+
23+
table_information = formatting.KeyValueTable(['id', 'username', 'hostname', 'description', 'vendor'])
24+
table_information.align['id'] = 'r'
25+
table_information.align['username'] = 'l'
26+
27+
for email in result:
28+
# print(email['id'])
29+
table_information.add_row([email.get('id'), email.get('username'), email.get('emailAddress'),
30+
utils.lookup(email, 'type', 'description'),
31+
utils.lookup(email, 'vendor', 'keyName')])
32+
33+
overview_table = _build_overview_table(email_manager.get_AccountOverview(email.get('id')))
34+
statistics = email_manager.get_statistics(email.get('id'),
35+
["requests", "delivered", "opens", "clicks", "bounds"],
36+
True, True, True, 6)
37+
38+
table.add_row(['email information', table_information])
39+
table.add_row(['email overview', overview_table])
40+
for statistic in statistics:
41+
table.add_row(['statistics', _build_statistics_table(statistic)])
42+
43+
env.fout(table)
44+
45+
46+
def _build_overview_table(email_overview):
47+
table = formatting.KeyValueTable(['name', 'value'])
48+
table.align['name'] = 'r'
49+
table.align['value'] = 'l'
50+
51+
table.add_row(['creditsAllowed', email_overview.get('creditsAllowed')])
52+
table.add_row(['creditsRemain', email_overview.get('creditsRemain')])
53+
table.add_row(['package', email_overview.get('package')])
54+
table.add_row(['reputation', email_overview.get('reputation')])
55+
table.add_row(['requests', email_overview.get('requests')])
56+
57+
return table
58+
59+
60+
def _build_statistics_table(statistics):
61+
table = formatting.KeyValueTable(['name', 'value'])
62+
table.align['name'] = 'r'
63+
table.align['value'] = 'l'
64+
65+
table.add_row(['delivered', statistics.get('delivered')])
66+
table.add_row(['requests', statistics.get('requests')])
67+
table.add_row(['bounces', statistics.get('bounces')])
68+
table.add_row(['opens', statistics.get('opens')])
69+
table.add_row(['clicks', statistics.get('clicks')])
70+
table.add_row(['spam Reports', statistics.get('spamReports')])
71+
72+
return table

SoftLayer/CLI/routes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
('block:volume-convert', 'SoftLayer.CLI.block.convert:cli'),
120120
('block:volume-set-note', 'SoftLayer.CLI.block.set_note:cli'),
121121

122+
('email', 'SoftLayer.CLI.email'),
123+
('email:detail', 'SoftLayer.CLI.email.detail:cli'),
124+
122125
('event-log', 'SoftLayer.CLI.event_log'),
123126
('event-log:get', 'SoftLayer.CLI.event_log.get:cli'),
124127
('event-log:types', 'SoftLayer.CLI.event_log.types:cli'),

SoftLayer/fixtures/SoftLayer_Account.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,3 +1076,27 @@
10761076
"username": "SL01SEV1234567_111"
10771077
}
10781078
]
1079+
1080+
getNetworkMessageDeliveryAccounts = [
1081+
{
1082+
"accountId": 147258,
1083+
"createDate": "2020-07-06T10:29:11-06:00",
1084+
"id": 1232123,
1085+
"typeId": 21,
1086+
"username": "test_CLI@ie.ibm.com",
1087+
"vendorId": 1,
1088+
"type": {
1089+
"description": "Delivery of messages through e-mail",
1090+
"id": 21,
1091+
"keyName": "EMAIL",
1092+
"name": "Email"
1093+
},
1094+
"vendor": {
1095+
"id": 1,
1096+
"keyName": "SENDGRID",
1097+
"name": "SendGrid"
1098+
},
1099+
"emailAddress": "test_CLI@ie.ibm.com",
1100+
"smtpAccess": "1"
1101+
}
1102+
]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
getAccountOverview = {
2+
"creditsAllowed": 25000,
3+
"creditsOverage": 0,
4+
"creditsRemain": 25000,
5+
"creditsUsed": 0,
6+
"package": "Free Package",
7+
"reputation": 100,
8+
"requests": 56
9+
}
10+
11+
getStatistics = [{
12+
"blocks": 0,
13+
"bounces": 0,
14+
"clicks": 0,
15+
"date": "2021-04-28",
16+
"delivered": 0,
17+
"invalidEmail": 0,
18+
"opens": 0,
19+
"repeatBounces": 0,
20+
"repeatSpamReports": 0,
21+
"repeatUnsubscribes": 0,
22+
"requests": 0,
23+
"spamReports": 0,
24+
"uniqueClicks": 0,
25+
"uniqueOpens": 0,
26+
"unsubscribes": 0
27+
}]

SoftLayer/managers/email.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
SoftLayer.account
3+
~~~~~~~~~~~~~~~~~~~~~~~
4+
Account manager
5+
6+
:license: MIT, see License for more details.
7+
"""
8+
9+
from SoftLayer import utils
10+
11+
12+
# Invalid names are ignored due to long method names and short argument names
13+
# pylint: disable=invalid-name, no-self-use
14+
15+
16+
class EmailManager(utils.IdentifierMixin, object):
17+
"""Common functions for getting information from the Account service
18+
19+
:param SoftLayer.API.BaseClient client: the client instance
20+
"""
21+
22+
def __init__(self, client):
23+
self.client = client
24+
25+
def get_AccountOverview(self, identifier):
26+
"""Gets all the Network Message Delivery Account Overview
27+
28+
:returns: Network Message Delivery Account overview
29+
"""
30+
return self.client.call('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
31+
'getAccountOverview', id=identifier)
32+
33+
def get_statistics(self, identifier, selectedStatistics,
34+
startDate, endDate, aggregatesOnly, days):
35+
"""Gets statistics Network Message Delivery Account
36+
37+
:returns: statistics Network Message Delivery Account
38+
"""
39+
body = [selectedStatistics,
40+
startDate,
41+
endDate,
42+
aggregatesOnly,
43+
days
44+
]
45+
46+
return self.client.call('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
47+
'getStatistics', id=identifier, *body)

docs/api/managers/email.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.. _email:
2+
3+
.. automodule:: SoftLayer.managers.email
4+
:members:
5+
:inherited-members:

docs/cli/email.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. _cli_email:
2+
3+
Email Commands
4+
=================
5+
6+
7+
.. click:: SoftLayer.CLI.email.detail:cli
8+
:prog: email detail
9+
:show-nested:

tests/CLI/modules/email_tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
SoftLayer.tests.CLI.modules.email_tests
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
5+
Tests for the user cli command
6+
"""
7+
from SoftLayer import testing
8+
9+
10+
class EmailCLITests(testing.TestCase):
11+
12+
def test_detail(self):
13+
result = self.run_command(['email', 'detail'])
14+
self.assert_no_fail(result)
15+
self.assert_called_with('SoftLayer_Account', 'getNetworkMessageDeliveryAccounts')

tests/managers/email_tests.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
SoftLayer.tests.managers.email_tests
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
5+
"""
6+
7+
from SoftLayer.managers.email import EmailManager
8+
from SoftLayer import testing
9+
10+
11+
class AccountManagerTests(testing.TestCase):
12+
13+
def test_get_AccountOverview(self):
14+
self.manager = EmailManager(self.client)
15+
self.manager.get_AccountOverview(1232123)
16+
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
17+
'getAccountOverview')
18+
19+
def test_get_statistics(self):
20+
self.manager = EmailManager(self.client)
21+
self.manager.get_statistics(1232123,
22+
["requests", "delivered", "opens", "clicks", "bounds"],
23+
True,
24+
True, True, 6)
25+
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
26+
'getStatistics')

0 commit comments

Comments
 (0)