From a20cd26aa18d8109c41b26e14a2b4d5f55d81511 Mon Sep 17 00:00:00 2001 From: Sam Kimbrel Date: Mon, 12 Aug 2013 15:54:42 -0700 Subject: [PATCH 1/2] Send the library and python versions in the UA string --- tests/test_client.py | 6 +++++- twilio/rest/__init__.py | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index c52f7c2aef..b7067ae865 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -21,9 +21,13 @@ def setUp(self): def test_request(self, mock): self.client.request("2010-04-01", method="GET") mock.assert_called_with("GET", "https://api.twilio.com/2010-04-01", - headers={"User-Agent": 'twilio-python', + headers={"User-Agent": ANY, 'Accept-Charset': 'utf-8'}, params={}, auth=AUTH, data=None) + called_kwargs = mock.mock_calls[0][2] + self.assertTrue( + 'twilio-python' in called_kwargs['headers']['User-Agent'] + ) def test_connect_apps(self): self.assertIsInstance(self.client.connect_apps, diff --git a/twilio/rest/__init__.py b/twilio/rest/__init__.py index 2c9cbcbcc3..7198f95e31 100644 --- a/twilio/rest/__init__.py +++ b/twilio/rest/__init__.py @@ -1,6 +1,8 @@ import logging import os +import platform from twilio import TwilioException +from twilio import __version__ as LIBRARY_VERSION from twilio.rest.resources import make_request from twilio.rest.resources import Accounts from twilio.rest.resources import Applications @@ -76,8 +78,13 @@ def request(self, path, method=None, vars=None): elif method == "POST" or method == "PUT": data = vars + user_agent = "twilio-python {} (python-{})".format( + LIBRARY_VERSION, + platform.python_version(), + ) + headers = { - "User-Agent": "twilio-python", + "User-Agent": user_agent, "Accept-Charset": "utf-8", } From dfd300405725bd9573ec38e99f1513517f5843d2 Mon Sep 17 00:00:00 2001 From: Sam Kimbrel Date: Mon, 12 Aug 2013 17:07:18 -0700 Subject: [PATCH 2/2] Use % instead of format because python 2.5 --- twilio/rest/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twilio/rest/__init__.py b/twilio/rest/__init__.py index 7198f95e31..784f5c874b 100644 --- a/twilio/rest/__init__.py +++ b/twilio/rest/__init__.py @@ -78,7 +78,7 @@ def request(self, path, method=None, vars=None): elif method == "POST" or method == "PUT": data = vars - user_agent = "twilio-python {} (python-{})".format( + user_agent = "twilio-python %s (python-%s)" % ( LIBRARY_VERSION, platform.python_version(), )