Skip to content

Commit

Permalink
Adding support for v2 api_key naming
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkingserious committed Jul 25, 2016
1 parent 27ca77f commit 1ee10fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions sendgrid/sendgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -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
4 changes: 3 additions & 1 deletion test/test_sendgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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')
Expand Down

0 comments on commit 1ee10fd

Please sign in to comment.