diff --git a/src/main/java/com/qiniu/http/Response.java b/src/main/java/com/qiniu/http/Response.java index 15c8bd79e..4f2cf43eb 100644 --- a/src/main/java/com/qiniu/http/Response.java +++ b/src/main/java/com/qiniu/http/Response.java @@ -116,7 +116,10 @@ public static Response createError(okhttp3.Response response, String address, do address, duration, error, body); } - + public static Response createInvalidArgument( String error) { + return new Response(null, InvalidArgument, "", "", "", + "", 0, error, null); + } private static String via(okhttp3.Response response) { String via; if (!(via = response.header("X-Via", "")).equals("")) { diff --git a/src/main/java/com/qiniu/rtc/RtcRoomManager.java b/src/main/java/com/qiniu/rtc/RtcRoomManager.java index a2e56fe64..c49247aec 100644 --- a/src/main/java/com/qiniu/rtc/RtcRoomManager.java +++ b/src/main/java/com/qiniu/rtc/RtcRoomManager.java @@ -8,6 +8,8 @@ import com.qiniu.util.Auth; import com.qiniu.util.StringMap; +import java.util.Objects; + public class RtcRoomManager { private final Auth auth; private final String host; @@ -75,6 +77,46 @@ private String getLink(String appId, String roomName, String param) { return builder.toString(); } + /** + * + * @param appId + * @param roomName + * @param start 开始时间:20200317000000 + * @param end 结束时间:20200317200000 + * @param G 查询的粒度,可选(5min, hour, day, month),默认为day + * @param total 表示查询房间的总时⻓ int64 + * @param kind 表示类型,Audio/SD/HD/UHD string + * @return Response + * @throws QiniuException + */ + public Response getCalculateForRoom(String appId, String roomName, String start, String end, String G, int total, String kind) throws QiniuException { + if (appId == null || roomName == null || start == null || end == null) { + return Response.createInvalidArgument("some request param is null"); + } + StringBuilder builder = new StringBuilder(); + builder.append(host); + builder.append("/v3/apps/").append(appId).append("/rooms/").append(roomName).append("/metric?"); + if (start != null) { + builder.append("start=").append(start).append("&"); + } + if (end != null) { + builder.append("end=").append(end); + } + if (G != null) { + builder.append("&granule=").append(G); + } + if (total > 0) { + builder.append("&total=").append(total); + } + if (kind != null) { + builder.append("&kind=").append(kind); + } + String url = builder.toString(); + StringMap headers = auth.authorizationV2(builder.toString()); + System.out.println("url:"+url); + return client.get(url, headers); + } + /** * @param appId 房间所属帐号的 app * @param roomName 房间名称,需满足规格 ^[a-zA-Z0-9_-]{3,64}$ diff --git a/src/test/java/test/com/qiniu/rtc/RtcTest.java b/src/test/java/test/com/qiniu/rtc/RtcTest.java index 86e5adb9c..630797712 100644 --- a/src/test/java/test/com/qiniu/rtc/RtcTest.java +++ b/src/test/java/test/com/qiniu/rtc/RtcTest.java @@ -5,6 +5,7 @@ import com.qiniu.rtc.RtcAppManager; import com.qiniu.rtc.RtcRoomManager; import com.qiniu.util.Auth; +import org.junit.Test; import test.com.qiniu.TestConfig; @@ -95,6 +96,16 @@ public void getRoomToken() { } } + @Test + public void getCalculateForRoom(){ + try { + Response response =rmanager.getCalculateForRoom("dix05zn6q", "roomtest", "20200317000000", "20200317193000", null,0,null); + System.out.print(getString(response)); + } catch (Exception e) { + e.printStackTrace(); + } + } + private String getString(Response response) { String[] resJson = response.getInfo().split("\n"); return response.statusCode + "\n" + resJson[2];