Skip to content

Commit caf0a79

Browse files
committed
Merge branch 'user-agent-application-info'
2 parents e0ba060 + 740f486 commit caf0a79

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

nexmo/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,18 @@ def __init__(self, **kwargs):
2828

2929
self.api_secret = kwargs.get('secret', None) or os.environ['NEXMO_API_SECRET']
3030

31-
self.headers = {'User-Agent': 'nexmo-python/{0}/{1}'.format(__version__, python_version())}
32-
3331
self.host = 'rest.nexmo.com'
3432

3533
self.api_host = 'api.nexmo.com'
3634

35+
user_agent = 'nexmo-python/{0}/{1}'.format(__version__, python_version())
36+
37+
if 'app_name' in kwargs and 'app_version' in kwargs:
38+
user_agent += '/{0}/{1}'.format(kwargs['app_name'], kwargs['app_version'])
39+
40+
self.headers = {'User-Agent': user_agent}
41+
42+
3743
def send_message(self, params):
3844
return self.post(self.host, '/sms/json', params)
3945

test_nexmo.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,17 @@ def test_server_error(self):
376376

377377
self.assertRaisesRegex(nexmo.ServerError, message, self.client.send_message, {})
378378

379+
@responses.activate
380+
def test_application_info_options(self):
381+
app_name, app_version = 'ExampleApp', 'X.Y.Z'
382+
383+
self.stub(responses.GET, 'https://rest.nexmo.com/account/get-balance')
384+
385+
self.client = nexmo.Client(key=self.api_key, secret=self.api_secret, app_name=app_name, app_version=app_version)
386+
self.user_agent = '/'.join(['nexmo-python', nexmo.__version__, platform.python_version(), app_name, app_version])
387+
388+
self.assertOK(self.client.get_balance())
389+
379390

380391
if __name__ == '__main__':
381392
unittest.main()

0 commit comments

Comments
 (0)