|  | 
| 2 | 2 | # pylint: disable=E0611 | 
| 3 | 3 | from __future__ import unicode_literals | 
| 4 | 4 | from janrain.capture.exceptions import ApiResponseError | 
|  | 5 | +from janrain.capture.version import get_version | 
| 5 | 6 | from json import dumps as to_json | 
| 6 | 7 | from contextlib import closing | 
| 7 | 8 | from base64 import b64encode | 
| @@ -151,15 +152,23 @@ class Api(object): | 
| 151 | 152 |         api = janrain.capture.Api("https://...", defaults) | 
| 152 | 153 |         count = api.call("entity.count", type_name="user") | 
| 153 | 154 |     """ | 
| 154 |  | -    def __init__(self, api_url, defaults={}, compress=True, sign_requests=True): | 
|  | 155 | +    def __init__(self, api_url, defaults={}, compress=True, sign_requests=True, | 
|  | 156 | +                 user_agent=None): | 
|  | 157 | + | 
| 155 | 158 |         if api_url[0:4] == "http": | 
| 156 | 159 |             self.api_url = api_url | 
| 157 | 160 |         else: | 
| 158 | 161 |             self.api_url = "https://" + api_url | 
|  | 162 | + | 
| 159 | 163 |         self.defaults = defaults | 
| 160 | 164 |         self.sign_requests = sign_requests | 
| 161 | 165 |         self.compress = compress | 
| 162 | 166 | 
 | 
|  | 167 | +        if not user_agent: | 
|  | 168 | +            self.user_agent = "janrain-python-api {}".format(get_version()) | 
|  | 169 | +        else: | 
|  | 170 | +            self.user_agent = user_agent | 
|  | 171 | + | 
| 163 | 172 | 
 | 
| 164 | 173 |     def call(self, api_call, **kwargs): | 
| 165 | 174 |         """ | 
| @@ -197,6 +206,9 @@ def call(self, api_call, **kwargs): | 
| 197 | 206 |         else: | 
| 198 | 207 |             headers = {} | 
| 199 | 208 | 
 | 
|  | 209 | +        # Custom user agent string | 
|  | 210 | +        headers['User-Agent'] = self.user_agent | 
|  | 211 | + | 
| 200 | 212 |         # Print the parameters (for debugging) | 
| 201 | 213 |         print_params = params.copy() | 
| 202 | 214 |         if 'client_secret' in print_params: | 
|  | 
0 commit comments