Skip to content

Commit

Permalink
Add DomainLists
Browse files Browse the repository at this point in the history
  • Loading branch information
GuGaobai1994 committed Apr 20, 2017
1 parent 34bb968 commit c936d9b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/DomainListDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.http.Response;
import com.qiniu.util.Auth;

public class DomainListDemo {
public static void main(String args[]) {
//设置需要操作的账号的AK和SK
String ACCESS_KEY = "DWQOcrnPp1ogwgAHBdIK1mI-";
String SECRET_KEY = "cJFhYuaq7Vo35e1pmXO0aGkJG";
Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);

Zone z = Zone.zone0();
Configuration c = new Configuration(z);

//实例化一个BucketManager对象
BucketManager bucketManager = new BucketManager(auth, c);

//要列举文件的空间名
String bucket = "dorst1";

try {
String[] domainLists = bucketManager.domainList(bucket);
for(String domain : domainLists)
System.out.print(domain);

} catch (QiniuException e) {

}

}
}
13 changes: 13 additions & 0 deletions src/main/java/com/qiniu/storage/BucketManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ public String[] buckets() throws QiniuException {
return r.jsonToObject(String[].class);
}

/**
* 获取该空间下所有的domain
* @param bucket
* @return 该空间名下的domain
* @throws QiniuException
*/

public String[] domainList (String bucket) throws QiniuException{
String url = String.format("%s/v6/domain/list?tbl=%s", "http://api.qiniu.com" ,bucket);
Response r = get(url);
return r.jsonToObject(String[].class);
}

/**
* 根据前缀获取文件列表的迭代器
*
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/com/qiniu/storage/BucketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public void testBuckets() {
}
}

@Test
public void testDomains() {
try {
String[] domains = bucketManager.domainList(TestConfig.testBucket_z0);
assertNotNull(domains);
} catch (QiniuException e) {
assertEquals(401, e.code());
}
}

@Test
public void testList() {
try {
Expand Down

0 comments on commit c936d9b

Please sign in to comment.