Skip to content

Commit 99c2800

Browse files
authored
Merge pull request #2 from unit7-0/master
Add ability to override default host value
2 parents 5b2e7c4 + 00d00b1 commit 99c2800

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

src/main/java/com/corezoid/sdk/entity/CorezoidMessage.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,22 @@ public static String response(List<ResponseOperation> operations) {
4040

4141
/**
4242
* Builder for request message
43-
*
43+
*/
44+
public static CorezoidMessage request(String apiSecret, String apiLogin,
45+
List<RequestOperation> operations) {
46+
return request(host, apiSecret, apiLogin, operations);
47+
}
48+
//----------------------------------------------------------------------------------------------------------------------
49+
50+
/**
51+
* Builder for request message
52+
* @param host override default host value
4453
* @param apiSecret
4554
* @param apiLogin
4655
* @param operations
4756
* @return
4857
*/
49-
public static CorezoidMessage request(String apiSecret, String apiLogin,
58+
public static CorezoidMessage request(String host, String apiSecret, String apiLogin,
5059
List<RequestOperation> operations) {
5160
if (apiSecret == null || apiSecret.equals("")) {
5261
throw new IllegalArgumentException("apiSecret is null or empty");
@@ -67,7 +76,7 @@ public static CorezoidMessage request(String apiSecret, String apiLogin,
6776
String content = obj.toString();
6877
String unixTime = String.valueOf(System.currentTimeMillis() / 1000);
6978

70-
return new CorezoidMessage(content, unixTime, apiSecret, apiLogin);
79+
return new CorezoidMessage(content, unixTime, apiSecret, apiLogin, host);
7180
}
7281
//----------------------------------------------------------------------------------------------------------------------
7382

@@ -115,12 +124,18 @@ public static Map<String, String> parseAnswer(String jsonString) throws Exceptio
115124
//----------------------------------------------------------------------------------------------------------------------
116125
private CorezoidMessage(String body, String time, String apiSecret,
117126
String apiLogin) {
127+
this(body, time, apiSecret, apiLogin, host);
128+
}
129+
130+
//----------------------------------------------------------------------------------------------------------------------
131+
private CorezoidMessage(String body, String time, String apiSecret,
132+
String apiLogin, String baseUri) {
118133
this.body = body;
119134
this.time = time;
120135
this.apiSecret = apiSecret;
121136
this.signCode = generateSign(time, apiSecret, body);
122137
this.url = new StringBuilder()
123-
.append(host).append("/api/")
138+
.append(baseUri).append("/api/")
124139
.append(version).append(slash)
125140
.append(format).append(slash)
126141
.append(apiLogin).append(slash)

0 commit comments

Comments
 (0)