Skip to content

Commit 28b19ff

Browse files
committed
feat: ability to change rest client credentials
1 parent c523b68 commit 28b19ff

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

src/main/java/com/cryptomarket/sdk/HMAC.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public HMAC(String apiKey, String apiSecret, Integer window) {
2525
this.window = window;
2626
}
2727

28+
public Integer getWindow() {
29+
return window;
30+
}
31+
2832
public String getCredential(String method, String body, String url) {
2933
String timestamp = String.format("%d", System.currentTimeMillis());
3034
String message = new StringBuffer()

src/main/java/com/cryptomarket/sdk/rest/CloseableHttpClient.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99

1010
public interface CloseableHttpClient extends Closeable {
1111

12+
/**
13+
* Changes the user credentials used for authentication in calls
14+
* @param apiKey the user public key used in new calls
15+
* @param apiSecret the user secret key used in new calls
16+
*/
17+
public void changeCredentials(String apiKey, String apiSecret);
18+
1219
/**
1320
* Does an http get without authentication
1421
*

src/main/java/com/cryptomarket/sdk/rest/CryptomarketRestClientImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class CryptomarketRestClientImpl implements CryptomarketRestClient {
5353
Adapter adapter = new Adapter();
5454

5555
public CryptomarketRestClientImpl(String apiKey, String apiSecret) {
56-
this(apiKey, apiSecret, HttpClients.createDefault());
56+
this(apiKey, apiSecret, HttpClients.createDefault());
5757
}
5858

5959
public CryptomarketRestClientImpl(String apiKey, String apiSecret,
@@ -71,6 +71,11 @@ public CryptomarketRestClientImpl(org.apache.http.impl.client.CloseableHttpClien
7171
this("", "", client);
7272
}
7373

74+
@Override
75+
public void changeCredentials(String apiKey, String apiSecret) {
76+
httpClient.changeCredentials(apiKey, apiSecret);
77+
}
78+
7479
// PUBLIC
7580

7681
@Override

src/main/java/com/cryptomarket/sdk/rest/HttpClientImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public HttpClientImpl(org.apache.http.impl.client.CloseableHttpClient client, St
9898
this.apiVersion = apiVersion;
9999
}
100100

101+
@Override
102+
public void changeCredentials(String apiKey, String apiSecret) {
103+
this.hmac = new HMAC(apiKey, apiSecret, hmac.getWindow());
104+
}
105+
101106
public void close() throws IOException {
102107
client.close();
103108
}

0 commit comments

Comments
 (0)