Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for v2 api_key naming #195

Merged
merged 1 commit into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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