Skip to content

Commit 8a84b04

Browse files
authored
Merge pull request #60 from GetStream/stats-external-api
[VID-270] Stable video stats API: GetCallReport
2 parents f3fe1a2 + e952617 commit 8a84b04

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

getstream/models/__init__.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,29 @@ class CallRejectedEvent(DataClassJsonMixin):
13791379
)
13801380

13811381

1382+
@dataclass
1383+
class CallReportResponse(DataClassJsonMixin):
1384+
score: float = dc_field(metadata=dc_config(field_name="score"))
1385+
ended_at: Optional[datetime] = dc_field(
1386+
default=None,
1387+
metadata=dc_config(
1388+
field_name="ended_at",
1389+
encoder=encode_datetime,
1390+
decoder=datetime_from_unix_ns,
1391+
mm_field=fields.DateTime(format="iso"),
1392+
),
1393+
)
1394+
started_at: Optional[datetime] = dc_field(
1395+
default=None,
1396+
metadata=dc_config(
1397+
field_name="started_at",
1398+
encoder=encode_datetime,
1399+
decoder=datetime_from_unix_ns,
1400+
mm_field=fields.DateTime(format="iso"),
1401+
),
1402+
)
1403+
1404+
13821405
@dataclass
13831406
class CallRequest(DataClassJsonMixin):
13841407
created_by_id: Optional[str] = dc_field(
@@ -5342,6 +5365,13 @@ class GetCallResponse(DataClassJsonMixin):
53425365
call: "CallResponse" = dc_field(metadata=dc_config(field_name="call"))
53435366

53445367

5368+
@dataclass
5369+
class GetCallReportResponse(DataClassJsonMixin):
5370+
duration: str = dc_field(metadata=dc_config(field_name="duration"))
5371+
session_id: str = dc_field(metadata=dc_config(field_name="session_id"))
5372+
report: "ReportResponse" = dc_field(metadata=dc_config(field_name="report"))
5373+
5374+
53455375
@dataclass
53465376
class GetCallStatsResponse(DataClassJsonMixin):
53475377
call_duration_seconds: int = dc_field(
@@ -7872,6 +7902,12 @@ class PaginationParams(DataClassJsonMixin):
78727902
)
78737903

78747904

7905+
@dataclass
7906+
class ParticipantReportResponse(DataClassJsonMixin):
7907+
sum: int = dc_field(metadata=dc_config(field_name="sum"))
7908+
unique: int = dc_field(metadata=dc_config(field_name="unique"))
7909+
7910+
78757911
@dataclass
78767912
class PendingMessageResponse(DataClassJsonMixin):
78777913
channel: "Optional[ChannelResponse]" = dc_field(
@@ -9583,6 +9619,17 @@ class ReportByHistogramBucket(DataClassJsonMixin):
95839619
)
95849620

95859621

9622+
@dataclass
9623+
class ReportResponse(DataClassJsonMixin):
9624+
call: "CallReportResponse" = dc_field(metadata=dc_config(field_name="call"))
9625+
participants: "ParticipantReportResponse" = dc_field(
9626+
metadata=dc_config(field_name="participants")
9627+
)
9628+
user_ratings: "UserRatingReportResponse" = dc_field(
9629+
metadata=dc_config(field_name="user_ratings")
9630+
)
9631+
9632+
95869633
@dataclass
95879634
class Response(DataClassJsonMixin):
95889635
duration: str = dc_field(metadata=dc_config(field_name="duration"))
@@ -12364,6 +12411,12 @@ class UserReactivatedEvent(DataClassJsonMixin):
1236412411
)
1236512412

1236612413

12414+
@dataclass
12415+
class UserRatingReportResponse(DataClassJsonMixin):
12416+
average: float = dc_field(metadata=dc_config(field_name="average"))
12417+
count: int = dc_field(metadata=dc_config(field_name="count"))
12418+
12419+
1236712420
@dataclass
1236812421
class UserRequest(DataClassJsonMixin):
1236912422
id: str = dc_field(metadata=dc_config(field_name="id"))

getstream/video/rest_client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,3 +792,19 @@ def query_aggregate_call_stats(
792792
return self.post(
793793
"/api/v2/video/stats", QueryAggregateCallStatsResponse, json=json
794794
)
795+
796+
def get_call_report(
797+
self, type: str, id: str, session_id: Optional[str] = None
798+
) -> StreamResponse[GetCallReportResponse]:
799+
query_params = build_query_param(session_id=session_id)
800+
path_params = {
801+
"type": type,
802+
"id": id,
803+
}
804+
805+
return self.get(
806+
"/api/v2/video/call/{type}/{id}/report",
807+
GetCallReportResponse,
808+
query_params=query_params,
809+
path_params=path_params,
810+
)

tests/test_video_integration.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,16 @@ def test_delete_not_existing_transcription(self):
355355
with pytest.raises(StreamAPIException):
356356
self.call.delete_transcription("random_session", "random_filename")
357357

358+
def test_get_call_report_for_latest_session(self):
359+
with pytest.raises(StreamAPIException):
360+
self.client.video.get_call_report(self.call.call_type, self.call.id)
361+
362+
def test_get_call_report_for_specified_session(self):
363+
with pytest.raises(StreamAPIException):
364+
self.client.video.get_call_report(
365+
self.call.call_type, self.call.id, session_id="non_existent"
366+
)
367+
358368

359369
class TestDeleteCall:
360370
def test_soft_delete(self, call: Call):

0 commit comments

Comments
 (0)