8000 Send the library and python versions in the UA string · Stackdriver/twilio-python@a20cd26 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 1, 2018. It is now read-only.

Commit a20cd26

Browse files
committed
Send the library and python versions in the UA string
1 parent 1030ce5 commit a20cd26

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

tests/test_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ def setUp(self):
2121
def test_request(self, mock):
2222
self.client.request("2010-04-01", method="GET")
2323
mock.assert_called_with("GET", "https://api.twilio.com/2010-04-01",
24-
headers={"User-Agent": 'twilio-python',
24+
headers={"User-Agent": ANY,
2525
'Accept-Charset': 'utf-8'},
2626
params={}, auth=AUTH, data=None)
27+
called_kwargs = mock.mock_calls[0][2]
28+
self.assertTrue(
29+
'twilio-python' in called_kwargs['headers']['User-Agent']
30+
)
2731

2832
def test_connect_apps(self):
2933
self.assertIsInstance(self.client.connect_apps,

twilio/rest/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
import os
3+
import platform
34
from twilio import TwilioException
5+
from twilio import __version__ as LIBRARY_VERSION
46
from twilio.rest.resources import make_request
57
from twilio.rest.resources import Accounts
68
from twilio.rest.resources import Applications
@@ -76,8 +78,13 @@ def request(self, path, method=None, vars=None):
7678
elif method == "POST" or method == "PUT":
7779
data = vars
7880

81+
user_agent = "twilio-python {} (python-{})".format(
82+
LIBRARY_VERSION,
83+
platform.python_version(),
84+
)
85+
7986
headers = {
80-
"User-Agent": "twilio-python",
87+
"User-Agent": user_agent,
8188
"Accept-Charset": "utf-8",
8289
}
8390

0 commit comments

Comments
 (0)
0