@@ -22,7 +22,8 @@ class Client(object):
22
22
""" A client for accessing the Twilio API. """
23
23
24
24
def __init__ (self , username = None , password = None , account_sid = None , region = None ,
25
- http_client = None , environment = None , edge = None ):
25
+ http_client = None , environment = None , edge = None ,
26
+ user_agent_extensions = None ):
26
27
"""
27
28
Initializes the Twilio Client
28
29
@@ -33,6 +34,7 @@ def __init__(self, username=None, password=None, account_sid=None, region=None,
33
34
:param HttpClient http_client: HttpClient, defaults to TwilioHttpClient
34
35
:param dict environment: Environment to look for auth details, defaults to os.environ
35
36
:param str edge: Twilio Edge to make requests to, defaults to None
37
+ :param list[str] user_agent_extensions: Additions to the user agent string
36
38
37
39
:returns: Twilio Client
38
40
:rtype: twilio.rest.Client
@@ -49,6 +51,8 @@ def __init__(self, username=None, password=None, account_sid=None, region=None,
49
51
""" :type : str """
50
52
self .region = region or environment .get ('TWILIO_REGION' )
51
53
""" :type : str """
54
+ self .user_agent_extensions = user_agent_extensions or []
55
+ """ :type : list[str] """
52
56
53
57
if not self .username or not self .password :
54
58
raise TwilioException ("Credentials are required to create a TwilioClient" )
@@ -113,10 +117,18 @@ def request(self, method, uri, params=None, data=None, headers=None, auth=None,
113
117
auth = auth or self .auth
114
118
headers = headers or {}
115
119
116
- headers ['User-Agent' ] = 'twilio-python/{} (Python {})' .format (
117
- __version__ ,
118
- platform .python_version (),
120
+ pkg_version = __version__
121
+ os_name = platform .system ()
122
+ os_arch = platform .machine ()
123
+ python_version = platform .python_version ()
124
+ headers ['User-Agent' ] = 'twilio-python/{} ({} {}) Python/{}' .format (
125
+ pkg_version ,
126
+ os_name ,
127
+ os_arch ,
128
+ python_version ,
119
129
)
130
+ for extension in self .user_agent_extensions :
131
+ headers ['User-Agent' ] += ' {}' .format (extension )
120
132
headers ['X-Twilio-Client' ] = 'python-{}' .format (__version__ )
121
133
headers ['Accept-Charset' ] = 'utf-8'
122
134
0 commit comments