Skip to content

Commit d36477a

Browse files
committed
added proxy feature
1 parent caf316e commit d36477a

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

docs/user/quickstart.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ directly by providing the OAuth information.
150150
redirect_uri=redirect_uri
151151
)
152152
153+
You can also pass a proxy configuration upon initialization in case you are behind a firewall.
154+
155+
.. code-block:: python
156+
>>> from webexteamssdk import WebexTeamsAPI
157+
>>> proxy = {'https': '<proxy_ip>:<proxy_port>'}
158+
>>> api = WebexTeamsAPI(access_token=<your_access_token>, proxy_dict=proxy)
159+
160+
153161
Making API Calls
154162
----------------
155163

webexteamssdk/api/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
6666
client_id=None,
6767
client_secret=None,
6868
oauth_code=None,
69-
redirect_uri=None):
69+
redirect_uri=None,
70+
proxy_dict=None):
7071
"""Create a new WebexTeamsAPI object.
7172
7273
An access token must be used when interacting with the Webex Teams API.
@@ -108,6 +109,8 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
108109
the user oauth process.
109110
oauth_redirect_uri(basestring): The redirect URI used in the user
110111
OAuth process.
112+
proxy_dict(dict): Dictionary of proxies passed on to the requests
113+
session.
111114
112115
Returns:
113116
WebexTeamsAPI: A new WebexTeamsAPI object.
@@ -126,6 +129,7 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
126129
check_type(client_secret, basestring, may_be_none=True)
127130
check_type(oauth_code, basestring, may_be_none=True)
128131
check_type(redirect_uri, basestring, may_be_none=True)
132+
check_type(proxy_dict, dict, may_be_none=True)
129133

130134
access_token = access_token or WEBEX_TEAMS_ACCESS_TOKEN
131135

@@ -162,7 +166,8 @@ def __init__(self, access_token=None, base_url=DEFAULT_BASE_URL,
162166
access_token=access_token,
163167
base_url=base_url,
164168
single_request_timeout=single_request_timeout,
165-
wait_on_rate_limit=wait_on_rate_limit
169+
wait_on_rate_limit=wait_on_rate_limit,
170+
proxy_dict=proxy_dict
166171
)
167172

168173
# API wrappers

webexteamssdk/restsession.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ class RestSession(object):
9999

100100
def __init__(self, access_token, base_url,
101101
single_request_timeout=DEFAULT_SINGLE_REQUEST_TIMEOUT,
102-
wait_on_rate_limit=DEFAULT_WAIT_ON_RATE_LIMIT):
102+
wait_on_rate_limit=DEFAULT_WAIT_ON_RATE_LIMIT,
103+
proxy_dict=None):
103104
"""Initialize a new RestSession object.
104105
105106
Args:
@@ -111,6 +112,8 @@ def __init__(self, access_token, base_url,
111112
HTTP REST API request.
112113
wait_on_rate_limit(bool): Enable or disable automatic rate-limit
113114
handling.
115+
proxy_dict(dict): Dictionary of proxies passed on to the requests
116+
session.
114117
115118
Raises:
116119
TypeError: If the parameter types are incorrect.
@@ -120,6 +123,7 @@ def __init__(self, access_token, base_url,
120123
check_type(base_url, basestring, may_be_none=False)
121124
check_type(single_request_timeout, int)
122125
check_type(wait_on_rate_limit, bool, may_be_none=False)
126+
check_type(proxy_dict, dict, may_be_none=True)
123127

124128
super(RestSession, self).__init__()
125129

@@ -132,6 +136,9 @@ def __init__(self, access_token, base_url,
132136
# Initialize a new `requests` session
133137
self._req_session = requests.session()
134138

139+
if proxy_dict is not None:
140+
self._req_session.proxies.update(proxy_dict)
141+
135142
# Update the headers of the `requests` session
136143
self.update_headers({'Authorization': 'Bearer ' + access_token,
137144
'Content-type': 'application/json;charset=utf-8'})

0 commit comments

Comments
 (0)