Skip to content

Commit 51545d3

Browse files
author
PureCloud Jenkins
committed
108.0.0
1 parent fc0556e commit 51545d3

429 files changed

Lines changed: 12904 additions & 8586 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,36 +54,7 @@ print(usersApi.get_users_me())
5454
5555
```
5656

57-
### Authorization Code Grant
5857

59-
* The app is authenticating as a human, the [Authorization Code Grant](https://developer.mypurecloud.com/api/rest/authorization/use-authorization-code.html)
60-
* The app is served via a web server
61-
* There is server-side code that will be making API requests
62-
63-
```{"language":"python"}
64-
apiclient, auth_token_info = apiclient.get_code_authorization_token("565c3091-4107-4675-b606-b1fead2d15a4",
65-
"9pal483eSr_vCZf0qQomFK298I8htjBZo49FI_lLZQ8",
66-
"fjaXJaIG7Y-gFhgwvxvNZLj-dcqhWS_pm_n-_1MziN8",
67-
"https://redirect-uri.com/oauth/callback")
68-
usersApi = PureCloudPlatformClientV2.UsersApi(apiclient)
69-
```
70-
71-
By default the SDK will use the refresh token to request a new access token transparently when it expires. If multiple threads are running 1 thread will request a new token, other threads will wait a maximum of 10 seconds for the token refresh to complete, this time can be overriden with the _refresh_token_wait_time_ field of the _Configuration_ object.
72-
If you wish to implement the refresh logic, set _should_refresh_access_token_ to false and store the refresh token from the auth response. The expires_in value can be used to proactively request a new one before it expires:
73-
74-
```{"language":"python"}
75-
refresh_token = auth_token_info["refresh_token"]
76-
expires_in = auth_token_info["expires_in"]
77-
PureCloudPlatformClientV2.configuration.should_refresh_access_token = False
78-
```
79-
80-
When the access token expires refresh it using the refresh_code_authorization_token method using the same clientId and clientSecret as used to request it.
81-
82-
```{"language":"python"}
83-
apiclient, auth_token_info = apiclient.refresh_code_authorization_token("565c3091-4107-4675-b606-b1fead2d15a4",
84-
"9pal483eSr_vCZf0qQomFK298I8htjBZo49FI_lLZQ8",
85-
refresh_token)
86-
```
8758

8859
### Setting the Environment
8960

build/PureCloudPlatformClientV2/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@
167167
from .models.biography import Biography
168168
from .models.bu_abandon_rate import BuAbandonRate
169169
from .models.bu_agent_schedule_activity import BuAgentScheduleActivity
170+
from .models.bu_agent_schedule_history_change import BuAgentScheduleHistoryChange
171+
from .models.bu_agent_schedule_history_change_metadata import BuAgentScheduleHistoryChangeMetadata
172+
from .models.bu_agent_schedule_history_deleted_change import BuAgentScheduleHistoryDeletedChange
173+
from .models.bu_agent_schedule_history_dropped_change import BuAgentScheduleHistoryDroppedChange
174+
from .models.bu_agent_schedule_history_response import BuAgentScheduleHistoryResponse
170175
from .models.bu_agent_schedule_published_schedule_reference import BuAgentSchedulePublishedScheduleReference
171176
from .models.bu_agent_schedule_query_response import BuAgentScheduleQueryResponse
172177
from .models.bu_agent_schedule_reschedule_response import BuAgentScheduleRescheduleResponse
@@ -385,8 +390,10 @@
385390
from .models.content_quick_reply import ContentQuickReply
386391
from .models.content_reaction import ContentReaction
387392
from .models.content_sort_item import ContentSortItem
393+
from .models.context import Context
388394
from .models.context_entity import ContextEntity
389395
from .models.context_intent import ContextIntent
396+
from .models.context_pattern import ContextPattern
390397
from .models.conversation import Conversation
391398
from .models.conversation_aggregate_data_container import ConversationAggregateDataContainer
392399
from .models.conversation_aggregate_query_clause import ConversationAggregateQueryClause
@@ -614,6 +621,7 @@
614621
from .models.credential_specification import CredentialSpecification
615622
from .models.credential_type import CredentialType
616623
from .models.credential_type_listing import CredentialTypeListing
624+
from .models.criteria import Criteria
617625
from .models.cross_platform_call_media_policy import CrossPlatformCallMediaPolicy
618626
from .models.cross_platform_chat_media_policy import CrossPlatformChatMediaPolicy
619627
from .models.cross_platform_email_media_policy import CrossPlatformEmailMediaPolicy
@@ -848,6 +856,7 @@
848856
from .models.endpoint import Endpoint
849857
from .models.entity import Entity
850858
from .models.entity_listing import EntityListing
859+
from .models.entity_type_criteria import EntityTypeCriteria
851860
from .models.entry import Entry
852861
from .models.error_body import ErrorBody
853862
from .models.error_details import ErrorDetails
@@ -1042,6 +1051,7 @@
10421051
from .models.ip_address_range_listing import IpAddressRangeListing
10431052
from .models.item_validation_limits import ItemValidationLimits
10441053
from .models.items import Items
1054+
from .models.journey import Journey
10451055
from .models.journey_action import JourneyAction
10461056
from .models.journey_action_map import JourneyActionMap
10471057
from .models.journey_aggregate_data_container import JourneyAggregateDataContainer
@@ -1054,6 +1064,8 @@
10541064
from .models.journey_context import JourneyContext
10551065
from .models.journey_customer import JourneyCustomer
10561066
from .models.journey_customer_session import JourneyCustomerSession
1067+
from .models.journey_pattern import JourneyPattern
1068+
from .models.journey_segment import JourneySegment
10571069
from .models.json_node import JsonNode
10581070
from .models.json_node_search_response import JsonNodeSearchResponse
10591071
from .models.json_schema_document import JsonSchemaDocument
@@ -1282,6 +1294,7 @@
12821294
from .models.patch_bu_rescheduling_options_management_unit_request import PatchBuReschedulingOptionsManagementUnitRequest
12831295
from .models.patch_bu_rescheduling_options_request import PatchBuReschedulingOptionsRequest
12841296
from .models.patch_bu_schedule_run_request import PatchBuScheduleRunRequest
1297+
from .models.patch_segment import PatchSegment
12851298
from .models.patch_shift_trade_request import PatchShiftTradeRequest
12861299
from .models.patch_user import PatchUser
12871300
from .models.permission_collection_entity_listing import PermissionCollectionEntityListing
@@ -1717,6 +1730,7 @@
17171730
from .models.segment_detail_query_clause import SegmentDetailQueryClause
17181731
from .models.segment_detail_query_filter import SegmentDetailQueryFilter
17191732
from .models.segment_detail_query_predicate import SegmentDetailQueryPredicate
1733+
from .models.segment_listing import SegmentListing
17201734
from .models.selected_columns import SelectedColumns
17211735
from .models.send_agentless_outbound_message_request import SendAgentlessOutboundMessageRequest
17221736
from .models.send_agentless_outbound_message_response import SendAgentlessOutboundMessageResponse

build/PureCloudPlatformClientV2/api_client.py

Lines changed: 7 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import threading
3535
import base64
3636
import json
37-
import time
3837

3938

4039
from datetime import datetime
@@ -87,17 +86,8 @@ def __init__(self, host=None, header_name=None, header_value=None, cookie=None):
8786
# Set default User-Agent.
8887
self.user_agent = 'PureCloud SDK/python'
8988

90-
# store clientId and clientSecret to request new access token for OAuth (Code Authorization)
91-
self.client_id = ""
92-
self.client_secret = ""
9389
# access token for OAuth
9490
self.access_token = ""
95-
# refresh token for OAuth (Code Authorization)
96-
self.refresh_token = ""
97-
# lock object used to ensure 1 thread tries to request a new access token
98-
self.refresh_token_lock = threading.Lock()
99-
# flag indicating a token refresh is being carried out
100-
self.refresh_in_progress = False
10191

10292

10393

@@ -166,83 +156,6 @@ def get_saml2bearer_token(self,client_id,client_secret,org_name,assertion):
166156
self.access_token = data[0]["access_token"]
167157
return self;
168158

169-
def get_code_authorization_token(self,client_id,client_secret,auth_code,redirect_uri):
170-
""":param client_id: Client Id to authenticate with
171-
:param client_secret: Client Secret to authenticate with
172-
:param auth_code: Authorization code
173-
:param redirect_uri: Authorized redirect URI for your Code Authorization client
174-
:return:
175-
"""
176-
177-
self.client_id = client_id
178-
self.client_secret = client_secret
179-
180-
query_params = {}
181-
body = None
182-
url = re.sub(r'\/\/(api)\.', '//login.', self.host) + '/oauth/token'
183-
184-
post_params = {'grant_type': 'authorization_code',
185-
'code': auth_code,
186-
'redirect_uri': redirect_uri
187-
}
188-
189-
auth_string = 'Basic ' + base64.b64encode(bytes((client_id + ':' + client_secret).encode('ascii'))).decode(
190-
'ascii')
191-
192-
header_params = {
193-
"Authorization": auth_string,
194-
'Content-Type': 'application/x-www-form-urlencoded'
195-
}
196-
header_params = self.sanitize_for_serialization(header_params)
197-
post_params = self.sanitize_for_serialization(post_params)
198-
199-
response = self.request("POST", url,
200-
query_params=query_params,
201-
headers=header_params,
202-
post_params=post_params, body=body)
203-
data = json.loads('[' + response.data + ']')
204-
205-
self.access_token = data[0]["access_token"]
206-
self.refresh_token = data[0]["refresh_token"]
207-
208-
return self, data[0]
209-
210-
def refresh_code_authorization_token(self,client_id,client_secret,refresh_token):
211-
""":param client_id: Client Id to authenticate with
212-
:param client_secret: Client Secret to authenticate with
213-
:param refresh_token: Refresh token used to request a new access token
214-
:return:
215-
"""
216-
217-
query_params = {}
218-
body = None
219-
url = re.sub(r'\/\/(api)\.', '//login.', self.host) + '/oauth/token'
220-
221-
post_params = {'grant_type': 'refresh_token',
222-
'refresh_token': refresh_token
223-
}
224-
225-
auth_string = 'Basic ' + base64.b64encode(bytes((client_id + ':' + client_secret).encode('ascii'))).decode(
226-
'ascii')
227-
228-
header_params = {
229-
"Authorization": auth_string,
230-
'Content-Type': 'application/x-www-form-urlencoded'
231-
}
232-
header_params = self.sanitize_for_serialization(header_params)
233-
post_params = self.sanitize_for_serialization(post_params)
234-
235-
response = self.request("POST", url,
236-
query_params=query_params,
237-
headers=header_params,
238-
post_params=post_params, body=body)
239-
data = json.loads('[' + response.data + ']')
240-
241-
self.access_token = data[0]["access_token"]
242-
self.refresh_token = data[0]["refresh_token"]
243-
244-
return self, data[0]
245-
246159
@property
247160
def user_agent(self):
248161
"""
@@ -260,42 +173,19 @@ def user_agent(self, value):
260173
def set_default_header(self, header_name, header_value):
261174
self.default_headers[header_name] = header_value
262175

263-
def handle_expired_access_token(self):
264-
if self.refresh_token_lock.acquire(False):
265-
try:
266-
self.refresh_in_progress = True
267-
self.refresh_code_authorization_token(self.client_id, self.client_secret, self.refresh_token)
268-
finally:
269-
self.refresh_in_progress = False
270-
self.refresh_token_lock.release()
271-
else:
272-
start_time = time.time()
273-
sleep_duration = 0.200
274-
# Wait maximum of refresh_token_wait_time seconds for other thread to complete refresh
275-
# It would be ideal to use refresh_token_lock.acquire with a timeout value here but that was added in python 3.2 and we have to support older versions
276-
while time.time() - start_time < Configuration().refresh_token_wait_time:
277-
time.sleep(sleep_duration)
278-
if not self.refresh_in_progress:
279-
return
280-
# Abort with error if we have waited refresh_token_wait_time seconds and refresh still isn't complete
281-
raise ApiException(
282-
status=500,
283-
reason="Token refresh took longer than `{0}` seconds"
284-
.format(str(Configuration().refresh_token_wait_time))
285-
)
286-
287176
def __call_api(self, resource_path, method,
288177
path_params=None, query_params=None, header_params=None,
289178
body=None, post_params=None, files=None,
290179
response_type=None, auth_settings=None, callback=None):
180+
291181
# headers parameters
292182
header_params = header_params or {}
293183
header_params.update(self.default_headers)
294184
if self.cookie:
295185
header_params['Cookie'] = self.cookie
296186
if header_params:
297187
header_params = self.sanitize_for_serialization(header_params)
298-
header_params['purecloud-sdk'] = '107.0.0'
188+
header_params['purecloud-sdk'] = '108.0.0'
299189

300190
# path parameters
301191
if path_params:
@@ -326,20 +216,11 @@ def __call_api(self, resource_path, method,
326216
# request url
327217
url = self.host + resource_path
328218

329-
response_data = None
330-
331-
try:
332-
# perform request and return response
333-
response_data = self.request(method, url, query_params=query_params,
334-
headers=header_params, post_params=post_params, body=body)
335-
except ApiException as e:
336-
if Configuration().should_refresh_access_token and e.status == 401 and self.refresh_token != "":
337-
self.handle_expired_access_token()
338-
return self.__call_api(resource_path, method, path_params,
339-
query_params, header_params, body, post_params,
340-
files, response_type, auth_settings, callback)
341-
else:
342-
raise
219+
# perform request and return response
220+
response_data = self.request(method, url,
221+
query_params=query_params,
222+
headers=header_params,
223+
post_params=post_params, body=body)
343224

344225
self.last_response = response_data
345226

0 commit comments

Comments
 (0)