Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add library User-Agent header #123

Merged
merged 7 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions webexteamssdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
import logging

import webexteamssdk.models.cards as cards
from ._metadata import *
from ._version import get_versions
from ._metadata import (
__author__, __author_email__, __copyright__, __description__,
__download_url__, __license__, __title__, __url__, __version__,
)
from .api import WebexTeamsAPI
from .exceptions import (
AccessTokenError, ApiError, ApiWarning, MalformedResponse, RateLimitError,
Expand All @@ -50,10 +52,6 @@
from .utils import WebexTeamsDateTime


__version__ = get_versions()['version']
del get_versions


# Initialize Package Logging
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
9 changes: 8 additions & 1 deletion webexteamssdk/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
SOFTWARE.
"""


__title__ = 'webexteamssdk'
__description__ = 'Community-developed Python SDK for the Webex Teams APIs'
__url__ = 'https://github.com/CiscoDevNet/webexteamssdk'
Expand All @@ -31,3 +30,11 @@
__author_email__ = 'chrlunsf@cisco.com'
__copyright__ = "Copyright (c) 2016-2019 Cisco Systems, Inc."
__license__ = "MIT"


# Only import the ._version module and compute the version when this module is
# imported.
if __name__ == "webexteamssdk._metadata":
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
21 changes: 19 additions & 2 deletions webexteamssdk/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from .team_memberships import TeamMembershipsAPI
from .teams import TeamsAPI
from .webhooks import WebhooksAPI
import os


class WebexTeamsAPI(object):
Expand All @@ -69,7 +70,9 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
client_secret=None,
oauth_code=None,
redirect_uri=None,
proxies=None):
proxies=None,
be_geo_id=None,
caller=None):
"""Create a new WebexTeamsAPI object.

An access token must be used when interacting with the Webex Teams API.
Expand Down Expand Up @@ -113,6 +116,12 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
OAuth process.
proxies(dict): Dictionary of proxies passed on to the requests
session.
be_geo_id(basestring): Optional partner identifier for API usage
tracking. Defaults to checking for a BE_GEO_ID environment
variable.
caller(basestring): Optional identifier for API usage tracking.
Defaults to checking for a WEBEX_PYTHON_SDK_CALLER environment
variable.

Returns:
WebexTeamsAPI: A new WebexTeamsAPI object.
Expand All @@ -132,6 +141,8 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
check_type(oauth_code, basestring, optional=True)
check_type(redirect_uri, basestring, optional=True)
check_type(proxies, dict, optional=True)
check_type(be_geo_id, basestring, optional=True)
check_type(caller, basestring, optional=True)

access_token = access_token or WEBEX_TEAMS_ACCESS_TOKEN

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

# Set optional API metrics tracking variables from env vars if there
be_geo_id = be_geo_id or os.environ.get('BE_GEO_ID')
caller = caller or os.environ.get('WEBEX_PYTHON_SDK_CALLER')

# If an access token hasn't been provided as a parameter, environment
# variable, or obtained via an OAuth exchange raise an error.
if not access_token:
Expand All @@ -169,7 +184,9 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
base_url=base_url,
single_request_timeout=single_request_timeout,
wait_on_rate_limit=wait_on_rate_limit,
proxies=proxies
proxies=proxies,
be_geo_id=be_geo_id,
caller=caller
)

# API wrappers
Expand Down
3 changes: 2 additions & 1 deletion webexteamssdk/models/cards/adaptive_card_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import json
import enum


class AdaptiveCardComponent:
"""Base class for all Adaptive Card components.

Expand Down Expand Up @@ -65,7 +66,7 @@ def to_dict(self):
if property_value is not None:
if isinstance(property_value, enum.Enum):
property_value = str(property_value)

serialized_data[property_name] = property_value

# Recursively serialize sub-components
Expand Down
Loading