Skip to content

Commit f5717ec

Browse files
committed
Configure package to use WEBEX_TEAMS_ACCESS_TOKEN environment variable
1 parent c45ad49 commit f5717ec

2 files changed

Lines changed: 18 additions & 20 deletions

File tree

webexteamsdk/api/__init__.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@
2222
SOFTWARE.
2323
"""
2424

25-
26-
import os
27-
2825
from past.types import basestring
2926

3027
from webexteamsdk.config import (
31-
ACCESS_TOKEN_ENVIRONMENT_VARIABLE, DEFAULT_BASE_URL,
32-
DEFAULT_SINGLE_REQUEST_TIMEOUT, DEFAULT_WAIT_ON_RATE_LIMIT,
28+
DEFAULT_BASE_URL, DEFAULT_SINGLE_REQUEST_TIMEOUT,
29+
DEFAULT_WAIT_ON_RATE_LIMIT,
3330
)
31+
from webexteamsdk.environment import WEBEX_TEAMS_ACCESS_TOKEN
3432
from webexteamsdk.exceptions import AccessTokenError
35-
from webexteamsdk.models import spark_data_factory
33+
from webexteamsdk.models.immutable import immutable_data_factory
3634
from webexteamsdk.restsession import RestSession
3735
from webexteamsdk.utils import check_type
3836
from .access_tokens import AccessTokensAPI
@@ -87,33 +85,34 @@ class WebexTeamsAPI(object):
8785
def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
8886
single_request_timeout=DEFAULT_SINGLE_REQUEST_TIMEOUT,
8987
wait_on_rate_limit=DEFAULT_WAIT_ON_RATE_LIMIT,
90-
object_factory=spark_data_factory):
88+
object_factory=immutable_data_factory):
9189
"""Create a new WebexTeamsAPI object.
9290
9391
An access token must be used when interacting with the Webex Teams API.
9492
This package supports two methods for you to provide that access token:
9593
96-
1. You may manually specify the access token via the access_token
94+
1. You may manually specify the access token via the `access_token`
9795
argument, when creating a new WebexTeamsAPI object.
9896
9997
2. If an access_token argument is not supplied, the package checks
100-
for a SPARK_ACCESS_TOKEN environment variable.
98+
for a WEBEX_TEAMS_ACCESS_TOKEN environment variable.
10199
102100
An AccessTokenError is raised if an access token is not provided
103101
via one of these two methods.
104102
105103
Args:
106104
access_token(basestring): The access token to be used for API
107105
calls to the Webex Teams service. Defaults to checking for a
108-
SPARK_ACCESS_TOKEN environment variable.
106+
WEBEX_TEAMS_ACCESS_TOKEN environment variable.
109107
base_url(basestring): The base URL to be prefixed to the
110108
individual API endpoint suffixes.
111109
Defaults to webexteamsdk.DEFAULT_BASE_URL.
112110
single_request_timeout(int): Timeout (in seconds) for RESTful HTTP
113111
requests. Defaults to
114-
webexteamsdk.DEFAULT_SINGLE_REQUEST_TIMEOUT.
112+
webexteamsdk.config.DEFAULT_SINGLE_REQUEST_TIMEOUT.
115113
wait_on_rate_limit(bool): Enables or disables automatic rate-limit
116-
handling. Defaults to webexteamsdk.DEFAULT_WAIT_ON_RATE_LIMIT.
114+
handling. Defaults to
115+
webexteamsdk.config.DEFAULT_WAIT_ON_RATE_LIMIT.
117116
object_factory(callable): The factory function to use to create
118117
Python objects from the returned Webex Teams JSON data objects.
119118
@@ -132,14 +131,13 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
132131
check_type(single_request_timeout, int)
133132
check_type(wait_on_rate_limit, bool)
134133

135-
env_access_token = os.environ.get(ACCESS_TOKEN_ENVIRONMENT_VARIABLE)
136-
access_token = access_token or env_access_token
134+
access_token = access_token or WEBEX_TEAMS_ACCESS_TOKEN
137135
if not access_token:
138-
error_message = "You must provide an Spark access token to " \
139-
"interact with the Webex Teams APIs, either via " \
140-
"a SPARK_ACCESS_TOKEN environment variable " \
141-
"or via the access_token argument."
142-
raise AccessTokenError(error_message)
136+
raise AccessTokenError(
137+
"You must provide a Webex Teams access token to interact with "
138+
"the Webex Teams APIs, either via a SPARK_ACCESS_TOKEN "
139+
"environment variable or via the access_token argument."
140+
)
143141

144142
# Create the API session
145143
# All of the API calls associated with a WebexTeamsAPI object will

webexteamsdk/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ def _get_access_token():
6464

6565

6666
# Package Environment Variables
67-
access_token = _get_access_token()
67+
WEBEX_TEAMS_ACCESS_TOKEN = _get_access_token()

0 commit comments

Comments
 (0)