Skip to content

Commit

Permalink
3.0.0rc3 release (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
aisling-2 authored Jun 27, 2023
1 parent 997fa33 commit 550f9dc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 47 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.0.0rc3 - 2023-06-27

### Added
- Added User-Agent header

## 3.0.0rc2 - 2023-05-31

### Added
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.binance</groupId>
<artifactId>binance-connector-java</artifactId>
<version>3.0.0rc2</version>
<version>3.0.0rc3</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>lightweight connector to API</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,80 +9,46 @@

public final class RequestBuilder {
private static final MediaType JSON_TYPE = MediaType.parse("application/json; charset=utf-8");
private static final String USER_AGENT = "binance-connector-java/3.0.0rc3";
private static final String CONTENT_TYPE = "application/x-www-form-urlencoded";

private RequestBuilder() {
}
public static Request buildPublicRequest(String fullUrl, HttpMethod httpMethod) {
try {
final Request request;
final Request.Builder requestBuilder = new Request.Builder().addHeader("User-Agent", USER_AGENT).addHeader("Content-Type", CONTENT_TYPE).url(fullUrl);
switch (httpMethod) {
case POST:
request = new Request.Builder().url(fullUrl)
.post(RequestBody.create("", JSON_TYPE))
.build();
break;
return requestBuilder.post(RequestBody.create("", JSON_TYPE)).build();
case GET:
request = new Request.Builder().url(fullUrl)
.get()
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
break;
return requestBuilder.get().build();
case PUT:
request = new Request.Builder().url(fullUrl)
.put(RequestBody.create("", JSON_TYPE))
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
break;
return requestBuilder.put(RequestBody.create("", JSON_TYPE)).build();
case DELETE:
request = new Request.Builder().url(fullUrl)
.delete()
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
break;
return requestBuilder.delete().build();
default:
throw new BinanceConnectorException("Invalid HTTP method: " + httpMethod);
}
return request;
} catch (IllegalArgumentException e) {
throw new BinanceConnectorException("Invalid URL: " + e.getMessage());
}
}

public static Request buildApiKeyRequest(String fullUrl, HttpMethod httpMethod, String apiKey) {
try {
final Request request;
final Request.Builder requestBuilder = new Request.Builder().addHeader("User-Agent", USER_AGENT).addHeader("Content-Type", CONTENT_TYPE).addHeader("X-MBX-APIKEY", apiKey).url(fullUrl);
switch (httpMethod) {
case POST:
request = new Request.Builder().url(fullUrl)
.post(RequestBody.create("", JSON_TYPE))
.addHeader("X-MBX-APIKEY", apiKey)
.build();
break;
return requestBuilder.post(RequestBody.create("", JSON_TYPE)).build();
case GET:
request = new Request.Builder().url(fullUrl)
.get()
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.addHeader("X-MBX-APIKEY", apiKey)
.build();
break;
return requestBuilder.get().build();
case PUT:
request = new Request.Builder().url(fullUrl)
.put(RequestBody.create("", JSON_TYPE))
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.addHeader("X-MBX-APIKEY", apiKey)
.build();
break;
return requestBuilder.put(RequestBody.create("", JSON_TYPE)).build();
case DELETE:
request = new Request.Builder().url(fullUrl)
.delete()
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.addHeader("X-MBX-APIKEY", apiKey)
.build();
break;
return requestBuilder.delete().build();
default:
throw new BinanceConnectorException("Invalid HTTP method: " + httpMethod);
}
return request;
} catch (IllegalArgumentException e) {
throw new BinanceConnectorException("Invalid URL: " + e.getMessage());
}
Expand Down

0 comments on commit 550f9dc

Please sign in to comment.