1212import xml .dom .minidom as xmldom # create_session
1313from jose import jwt # _create_jwt_auth_header
1414import random # _create_jwt_auth_header
15+ import logging # logging
1516import warnings # Native. Used for notifying deprecations
1617
18+
1719# compat
1820from six .moves .urllib .parse import urlencode
1921from six import text_type , u , b , PY3
@@ -77,6 +79,9 @@ class ArchiveModes(Enum):
7779 """The session will be automatically archived."""
7880
7981
82+ logger = logging .getLogger ("opentok" )
83+
84+
8085class OpenTok (object ):
8186 """Use this SDK to create tokens and interface with the server-side portion
8287 of the Opentok API.
@@ -381,6 +386,13 @@ def create_session(
381386 options [u ("location" )] = location
382387
383388 try :
389+ logger .debug (
390+ "POST to %r with params %r, headers %r, proxies %r" ,
391+ self .endpoints .session_url (),
392+ options ,
393+ self .headers (),
394+ self .proxies ,
395+ )
384396 response = requests .post (
385397 self .endpoints .get_session_url (),
386398 data = options ,
@@ -521,6 +533,14 @@ def start_archive(
521533 "resolution" : resolution ,
522534 }
523535
536+ logger .debug (
537+ "POST to %r with params %r, headers %r, proxies %r" ,
538+ self .endpoints .archive_url (),
539+ json .dumps (payload ),
540+ self .json_headers (),
541+ self .proxies ,
542+ )
543+
524544 response = requests .post (
525545 self .endpoints .get_archive_url (),
526546 data = json .dumps (payload ),
@@ -560,6 +580,13 @@ def stop_archive(self, archive_id):
560580
561581 :rtype: The Archive object corresponding to the archive being stopped.
562582 """
583+ logger .debug (
584+ "POST to %r with headers %r, proxies %r" ,
585+ self .endpoints .archive_url (archive_id ) + "/stop" ,
586+ self .json_headers (),
587+ self .proxies ,
588+ )
589+
563590 response = requests .post (
564591 self .endpoints .get_archive_url (archive_id ) + "/stop" ,
565592 headers = self .get_json_headers (),
@@ -588,6 +615,13 @@ def delete_archive(self, archive_id):
588615
589616 :param String archive_id: The archive ID of the archive to be deleted.
590617 """
618+ logger .debug (
619+ "DELETE to %r with headers %r, proxies %r" ,
620+ self .endpoints .archive_url (archive_id ),
621+ self .json_headers (),
622+ self .proxies ,
623+ )
624+
591625 response = requests .delete (
592626 self .endpoints .get_archive_url (archive_id ),
593627 headers = self .get_json_headers (),
@@ -611,6 +645,13 @@ def get_archive(self, archive_id):
611645
612646 :rtype: The Archive object.
613647 """
648+ logger .debug (
649+ "GET to %r with headers %r, proxies %r" ,
650+ self .endpoints .archive_url (archive_id ),
651+ self .json_headers (),
652+ self .proxies ,
653+ )
654+
614655 response = requests .get (
615656 self .endpoints .get_archive_url (archive_id ),
616657 headers = self .get_json_headers (),
@@ -650,6 +691,13 @@ def get_archives(self, offset=None, count=None, session_id=None):
650691
651692 endpoint = self .endpoints .get_archive_url () + "?" + urlencode (params )
652693
694+ logger .debug (
695+ "GET to %r with headers %r, proxies %r" ,
696+ endpoint ,
697+ self .json_headers (),
698+ self .proxies ,
699+ )
700+
653701 response = requests .get (
654702 endpoint ,
655703 headers = self .get_json_headers (),
@@ -688,6 +736,14 @@ def send_signal(self, session_id, payload, connection_id=None):
688736 the signal is sent to the specified client. Otherwise, the signal is sent to all clients
689737 connected to the session
690738 """
739+ logger .debug (
740+ "POST to %r with params %r, headers %r, proxies %r" ,
741+ self .endpoints .signaling_url (session_id , connection_id ),
742+ json .dumps (payload ),
743+ self .json_headers (),
744+ self .proxies ,
745+ )
746+
691747 response = requests .post (
692748 self .endpoints .get_signaling_url (session_id , connection_id ),
693749 data = json .dumps (payload ),
@@ -735,6 +791,14 @@ def get_stream(self, session_id, stream_id):
735791 -layoutClassList: It's an array of the layout classes for the stream
736792 """
737793 endpoint = self .endpoints .get_stream_url (session_id , stream_id )
794+
795+ logger .debug (
796+ "GET to %r with headers %r, proxies %r" ,
797+ endpoint ,
798+ self .json_headers (),
799+ self .proxies ,
800+ )
801+
738802 response = requests .get (
739803 endpoint ,
740804 headers = self .get_json_headers (),
@@ -765,6 +829,13 @@ def list_streams(self, session_id):
765829 """
766830 endpoint = self .endpoints .get_stream_url (session_id )
767831
832+ logger .debug (
833+ "GET to %r with headers %r, proxies %r" ,
834+ endpoint ,
835+ self .json_headers (),
836+ self .proxies ,
837+ )
838+
768839 response = requests .get (
769840 endpoint ,
770841 headers = self .get_json_headers (),
@@ -793,6 +864,14 @@ def force_disconnect(self, session_id, connection_id):
793864 :param String connection_id: The connection ID of the client that will be disconnected
794865 """
795866 endpoint = self .endpoints .force_disconnect_url (session_id , connection_id )
867+
868+ logger .debug (
869+ "DELETE to %r with headers %r, proxies %r" ,
870+ endpoint ,
871+ self .json_headers (),
872+ self .proxies ,
873+ )
874+
796875 response = requests .delete (
797876 endpoint ,
798877 headers = self .get_json_headers (),
@@ -838,6 +917,15 @@ def set_archive_layout(self, archive_id, layout_type, stylesheet=None):
838917 payload ["stylesheet" ] = stylesheet
839918
840919 endpoint = self .endpoints .set_archive_layout_url (archive_id )
920+
921+ logger .debug (
922+ "PUT to %r with params %r, headers %r, proxies %r" ,
923+ endpoint ,
924+ json .dumps (payload ),
925+ self .json_headers (),
926+ self .proxies ,
927+ )
928+
841929 response = requests .put (
842930 endpoint ,
843931 data = json .dumps (payload ),
@@ -909,6 +997,15 @@ def dial(self, session_id, token, sip_uri, options=[]):
909997 payload ["sip" ]["secure" ] = options ["secure" ]
910998
911999 endpoint = self .endpoints .dial_url ()
1000+
1001+ logger .debug (
1002+ "POST to %r with params %r, headers %r, proxies %r" ,
1003+ endpoint ,
1004+ json .dumps (payload ),
1005+ self .json_headers (),
1006+ self .proxies ,
1007+ )
1008+
9121009 response = requests .post (
9131010 endpoint ,
9141011 data = json .dumps (payload ),
@@ -954,6 +1051,15 @@ class names (Strings) to apply to the stream. For example:
9541051 items_payload = {"items" : payload }
9551052
9561053 endpoint = self .endpoints .set_stream_class_lists_url (session_id )
1054+
1055+ logger .debug (
1056+ "PUT to %r with params %r, headers %r, proxies %r" ,
1057+ endpoint ,
1058+ json .dumps (items_payload ),
1059+ self .json_headers (),
1060+ self .proxies ,
1061+ )
1062+
9571063 response = requests .put (
9581064 endpoint ,
9591065 data = json .dumps (items_payload ),
@@ -1016,7 +1122,16 @@ def start_broadcast(self, session_id, options):
10161122
10171123 payload .update (options )
10181124
1019- endpoint = self .endpoints .get_broadcast_url ()
1125+ endpoint = self .endpoints .broadcast_url ()
1126+
1127+ logger .debug (
1128+ "POST to %r with params %r, headers %r, proxies %r" ,
1129+ endpoint ,
1130+ json .dumps (payload ),
1131+ self .json_headers (),
1132+ self .proxies ,
1133+ )
1134+
10201135 response = requests .post (
10211136 endpoint ,
10221137 data = json .dumps (payload ),
@@ -1050,7 +1165,16 @@ def stop_broadcast(self, broadcast_id):
10501165 :rtype A Broadcast object, which contains information of the broadcast: id, sessionId
10511166 projectId, createdAt, updatedAt and resolution
10521167 """
1053- endpoint = self .endpoints .get_broadcast_url (broadcast_id , stop = True )
1168+
1169+ endpoint = self .endpoints .broadcast_url (broadcast_id , stop = True )
1170+
1171+ logger .debug (
1172+ "POST to %r with headers %r, proxies %r" ,
1173+ endpoint ,
1174+ self .json_headers (),
1175+ self .proxies ,
1176+ )
1177+
10541178 response = requests .post (
10551179 endpoint ,
10561180 headers = self .get_json_headers (),
@@ -1084,7 +1208,16 @@ def get_broadcast(self, broadcast_id):
10841208 :rtype A Broadcast object, which contains information of the broadcast: id, sessionId
10851209 projectId, createdAt, updatedAt, resolution, broadcastUrls and status
10861210 """
1087- endpoint = self .endpoints .get_broadcast_url (broadcast_id )
1211+
1212+ endpoint = self .endpoints .broadcast_url (broadcast_id )
1213+
1214+ logger .debug (
1215+ "GET to %r with headers %r, proxies %r" ,
1216+ endpoint ,
1217+ self .json_headers (),
1218+ self .proxies ,
1219+ )
1220+
10881221 response = requests .get (
10891222 endpoint ,
10901223 headers = self .get_json_headers (),
@@ -1126,7 +1259,16 @@ def set_broadcast_layout(self, broadcast_id, layout_type, stylesheet=None):
11261259 if stylesheet is not None :
11271260 payload ["stylesheet" ] = stylesheet
11281261
1129- endpoint = self .endpoints .get_broadcast_url (broadcast_id , layout = True )
1262+ endpoint = self .endpoints .broadcast_url (broadcast_id , layout = True )
1263+
1264+ logger .debug (
1265+ "PUT to %r with params %r, headers %r, proxies %r" ,
1266+ endpoint ,
1267+ json .dumps (payload ),
1268+ self .json_headers (),
1269+ self .proxies ,
1270+ )
1271+
11301272 response = requests .put (
11311273 endpoint ,
11321274 data = json .dumps (payload ),
0 commit comments