1212import xml .dom .minidom as xmldom # create_session
1313from jose import jwt # _create_jwt_auth_header
1414import random # _create_jwt_auth_header
15+ import warnings # Native. Used for notifying deprecations
1516
1617# compat
1718from six .moves .urllib .parse import urlencode
@@ -381,9 +382,9 @@ def create_session(
381382
382383 try :
383384 response = requests .post (
384- self .endpoints .session_url (),
385+ self .endpoints .get_session_url (),
385386 data = options ,
386- headers = self .headers (),
387+ headers = self .get_headers (),
387388 proxies = self .proxies ,
388389 timeout = self .timeout ,
389390 )
@@ -422,7 +423,7 @@ def create_session(
422423 except Exception as e :
423424 raise OpenTokException ("Failed to generate session: %s" % str (e ))
424425
425- def headers (self ):
426+ def get_headers (self ):
426427 """For internal use."""
427428 return {
428429 "User-Agent" : "OpenTok-Python-SDK/"
@@ -432,12 +433,28 @@ def headers(self):
432433 "X-OPENTOK-AUTH" : self ._create_jwt_auth_header (),
433434 }
434435
435- def json_headers (self ):
436+ def headers (self ):
437+ warnings .warn (
438+ "opentok.headers is deprecated (use opentok.get_headers instead)." ,
439+ DeprecationWarning ,
440+ stacklevel = 2 ,
441+ )
442+ return self .get_headers ()
443+
444+ def get_json_headers (self ):
436445 """For internal use."""
437- result = self .headers ()
446+ result = self .get_headers ()
438447 result ["Content-Type" ] = "application/json"
439448 return result
440449
450+ def json_headers (self ):
451+ warnings .warn (
452+ "opentok.json_headers is deprecated (use opentok.get_json_headers instead)." ,
453+ DeprecationWarning ,
454+ stacklevel = 2 ,
455+ )
456+ return self .get_json_headers ()
457+
441458 def start_archive (
442459 self ,
443460 session_id ,
@@ -505,9 +522,9 @@ def start_archive(
505522 }
506523
507524 response = requests .post (
508- self .endpoints .archive_url (),
525+ self .endpoints .get_archive_url (),
509526 data = json .dumps (payload ),
510- headers = self .json_headers (),
527+ headers = self .get_json_headers (),
511528 proxies = self .proxies ,
512529 timeout = self .timeout ,
513530 )
@@ -544,8 +561,8 @@ def stop_archive(self, archive_id):
544561 :rtype: The Archive object corresponding to the archive being stopped.
545562 """
546563 response = requests .post (
547- self .endpoints .archive_url (archive_id ) + "/stop" ,
548- headers = self .json_headers (),
564+ self .endpoints .get_archive_url (archive_id ) + "/stop" ,
565+ headers = self .get_json_headers (),
549566 proxies = self .proxies ,
550567 timeout = self .timeout ,
551568 )
@@ -572,8 +589,8 @@ def delete_archive(self, archive_id):
572589 :param String archive_id: The archive ID of the archive to be deleted.
573590 """
574591 response = requests .delete (
575- self .endpoints .archive_url (archive_id ),
576- headers = self .json_headers (),
592+ self .endpoints .get_archive_url (archive_id ),
593+ headers = self .get_json_headers (),
577594 proxies = self .proxies ,
578595 timeout = self .timeout ,
579596 )
@@ -595,8 +612,8 @@ def get_archive(self, archive_id):
595612 :rtype: The Archive object.
596613 """
597614 response = requests .get (
598- self .endpoints .archive_url (archive_id ),
599- headers = self .json_headers (),
615+ self .endpoints .get_archive_url (archive_id ),
616+ headers = self .get_json_headers (),
600617 proxies = self .proxies ,
601618 timeout = self .timeout ,
602619 )
@@ -631,11 +648,11 @@ def get_archives(self, offset=None, count=None, session_id=None):
631648 if session_id is not None :
632649 params ["sessionId" ] = session_id
633650
634- endpoint = self .endpoints .archive_url () + "?" + urlencode (params )
651+ endpoint = self .endpoints .get_archive_url () + "?" + urlencode (params )
635652
636653 response = requests .get (
637654 endpoint ,
638- headers = self .json_headers (),
655+ headers = self .get_json_headers (),
639656 proxies = self .proxies ,
640657 timeout = self .timeout ,
641658 )
@@ -656,7 +673,7 @@ def list_archives(self, offset=None, count=None, session_id=None):
656673 """
657674 return self .get_archives (offset , count , session_id )
658675
659- def signal (self , session_id , payload , connection_id = None ):
676+ def send_signal (self , session_id , payload , connection_id = None ):
660677 """
661678 Send signals to all participants in an active OpenTok session or to a specific client
662679 connected to that session.
@@ -672,9 +689,9 @@ def signal(self, session_id, payload, connection_id=None):
672689 connected to the session
673690 """
674691 response = requests .post (
675- self .endpoints .signaling_url (session_id , connection_id ),
692+ self .endpoints .get_signaling_url (session_id , connection_id ),
676693 data = json .dumps (payload ),
677- headers = self .json_headers (),
694+ headers = self .get_json_headers (),
678695 proxies = self .proxies ,
679696 timeout = self .timeout ,
680697 )
@@ -700,6 +717,14 @@ def signal(self, session_id, payload, connection_id=None):
700717 else :
701718 raise RequestError ("An unexpected error occurred" , response .status_code )
702719
720+ def signal (self , session_id , payload , connection_id = None ):
721+ warnings .warn (
722+ "opentok.signal is deprecated (use opentok.send_signal instead)." ,
723+ DeprecationWarning ,
724+ stacklevel = 2 ,
725+ )
726+ self .send_signal (session_id , payload , connection_id )
727+
703728 def get_stream (self , session_id , stream_id ):
704729 """
705730 Returns an Stream object that contains information of an OpenTok stream:
@@ -712,7 +737,7 @@ def get_stream(self, session_id, stream_id):
712737 endpoint = self .endpoints .get_stream_url (session_id , stream_id )
713738 response = requests .get (
714739 endpoint ,
715- headers = self .json_headers (),
740+ headers = self .get_json_headers (),
716741 proxies = self .proxies ,
717742 timeout = self .timeout ,
718743 )
@@ -742,7 +767,7 @@ def list_streams(self, session_id):
742767
743768 response = requests .get (
744769 endpoint ,
745- headers = self .json_headers (),
770+ headers = self .get_json_headers (),
746771 proxies = self .proxies ,
747772 timeout = self .timeout ,
748773 )
@@ -770,7 +795,7 @@ def force_disconnect(self, session_id, connection_id):
770795 endpoint = self .endpoints .force_disconnect_url (session_id , connection_id )
771796 response = requests .delete (
772797 endpoint ,
773- headers = self .json_headers (),
798+ headers = self .get_json_headers (),
774799 proxies = self .proxies ,
775800 timeout = self .timeout ,
776801 )
@@ -816,7 +841,7 @@ def set_archive_layout(self, archive_id, layout_type, stylesheet=None):
816841 response = requests .put (
817842 endpoint ,
818843 data = json .dumps (payload ),
819- headers = self .json_headers (),
844+ headers = self .get_json_headers (),
820845 proxies = self .proxies ,
821846 timeout = self .timeout ,
822847 )
@@ -887,7 +912,7 @@ def dial(self, session_id, token, sip_uri, options=[]):
887912 response = requests .post (
888913 endpoint ,
889914 data = json .dumps (payload ),
890- headers = self .json_headers (),
915+ headers = self .get_json_headers (),
891916 proxies = self .proxies ,
892917 timeout = self .timeout ,
893918 )
@@ -932,7 +957,7 @@ class names (Strings) to apply to the stream. For example:
932957 response = requests .put (
933958 endpoint ,
934959 data = json .dumps (items_payload ),
935- headers = self .json_headers (),
960+ headers = self .get_json_headers (),
936961 proxies = self .proxies ,
937962 timeout = self .timeout ,
938963 )
@@ -991,11 +1016,11 @@ def start_broadcast(self, session_id, options):
9911016
9921017 payload .update (options )
9931018
994- endpoint = self .endpoints .broadcast_url ()
1019+ endpoint = self .endpoints .get_broadcast_url ()
9951020 response = requests .post (
9961021 endpoint ,
9971022 data = json .dumps (payload ),
998- headers = self .json_headers (),
1023+ headers = self .get_json_headers (),
9991024 proxies = self .proxies ,
10001025 timeout = self .timeout ,
10011026 )
@@ -1025,10 +1050,10 @@ def stop_broadcast(self, broadcast_id):
10251050 :rtype A Broadcast object, which contains information of the broadcast: id, sessionId
10261051 projectId, createdAt, updatedAt and resolution
10271052 """
1028- endpoint = self .endpoints .broadcast_url (broadcast_id , stop = True )
1053+ endpoint = self .endpoints .get_broadcast_url (broadcast_id , stop = True )
10291054 response = requests .post (
10301055 endpoint ,
1031- headers = self .json_headers (),
1056+ headers = self .get_json_headers (),
10321057 proxies = self .proxies ,
10331058 timeout = self .timeout ,
10341059 )
@@ -1059,10 +1084,10 @@ def get_broadcast(self, broadcast_id):
10591084 :rtype A Broadcast object, which contains information of the broadcast: id, sessionId
10601085 projectId, createdAt, updatedAt, resolution, broadcastUrls and status
10611086 """
1062- endpoint = self .endpoints .broadcast_url (broadcast_id )
1087+ endpoint = self .endpoints .get_broadcast_url (broadcast_id )
10631088 response = requests .get (
10641089 endpoint ,
1065- headers = self .json_headers (),
1090+ headers = self .get_json_headers (),
10661091 proxies = self .proxies ,
10671092 timeout = self .timeout ,
10681093 )
@@ -1101,11 +1126,11 @@ def set_broadcast_layout(self, broadcast_id, layout_type, stylesheet=None):
11011126 if stylesheet is not None :
11021127 payload ["stylesheet" ] = stylesheet
11031128
1104- endpoint = self .endpoints .broadcast_url (broadcast_id , layout = True )
1129+ endpoint = self .endpoints .get_broadcast_url (broadcast_id , layout = True )
11051130 response = requests .put (
11061131 endpoint ,
11071132 data = json .dumps (payload ),
1108- headers = self .json_headers (),
1133+ headers = self .get_json_headers (),
11091134 proxies = self .proxies ,
11101135 timeout = self .timeout ,
11111136 )
0 commit comments