-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #479 from qiniu/hugo
[qvs]add stopStream and delete check argument
- Loading branch information
Showing
8 changed files
with
497 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package com.qiniu.qvs; | ||
|
||
import com.qiniu.common.QiniuException; | ||
import com.qiniu.qvs.model.Device; | ||
import com.qiniu.qvs.model.PatchOperation; | ||
import com.qiniu.http.Client; | ||
import com.qiniu.http.Response; | ||
import com.qiniu.util.Auth; | ||
import com.qiniu.util.StringMap; | ||
import com.qiniu.util.UrlUtils; | ||
|
||
public class DeviceManager { | ||
|
||
private final String apiServer; | ||
private final Client client; | ||
private final Auth auth; | ||
|
||
public DeviceManager(Auth auth) { | ||
this(auth, "http://qvs.qiniuapi.com"); | ||
} | ||
|
||
public DeviceManager(Auth auth, String apiServer) { | ||
this(auth, apiServer, new Client()); | ||
} | ||
|
||
public DeviceManager(Auth auth, String apiServer, Client client) { | ||
this.auth = auth; | ||
this.apiServer = apiServer; | ||
this.client = client; | ||
} | ||
|
||
|
||
/* | ||
* 创建设备 | ||
*/ | ||
public Response createDevice(String namespaceId, Device device) throws QiniuException { | ||
StringMap params = new StringMap(); | ||
params.put("name", device.getName()); | ||
params.put("gbId", device.getGbId()); | ||
params.putNotNull("username", device.getUsername()); | ||
params.putNotNull("password", device.getPassword()); | ||
params.put("pullIfRegister", device.isPullIfRegister()); | ||
params.put("desc", device.getDesc()); | ||
|
||
String url = String.format("%s/v1/namespaces/%s/devices", apiServer, namespaceId); | ||
return QvsResponse.post(url, params, client, auth); | ||
} | ||
|
||
/* | ||
* 删除设备 | ||
*/ | ||
public Response deleteDevice(String namespaceId, String gbId) throws QiniuException { | ||
String url = String.format("%s/v1/namespaces/%s/devices/%s", apiServer, namespaceId, gbId); | ||
return QvsResponse.delete(url, client, auth); | ||
} | ||
|
||
/* | ||
* 更新设备 | ||
*/ | ||
public Response updateDevice(String namespaceId, String gbId, PatchOperation[] patchOperation) | ||
throws QiniuException { | ||
StringMap params = new StringMap().put("operations", patchOperation); | ||
String url = String.format("%s/v1/namespaces/%s/devices/%s", apiServer, namespaceId, gbId); | ||
return QvsResponse.patch(url, params, client, auth); | ||
} | ||
|
||
/* | ||
* 查询设备 | ||
*/ | ||
public Response queryDevice(String namespaceId, String gbId) throws QiniuException { | ||
String url = String.format("%s/v1/namespaces/%s/devices/%s", apiServer, namespaceId, gbId); | ||
return QvsResponse.get(url, client, auth); | ||
} | ||
|
||
/* | ||
* 获取设备列表 | ||
*/ | ||
public Response listDevice(String namespaceId, int offset, int line, String prefix, String state, int qtype) | ||
throws QiniuException { | ||
String requestUrl = String.format("%s/v1/namespaces/%s/devices", apiServer, namespaceId); | ||
StringMap map = new StringMap().put("offset", offset).put("line", line).put("qtype", qtype) | ||
.put("prefix", prefix).put("state", state); | ||
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map); | ||
return QvsResponse.get(requestUrl, client, auth); | ||
} | ||
|
||
/* | ||
* 获取通道列表 | ||
*/ | ||
public Response listChannels(String namespaceId, String gbId, String prefix) throws QiniuException { | ||
String requestUrl = String.format("%s/v1/namespaces/%s/devices/%s/channels", apiServer, namespaceId, gbId); | ||
StringMap map = new StringMap().put("prefix", prefix); | ||
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map); | ||
return QvsResponse.get(requestUrl, client, auth); | ||
} | ||
|
||
/* | ||
* 启动设备拉流 | ||
*/ | ||
public Response startDevice(String namespaceId, String gbId, String[] channels) throws QiniuException { | ||
String url = String.format("%s/v1/namespaces/%s/devices/%s/start", apiServer, namespaceId, gbId); | ||
StringMap params = new StringMap().put("channels", channels); | ||
return QvsResponse.post(url, params, client, auth); | ||
} | ||
|
||
/* | ||
* 停止设备拉流 | ||
*/ | ||
public Response stopDevice(String namespaceId, String gbId, String[] channels) throws QiniuException { | ||
String url = String.format("%s/v1/namespaces/%s/devices/%s/stop", apiServer, namespaceId, gbId); | ||
StringMap params = new StringMap().put("channels", channels); | ||
return QvsResponse.post(url, params, client, auth); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.qiniu.qvs.model; | ||
|
||
public class Device { | ||
private String name;// 设备名称(可包含 字母、数字、中划线、下划线;1 ~ 100 个字符长) | ||
private String gbId; // 设备国标ID | ||
private String username; // 用户名, 4~40位,可包含大写字母、小写字母、数字、中划线,建议与设备国标ID一致 | ||
private String password; // 密码, 4~40位,可包含大写字母、小写字母、数字、中划线 | ||
private boolean pullIfRegister; // 注册成功后启动拉流, 默认关闭 | ||
private String desc;// 关于设备的描述信息 | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getGbId() { | ||
return gbId; | ||
} | ||
|
||
public void setGbId(String gbId) { | ||
this.gbId = gbId; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
public boolean isPullIfRegister() { | ||
return pullIfRegister; | ||
} | ||
|
||
public void setPullIfRegister(boolean pullIfRegister) { | ||
this.pullIfRegister = pullIfRegister; | ||
} | ||
|
||
public String getDesc() { | ||
return desc; | ||
} | ||
|
||
public void setDesc(String desc) { | ||
this.desc = desc; | ||
} | ||
} |
Oops, something went wrong.