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
1516
1617# compat
1718from six .moves .urllib .parse import urlencode
@@ -76,6 +77,9 @@ class ArchiveModes(Enum):
7677 """The session will be automatically archived."""
7778
7879
80+ logger = logging .getLogger ("opentok" )
81+
82+
7983class OpenTok (object ):
8084 """Use this SDK to create tokens and interface with the server-side portion
8185 of the Opentok API.
@@ -370,6 +374,13 @@ def create_session(
370374 options [u ("location" )] = location
371375
372376 try :
377+ logger .debug (
378+ "POST to %r with params %r, headers %r, proxies %r" ,
379+ self .endpoints .session_url (),
380+ options ,
381+ self .headers (),
382+ self .proxies ,
383+ )
373384 response = requests .post (
374385 self .endpoints .session_url (),
375386 data = options ,
@@ -494,6 +505,14 @@ def start_archive(
494505 "resolution" : resolution ,
495506 }
496507
508+ logger .debug (
509+ "POST to %r with params %r, headers %r, proxies %r" ,
510+ self .endpoints .archive_url (),
511+ json .dumps (payload ),
512+ self .json_headers (),
513+ self .proxies ,
514+ )
515+
497516 response = requests .post (
498517 self .endpoints .archive_url (),
499518 data = json .dumps (payload ),
@@ -533,6 +552,13 @@ def stop_archive(self, archive_id):
533552
534553 :rtype: The Archive object corresponding to the archive being stopped.
535554 """
555+ logger .debug (
556+ "POST to %r with headers %r, proxies %r" ,
557+ self .endpoints .archive_url (archive_id ) + "/stop" ,
558+ self .json_headers (),
559+ self .proxies ,
560+ )
561+
536562 response = requests .post (
537563 self .endpoints .archive_url (archive_id ) + "/stop" ,
538564 headers = self .json_headers (),
@@ -561,6 +587,13 @@ def delete_archive(self, archive_id):
561587
562588 :param String archive_id: The archive ID of the archive to be deleted.
563589 """
590+ logger .debug (
591+ "DELETE to %r with headers %r, proxies %r" ,
592+ self .endpoints .archive_url (archive_id ),
593+ self .json_headers (),
594+ self .proxies ,
595+ )
596+
564597 response = requests .delete (
565598 self .endpoints .archive_url (archive_id ),
566599 headers = self .json_headers (),
@@ -584,6 +617,13 @@ def get_archive(self, archive_id):
584617
585618 :rtype: The Archive object.
586619 """
620+ logger .debug (
621+ "GET to %r with headers %r, proxies %r" ,
622+ self .endpoints .archive_url (archive_id ),
623+ self .json_headers (),
624+ self .proxies ,
625+ )
626+
587627 response = requests .get (
588628 self .endpoints .archive_url (archive_id ),
589629 headers = self .json_headers (),
@@ -623,6 +663,13 @@ def get_archives(self, offset=None, count=None, session_id=None):
623663
624664 endpoint = self .endpoints .archive_url () + "?" + urlencode (params )
625665
666+ logger .debug (
667+ "GET to %r with headers %r, proxies %r" ,
668+ endpoint ,
669+ self .json_headers (),
670+ self .proxies ,
671+ )
672+
626673 response = requests .get (
627674 endpoint ,
628675 headers = self .json_headers (),
@@ -661,6 +708,14 @@ def signal(self, session_id, payload, connection_id=None):
661708 the signal is sent to the specified client. Otherwise, the signal is sent to all clients
662709 connected to the session
663710 """
711+ logger .debug (
712+ "POST to %r with params %r, headers %r, proxies %r" ,
713+ self .endpoints .signaling_url (session_id , connection_id ),
714+ json .dumps (payload ),
715+ self .json_headers (),
716+ self .proxies ,
717+ )
718+
664719 response = requests .post (
665720 self .endpoints .signaling_url (session_id , connection_id ),
666721 data = json .dumps (payload ),
@@ -700,6 +755,14 @@ def get_stream(self, session_id, stream_id):
700755 -layoutClassList: It's an array of the layout classes for the stream
701756 """
702757 endpoint = self .endpoints .get_stream_url (session_id , stream_id )
758+
759+ logger .debug (
760+ "GET to %r with headers %r, proxies %r" ,
761+ endpoint ,
762+ self .json_headers (),
763+ self .proxies ,
764+ )
765+
703766 response = requests .get (
704767 endpoint ,
705768 headers = self .json_headers (),
@@ -730,6 +793,13 @@ def list_streams(self, session_id):
730793 """
731794 endpoint = self .endpoints .get_stream_url (session_id )
732795
796+ logger .debug (
797+ "GET to %r with headers %r, proxies %r" ,
798+ endpoint ,
799+ self .json_headers (),
800+ self .proxies ,
801+ )
802+
733803 response = requests .get (
734804 endpoint ,
735805 headers = self .json_headers (),
@@ -758,6 +828,14 @@ def force_disconnect(self, session_id, connection_id):
758828 :param String connection_id: The connection ID of the client that will be disconnected
759829 """
760830 endpoint = self .endpoints .force_disconnect_url (session_id , connection_id )
831+
832+ logger .debug (
833+ "DELETE to %r with headers %r, proxies %r" ,
834+ endpoint ,
835+ self .json_headers (),
836+ self .proxies ,
837+ )
838+
761839 response = requests .delete (
762840 endpoint ,
763841 headers = self .json_headers (),
@@ -803,6 +881,15 @@ def set_archive_layout(self, archive_id, layout_type, stylesheet=None):
803881 payload ["stylesheet" ] = stylesheet
804882
805883 endpoint = self .endpoints .set_archive_layout_url (archive_id )
884+
885+ logger .debug (
886+ "PUT to %r with params %r, headers %r, proxies %r" ,
887+ endpoint ,
888+ json .dumps (payload ),
889+ self .json_headers (),
890+ self .proxies ,
891+ )
892+
806893 response = requests .put (
807894 endpoint ,
808895 data = json .dumps (payload ),
@@ -874,6 +961,15 @@ def dial(self, session_id, token, sip_uri, options=[]):
874961 payload ["sip" ]["secure" ] = options ["secure" ]
875962
876963 endpoint = self .endpoints .dial_url ()
964+
965+ logger .debug (
966+ "POST to %r with params %r, headers %r, proxies %r" ,
967+ endpoint ,
968+ json .dumps (payload ),
969+ self .json_headers (),
970+ self .proxies ,
971+ )
972+
877973 response = requests .post (
878974 endpoint ,
879975 data = json .dumps (payload ),
@@ -919,6 +1015,15 @@ class names (Strings) to apply to the stream. For example:
9191015 items_payload = {"items" : payload }
9201016
9211017 endpoint = self .endpoints .set_stream_class_lists_url (session_id )
1018+
1019+ logger .debug (
1020+ "PUT to %r with params %r, headers %r, proxies %r" ,
1021+ endpoint ,
1022+ json .dumps (items_payload ),
1023+ self .json_headers (),
1024+ self .proxies ,
1025+ )
1026+
9221027 response = requests .put (
9231028 endpoint ,
9241029 data = json .dumps (items_payload ),
@@ -982,6 +1087,15 @@ def start_broadcast(self, session_id, options):
9821087 payload .update (options )
9831088
9841089 endpoint = self .endpoints .broadcast_url ()
1090+
1091+ logger .debug (
1092+ "POST to %r with params %r, headers %r, proxies %r" ,
1093+ endpoint ,
1094+ json .dumps (payload ),
1095+ self .json_headers (),
1096+ self .proxies ,
1097+ )
1098+
9851099 response = requests .post (
9861100 endpoint ,
9871101 data = json .dumps (payload ),
@@ -1016,6 +1130,14 @@ def stop_broadcast(self, broadcast_id):
10161130 projectId, createdAt, updatedAt and resolution
10171131 """
10181132 endpoint = self .endpoints .broadcast_url (broadcast_id , stop = True )
1133+
1134+ logger .debug (
1135+ "POST to %r with headers %r, proxies %r" ,
1136+ endpoint ,
1137+ self .json_headers (),
1138+ self .proxies ,
1139+ )
1140+
10191141 response = requests .post (
10201142 endpoint ,
10211143 headers = self .json_headers (),
@@ -1050,6 +1172,14 @@ def get_broadcast(self, broadcast_id):
10501172 projectId, createdAt, updatedAt, resolution, broadcastUrls and status
10511173 """
10521174 endpoint = self .endpoints .broadcast_url (broadcast_id )
1175+
1176+ logger .debug (
1177+ "GET to %r with headers %r, proxies %r" ,
1178+ endpoint ,
1179+ self .json_headers (),
1180+ self .proxies ,
1181+ )
1182+
10531183 response = requests .get (
10541184 endpoint ,
10551185 headers = self .json_headers (),
@@ -1092,6 +1222,15 @@ def set_broadcast_layout(self, broadcast_id, layout_type, stylesheet=None):
10921222 payload ["stylesheet" ] = stylesheet
10931223
10941224 endpoint = self .endpoints .broadcast_url (broadcast_id , layout = True )
1225+
1226+ logger .debug (
1227+ "PUT to %r with params %r, headers %r, proxies %r" ,
1228+ endpoint ,
1229+ json .dumps (payload ),
1230+ self .json_headers (),
1231+ self .proxies ,
1232+ )
1233+
10951234 response = requests .put (
10961235 endpoint ,
10971236 data = json .dumps (payload ),
0 commit comments