Skip to content

Commit 30c080a

Browse files
authored
Merge pull request #123 from CiscoDevNet/pr/110
Add library User-Agent header
2 parents 54d3f68 + 73757b3 commit 30c080a

File tree

5 files changed

+155
-45
lines changed

5 files changed

+155
-45
lines changed

webexteamssdk/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
import logging
3434

3535
import webexteamssdk.models.cards as cards
36-
from ._metadata import *
37-
from ._version import get_versions
36+
from ._metadata import (
37+
__author__, __author_email__, __copyright__, __description__,
38+
__download_url__, __license__, __title__, __url__, __version__,
39+
)
3840
from .api import WebexTeamsAPI
3941
from .exceptions import (
4042
AccessTokenError, ApiError, ApiWarning, MalformedResponse, RateLimitError,
@@ -50,10 +52,6 @@
5052
from .utils import WebexTeamsDateTime
5153

5254

53-
__version__ = get_versions()['version']
54-
del get_versions
55-
56-
5755
# Initialize Package Logging
5856
logger = logging.getLogger(__name__)
5957
logger.addHandler(logging.NullHandler())

webexteamssdk/_metadata.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
SOFTWARE.
2323
"""
2424

25-
2625
__title__ = 'webexteamssdk'
2726
__description__ = 'Community-developed Python SDK for the Webex Teams APIs'
2827
__url__ = 'https://github.com/CiscoDevNet/webexteamssdk'
@@ -31,3 +30,11 @@
3130
__author_email__ = 'chrlunsf@cisco.com'
3231
__copyright__ = "Copyright (c) 2016-2019 Cisco Systems, Inc."
3332
__license__ = "MIT"
33+
34+
35+
# Only import the ._version module and compute the version when this module is
36+
# imported.
37+
if __name__ == "webexteamssdk._metadata":
38+
from ._version import get_versions
39+
__version__ = get_versions()['version']
40+
del get_versions

webexteamssdk/api/__init__.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from .team_memberships import TeamMembershipsAPI
4949
from .teams import TeamsAPI
5050
from .webhooks import WebhooksAPI
51+
import os
5152

5253

5354
class WebexTeamsAPI(object):
@@ -69,7 +70,9 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
6970
client_secret=None,
7071
oauth_code=None,
7172
redirect_uri=None,
72-
proxies=None):
73+
proxies=None,
74+
be_geo_id=None,
75+
caller=None):
7376
"""Create a new WebexTeamsAPI object.
7477
7578
An access token must be used when interacting with the Webex Teams API.
@@ -113,6 +116,12 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
113116
OAuth process.
114117
proxies(dict): Dictionary of proxies passed on to the requests
115118
session.
119+
be_geo_id(basestring): Optional partner identifier for API usage
120+
tracking. Defaults to checking for a BE_GEO_ID environment
121+
variable.
122+
caller(basestring): Optional identifier for API usage tracking.
123+
Defaults to checking for a WEBEX_PYTHON_SDK_CALLER environment
124+
variable.
116125
117126
Returns:
118127
WebexTeamsAPI: A new WebexTeamsAPI object.
@@ -132,6 +141,8 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
132141
check_type(oauth_code, basestring, optional=True)
133142
check_type(redirect_uri, basestring, optional=True)
134143
check_type(proxies, dict, optional=True)
144+
check_type(be_geo_id, basestring, optional=True)
145+
check_type(caller, basestring, optional=True)
135146

136147
access_token = access_token or WEBEX_TEAMS_ACCESS_TOKEN
137148

@@ -151,6 +162,10 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
151162
redirect_uri=redirect_uri
152163
).access_token
153164

165+
# Set optional API metrics tracking variables from env vars if there
166+
be_geo_id = be_geo_id or os.environ.get('BE_GEO_ID')
167+
caller = caller or os.environ.get('WEBEX_PYTHON_SDK_CALLER')
168+
154169
# If an access token hasn't been provided as a parameter, environment
155170
# variable, or obtained via an OAuth exchange raise an error.
156171
if not access_token:
@@ -169,7 +184,9 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
169184
base_url=base_url,
170185
single_request_timeout=single_request_timeout,
171186
wait_on_rate_limit=wait_on_rate_limit,
172-
proxies=proxies
187+
proxies=proxies,
188+
be_geo_id=be_geo_id,
189+
caller=caller
173190
)
174191

175192
# API wrappers

webexteamssdk/models/cards/adaptive_card_component.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import json
2626
import enum
2727

28+
2829
class AdaptiveCardComponent:
2930
"""Base class for all Adaptive Card components.
3031
@@ -65,7 +66,7 @@ def to_dict(self):
6566
if property_value is not None:
6667
if isinstance(property_value, enum.Enum):
6768
property_value = str(property_value)
68-
69+
6970
serialized_data[property_name] = property_value
7071

7172
# Recursively serialize sub-components

0 commit comments

Comments
 (0)