12
12
import xml .dom .minidom as xmldom # create_session
13
13
from jose import jwt # _create_jwt_auth_header
14
14
import random # _create_jwt_auth_header
15
+ import warnings # Native. Used for notifying deprecations
15
16
16
17
# compat
17
18
from six .moves .urllib .parse import urlencode
@@ -381,9 +382,9 @@ def create_session(
381
382
382
383
try :
383
384
response = requests .post (
384
- self .endpoints .session_url (),
385
+ self .endpoints .get_session_url (),
385
386
data = options ,
386
- headers = self .headers (),
387
+ headers = self .get_headers (),
387
388
proxies = self .proxies ,
388
389
timeout = self .timeout ,
389
390
)
@@ -422,7 +423,7 @@ def create_session(
422
423
except Exception as e :
423
424
raise OpenTokException ("Failed to generate session: %s" % str (e ))
424
425
425
- def headers (self ):
426
+ def get_headers (self ):
426
427
"""For internal use."""
427
428
return {
428
429
"User-Agent" : "OpenTok-Python-SDK/"
@@ -432,12 +433,28 @@ def headers(self):
432
433
"X-OPENTOK-AUTH" : self ._create_jwt_auth_header (),
433
434
}
434
435
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 ):
436
445
"""For internal use."""
437
- result = self .headers ()
446
+ result = self .get_headers ()
438
447
result ["Content-Type" ] = "application/json"
439
448
return result
440
449
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
+
441
458
def start_archive (
442
459
self ,
443
460
session_id ,
@@ -505,9 +522,9 @@ def start_archive(
505
522
}
506
523
507
524
response = requests .post (
508
- self .endpoints .archive_url (),
525
+ self .endpoints .get_archive_url (),
509
526
data = json .dumps (payload ),
510
- headers = self .json_headers (),
527
+ headers = self .get_json_headers (),
511
528
proxies = self .proxies ,
512
529
timeout = self .timeout ,
513
530
)
@@ -544,8 +561,8 @@ def stop_archive(self, archive_id):
544
561
:rtype: The Archive object corresponding to the archive being stopped.
545
562
"""
546
563
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 (),
549
566
proxies = self .proxies ,
550
567
timeout = self .timeout ,
551
568
)
@@ -572,8 +589,8 @@ def delete_archive(self, archive_id):
572
589
:param String archive_id: The archive ID of the archive to be deleted.
573
590
"""
574
591
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 (),
577
594
proxies = self .proxies ,
578
595
timeout = self .timeout ,
579
596
)
@@ -595,8 +612,8 @@ def get_archive(self, archive_id):
595
612
:rtype: The Archive object.
596
613
"""
597
614
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 (),
600
617
proxies = self .proxies ,
601
618
timeout = self .timeout ,
602
619
)
@@ -631,11 +648,11 @@ def get_archives(self, offset=None, count=None, session_id=None):
631
648
if session_id is not None :
632
649
params ["sessionId" ] = session_id
633
650
634
- endpoint = self .endpoints .archive_url () + "?" + urlencode (params )
651
+ endpoint = self .endpoints .get_archive_url () + "?" + urlencode (params )
635
652
636
653
response = requests .get (
637
654
endpoint ,
638
- headers = self .json_headers (),
655
+ headers = self .get_json_headers (),
639
656
proxies = self .proxies ,
640
657
timeout = self .timeout ,
641
658
)
@@ -656,7 +673,7 @@ def list_archives(self, offset=None, count=None, session_id=None):
656
673
"""
657
674
return self .get_archives (offset , count , session_id )
658
675
659
- def signal (self , session_id , payload , connection_id = None ):
676
+ def send_signal (self , session_id , payload , connection_id = None ):
660
677
"""
661
678
Send signals to all participants in an active OpenTok session or to a specific client
662
679
connected to that session.
@@ -672,9 +689,9 @@ def signal(self, session_id, payload, connection_id=None):
672
689
connected to the session
673
690
"""
674
691
response = requests .post (
675
- self .endpoints .signaling_url (session_id , connection_id ),
692
+ self .endpoints .get_signaling_url (session_id , connection_id ),
676
693
data = json .dumps (payload ),
677
- headers = self .json_headers (),
694
+ headers = self .get_json_headers (),
678
695
proxies = self .proxies ,
679
696
timeout = self .timeout ,
680
697
)
@@ -700,6 +717,14 @@ def signal(self, session_id, payload, connection_id=None):
700
717
else :
701
718
raise RequestError ("An unexpected error occurred" , response .status_code )
702
719
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
+
703
728
def get_stream (self , session_id , stream_id ):
704
729
"""
705
730
Returns an Stream object that contains information of an OpenTok stream:
@@ -712,7 +737,7 @@ def get_stream(self, session_id, stream_id):
712
737
endpoint = self .endpoints .get_stream_url (session_id , stream_id )
713
738
response = requests .get (
714
739
endpoint ,
715
- headers = self .json_headers (),
740
+ headers = self .get_json_headers (),
716
741
proxies = self .proxies ,
717
742
timeout = self .timeout ,
718
743
)
@@ -742,7 +767,7 @@ def list_streams(self, session_id):
742
767
743
768
response = requests .get (
744
769
endpoint ,
745
- headers = self .json_headers (),
770
+ headers = self .get_json_headers (),
746
771
proxies = self .proxies ,
747
772
timeout = self .timeout ,
748
773
)
@@ -770,7 +795,7 @@ def force_disconnect(self, session_id, connection_id):
770
795
endpoint = self .endpoints .force_disconnect_url (session_id , connection_id )
771
796
response = requests .delete (
772
797
endpoint ,
773
- headers = self .json_headers (),
798
+ headers = self .get_json_headers (),
774
799
proxies = self .proxies ,
775
800
timeout = self .timeout ,
776
801
)
@@ -816,7 +841,7 @@ def set_archive_layout(self, archive_id, layout_type, stylesheet=None):
816
841
response = requests .put (
817
842
endpoint ,
818
843
data = json .dumps (payload ),
819
- headers = self .json_headers (),
844
+ headers = self .get_json_headers (),
820
845
proxies = self .proxies ,
821
846
timeout = self .timeout ,
822
847
)
@@ -887,7 +912,7 @@ def dial(self, session_id, token, sip_uri, options=[]):
887
912
response = requests .post (
888
913
endpoint ,
889
914
data = json .dumps (payload ),
890
- headers = self .json_headers (),
915
+ headers = self .get_json_headers (),
891
916
proxies = self .proxies ,
892
917
timeout = self .timeout ,
893
918
)
@@ -932,7 +957,7 @@ class names (Strings) to apply to the stream. For example:
932
957
response = requests .put (
933
958
endpoint ,
934
959
data = json .dumps (items_payload ),
935
- headers = self .json_headers (),
960
+ headers = self .get_json_headers (),
936
961
proxies = self .proxies ,
937
962
timeout = self .timeout ,
938
963
)
@@ -991,11 +1016,11 @@ def start_broadcast(self, session_id, options):
991
1016
992
1017
payload .update (options )
993
1018
994
- endpoint = self .endpoints .broadcast_url ()
1019
+ endpoint = self .endpoints .get_broadcast_url ()
995
1020
response = requests .post (
996
1021
endpoint ,
997
1022
data = json .dumps (payload ),
998
- headers = self .json_headers (),
1023
+ headers = self .get_json_headers (),
999
1024
proxies = self .proxies ,
1000
1025
timeout = self .timeout ,
1001
1026
)
@@ -1025,10 +1050,10 @@ def stop_broadcast(self, broadcast_id):
1025
1050
:rtype A Broadcast object, which contains information of the broadcast: id, sessionId
1026
1051
projectId, createdAt, updatedAt and resolution
1027
1052
"""
1028
- endpoint = self .endpoints .broadcast_url (broadcast_id , stop = True )
1053
+ endpoint = self .endpoints .get_broadcast_url (broadcast_id , stop = True )
1029
1054
response = requests .post (
1030
1055
endpoint ,
1031
- headers = self .json_headers (),
1056
+ headers = self .get_json_headers (),
1032
1057
proxies = self .proxies ,
1033
1058
timeout = self .timeout ,
1034
1059
)
@@ -1059,10 +1084,10 @@ def get_broadcast(self, broadcast_id):
1059
1084
:rtype A Broadcast object, which contains information of the broadcast: id, sessionId
1060
1085
projectId, createdAt, updatedAt, resolution, broadcastUrls and status
1061
1086
"""
1062
- endpoint = self .endpoints .broadcast_url (broadcast_id )
1087
+ endpoint = self .endpoints .get_broadcast_url (broadcast_id )
1063
1088
response = requests .get (
1064
1089
endpoint ,
1065
- headers = self .json_headers (),
1090
+ headers = self .get_json_headers (),
1066
1091
proxies = self .proxies ,
1067
1092
timeout = self .timeout ,
1068
1093
)
@@ -1101,11 +1126,11 @@ def set_broadcast_layout(self, broadcast_id, layout_type, stylesheet=None):
1101
1126
if stylesheet is not None :
1102
1127
payload ["stylesheet" ] = stylesheet
1103
1128
1104
- endpoint = self .endpoints .broadcast_url (broadcast_id , layout = True )
1129
+ endpoint = self .endpoints .get_broadcast_url (broadcast_id , layout = True )
1105
1130
response = requests .put (
1106
1131
endpoint ,
1107
1132
data = json .dumps (payload ),
1108
- headers = self .json_headers (),
1133
+ headers = self .get_json_headers (),
1109
1134
proxies = self .proxies ,
1110
1135
timeout = self .timeout ,
1111
1136
)
0 commit comments