From 1ee10fda132e132ca99ddcc7ff7149cebc4d96a2 Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Mon, 25 Jul 2016 12:48:10 -0700 Subject: [PATCH] Adding support for v2 api_key naming --- sendgrid/sendgrid.py | 11 +++++++++++ test/test_sendgrid.py | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sendgrid/sendgrid.py b/sendgrid/sendgrid.py index ac043b002..efef3c9ae 100644 --- a/sendgrid/sendgrid.py +++ b/sendgrid/sendgrid.py @@ -14,6 +14,9 @@ def __init__(self, **opts): """ self.path = opts.get('path', os.path.abspath(os.path.dirname(__file__))) self._apikey = opts.get('apikey', os.environ.get('SENDGRID_API_KEY')) + # Support v2 api_key naming + self._apikey = opts.get('api_key', os.environ.get('SENDGRID_API_KEY')) + self._api_key = self._apikey self.useragent = 'sendgrid/{0};python'.format(__version__) self.host = opts.get('host', 'https://api.sendgrid.com') self.version = __version__ @@ -35,3 +38,11 @@ def apikey(self): @apikey.setter def apikey(self, value): self._apikey = value + + @property + def api_key(self): + return self._apikey + + @api_key.setter + def api_key(self, value): + self._apikey = value \ No newline at end of file diff --git a/test/test_sendgrid.py b/test/test_sendgrid.py index d9f7774f2..b96291b0f 100644 --- a/test/test_sendgrid.py +++ b/test/test_sendgrid.py @@ -18,7 +18,7 @@ class UnitTests(unittest.TestCase): def setUpClass(cls): cls.host = host cls.path = '{0}{1}'.format(os.path.abspath(os.path.dirname(__file__)), '/..') - cls.sg = sendgrid.SendGridAPIClient(host=host, path=cls.path) + cls.sg = sendgrid.SendGridAPIClient(host=host, path=cls.path, api_key=os.environ.get('SENDGRID_API_KEY')) if os.path.isfile('/usr/local/bin/prism') == False: if sys.platform != 'win32': try: @@ -38,6 +38,8 @@ def setUpClass(cls): def test_apikey_init(self): self.assertEqual(self.sg.apikey, os.environ.get('SENDGRID_API_KEY')) + # Support the previous naming convention for API keys + self.assertEqual(self.sg.api_key, self.sg.apikey) def test_useragent(self): useragent = '{0}{1}{2}'.format('sendgrid/', __version__, ';python')