Skip to content

Commit 55852e5

Browse files
Merge pull request #195 from sendgrid/support-old-apikey-name
Adding support for v2 api_key naming
2 parents 27ca77f + 1ee10fd commit 55852e5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sendgrid/sendgrid.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def __init__(self, **opts):
1414
"""
1515
self.path = opts.get('path', os.path.abspath(os.path.dirname(__file__)))
1616
self._apikey = opts.get('apikey', os.environ.get('SENDGRID_API_KEY'))
17+
# Support v2 api_key naming
18+
self._apikey = opts.get('api_key', os.environ.get('SENDGRID_API_KEY'))
19+
self._api_key = self._apikey
1720
self.useragent = 'sendgrid/{0};python'.format(__version__)
1821
self.host = opts.get('host', 'https://api.sendgrid.com')
1922
self.version = __version__
@@ -35,3 +38,11 @@ def apikey(self):
3538
@apikey.setter
3639
def apikey(self, value):
3740
self._apikey = value
41+
42+
@property
43+
def api_key(self):
44+
return self._apikey
45+
46+
@api_key.setter
47+
def api_key(self, value):
48+
self._apikey = value

test/test_sendgrid.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class UnitTests(unittest.TestCase):
1818
def setUpClass(cls):
1919
cls.host = host
2020
cls.path = '{0}{1}'.format(os.path.abspath(os.path.dirname(__file__)), '/..')
21-
cls.sg = sendgrid.SendGridAPIClient(host=host, path=cls.path)
21+
cls.sg = sendgrid.SendGridAPIClient(host=host, path=cls.path, api_key=os.environ.get('SENDGRID_API_KEY'))
2222
if os.path.isfile('/usr/local/bin/prism') == False:
2323
if sys.platform != 'win32':
2424
try:
@@ -38,6 +38,8 @@ def setUpClass(cls):
3838

3939
def test_apikey_init(self):
4040
self.assertEqual(self.sg.apikey, os.environ.get('SENDGRID_API_KEY'))
41+
# Support the previous naming convention for API keys
42+
self.assertEqual(self.sg.api_key, self.sg.apikey)
4143

4244
def test_useragent(self):
4345
useragent = '{0}{1}{2}'.format('sendgrid/', __version__, ';python')

0 commit comments

Comments
 (0)