Base.java
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.qcloud.Module;
import com.qcloud.Common.*;
import java.util.TreeMap;
public abstract class Base {
protected String serverHost = "";
protected String serverUri = "/v2/index.php";
protected String secretId = "";
protected String secretKey = "";
protected String defaultRegion = "";
protected String requestMethod = "GET";
public void setConfig(TreeMap<String, Object> config) {
if (config == null)
return;
for (String key : config.keySet()) {
if(key.equals("SecretId")){
setConfigSecretId(config.get(key).toString());
}
else if(key.equals("SecretKey")){
setConfigSecretKey(config.get(key).toString());
}
else if(key.equals("DefaultRegion")){
setConfigDefaultRegion(config.get(key).toString());
}
else if(key.equals("RequestMethod")){
setConfigRequestMethod(config.get(key).toString());
}
}
}
public void setConfigSecretId(String secretId) {
this.secretId = secretId;
}
public void setConfigSecretKey(String secretKey) {
this.secretKey = secretKey;
}
public void setConfigDefaultRegion(String region) {
this.defaultRegion = region;
}
public void setConfigRequestMethod(String method) {
this.requestMethod = method;
}
public String getLastRequest() {
return Request.getRequestUrl();
}
public String getLastResponse() {
return Request.getRawResponse();
}
private String ucFirst(String word){
return word.replaceFirst(word.substring(0, 1),
word.substring(0, 1).toUpperCase());
}
public String generateUrl(String actionName, TreeMap<String, Object> params) {
actionName = ucFirst(actionName);
if(params == null)
params = new TreeMap<String, Object>();
params.put("Action", actionName);
if (!params.containsKey("Region")) {
params.put("Region", defaultRegion);
}
return Request.generateUrl(params, secretId, secretKey, requestMethod,
serverHost, serverUri);
}
public String call(String actionName, TreeMap<String, Object> params){
return call(actionName, params, null);
}
public String call(String actionName, TreeMap<String, Object> params, String fileName){
actionName = ucFirst(actionName);
if(params == null)
params = new TreeMap<String, Object>();
params.put("Action", actionName);
if (!params.containsKey("Region")) {
params.put("Region", defaultRegion);
}
String response = Request.send(params, secretId, secretKey, requestMethod, serverHost, serverUri, fileName);
return response;
}
}