Skip to content

Commit

Permalink
0.4.0 (#12)
Browse files Browse the repository at this point in the history
* Bump Version to 0.4.0
* Use Gradle 8.3
* Rename HttpClient methods to avoid issue with FindBugs
* Add documentation
* Add package-info
* Remove FBWarnings Annotations
* Change download pdf test
  • Loading branch information
BolZer authored Sep 15, 2023
1 parent 2a8480d commit 6ef48ff
Show file tree
Hide file tree
Showing 30 changed files with 253 additions and 185 deletions.
1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

**2023-09-15 - Version 0.4.0**
- Add documentation to document resource
- Remove FBWarning Annotations
- Change Naming of methods in HttpClient contract to avoid FBWarnings

**2023-09-13 - Version 0.3.0**
- Finalize Attachment Resource
- Add missing copy method in Document Resource
Expand Down
4 changes: 2 additions & 2 deletions easybill-java-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import java.net.URI

version = "0.3.0"
version = "0.4.0"

java {
withJavadocJar()
Expand Down Expand Up @@ -51,7 +51,7 @@ publishing {
create<MavenPublication>("maven") {
groupId = "io.github.bolzer"
artifactId = "easybill-java-sdk"
version = "0.3.0"
version = "0.4.0"

from(components["java"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@
import io.github.bolzer.easybill_java_sdk.resources.*;
import org.checkerframework.checker.nullness.qual.NonNull;

/** The REST API Client of the SDK. Exposes the different REST API resources as high levels methods. */
public final class Client {

/** User-Agent to be used for the HTTP-Header User-Agent. This agent is not customizable.*/
@NonNull
public static final String USER_AGENT = "easybill-JAVA-REST-SDK-0.3.0";
public static final String USER_AGENT = "easybill-JAVA-REST-SDK-0.4.0";

/**
* The base url for the easybill REST API. It's intentional left non-final as this URL is overwritten
* for testing purpose
*/
@NonNull
@SuppressFBWarnings
public static String BASE_URL = "https://api.easybill.de/rest/v1";

/**
* The actual http client. Abstracted by the Interface-Contract in the SDK. The SDK actually uses
* OKHttpClient.
*/
@NonNull
private final HttpClient httpClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

public final class HttpClientImpl implements HttpClient {
final class HttpClientImpl implements HttpClient {

private enum RequestMethod {
GET,
Expand All @@ -48,7 +48,7 @@ public HttpClientImpl(@NonNull String apiToken) {
.build();
}

public @NonNull ByteBuffer getBytes(@NonNull String endpoint)
public @NonNull ByteBuffer requestGetBytes(@NonNull String endpoint)
throws EasybillRestException {
try {
try (
Expand Down Expand Up @@ -77,7 +77,7 @@ public HttpClientImpl(@NonNull String apiToken) {
}
}

public @NonNull <T extends @Initialized @NonNull Object> T getJson(
public @NonNull <T extends @Initialized @NonNull Object> T requestGetJson(
@NonNull String endpoint,
@NonNull TypeReference<T> typeReference
) throws EasybillRestException {
Expand All @@ -101,7 +101,7 @@ public HttpClientImpl(@NonNull String apiToken) {
}
}

public @NonNull <T extends @Initialized @NonNull Object> T getJson(
public @NonNull <T extends @Initialized @NonNull Object> T requestGetJson(
@NonNull String endpoint,
@Nullable QueryRequest queryRequest,
@NonNull TypeReference<T> typeReference
Expand All @@ -127,7 +127,7 @@ public HttpClientImpl(@NonNull String apiToken) {
}

@Override
public void postEmpty(@NonNull String endpoint)
public void requestPostEmpty(@NonNull String endpoint)
throws EasybillRestException {
try {
try (
Expand All @@ -145,10 +145,10 @@ public void postEmpty(@NonNull String endpoint)
}

@Override
public <T extends @Initialized @NonNull Object> T postFile(
public <T extends @Initialized @NonNull Object> T requestPostFile(
@NonNull String endpoint,
@NonNull File file,
TypeReference<T> typeReference
@NonNull TypeReference<T> typeReference
) throws EasybillRestException {
try {
RequestBody requestBody = new MultipartBody.Builder()
Expand Down Expand Up @@ -180,10 +180,10 @@ public void postEmpty(@NonNull String endpoint)
}

@Override
public <T extends @Initialized @NonNull Object> T postJson(
public <T extends @Initialized @NonNull Object> T requestPostJson(
@NonNull String endpoint,
@NonNull Object payload,
TypeReference<T> typeReference
@NonNull TypeReference<T> typeReference
) throws EasybillRestException {
try {
final RequestBody requestBody = RequestBody.create(
Expand Down Expand Up @@ -211,11 +211,11 @@ public void postEmpty(@NonNull String endpoint)
}

@Override
public <T extends @Initialized @NonNull Object> T postJson(
public <T extends @Initialized @NonNull Object> T requestPostJson(
@NonNull String endpoint,
@NonNull QueryRequest queryRequest,
@NonNull Object payload,
TypeReference<T> typeReference
@NonNull TypeReference<T> typeReference
) throws EasybillRestException {
try {
final RequestBody requestBody = RequestBody.create(
Expand Down Expand Up @@ -243,8 +243,10 @@ public void postEmpty(@NonNull String endpoint)
}

@Override
public void postJson(@NonNull String endpoint, @NonNull Object payload)
throws EasybillRestException {
public void requestPostJson(
@NonNull String endpoint,
@NonNull Object payload
) throws EasybillRestException {
try {
final RequestBody requestBody = RequestBody.create(
this.getPreparedObjectMapper().writeValueAsString(payload),
Expand All @@ -266,10 +268,10 @@ public void postJson(@NonNull String endpoint, @NonNull Object payload)
}

@Override
public <T extends @Initialized @NonNull Object> T putJson(
public <T extends @Initialized @NonNull Object> T requestPutJson(
@NonNull String endpoint,
@NonNull Object payload,
TypeReference<T> typeReference
@NonNull TypeReference<T> typeReference
) throws EasybillRestException {
try {
final RequestBody requestBody = RequestBody.create(
Expand Down Expand Up @@ -297,11 +299,11 @@ public void postJson(@NonNull String endpoint, @NonNull Object payload)
}

@Override
public <T extends @Initialized @NonNull Object> T putJson(
public <T extends @Initialized @NonNull Object> T requestPutJson(
@NonNull String endpoint,
@NonNull QueryRequest queryRequest,
@NonNull Object payload,
TypeReference<T> typeReference
@NonNull TypeReference<T> typeReference
) throws EasybillRestException {
try {
final RequestBody requestBody = RequestBody.create(
Expand Down Expand Up @@ -329,7 +331,8 @@ public void postJson(@NonNull String endpoint, @NonNull Object payload)
}

@Override
public void delete(@NonNull String endpoint) throws EasybillRestException {
public void requestDelete(@NonNull String endpoint)
throws EasybillRestException {
try {
try (
Response response = this.request(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,59 @@

public interface HttpClient {
@NonNull
ByteBuffer getBytes(@NonNull String endpoint) throws EasybillRestException;
ByteBuffer requestGetBytes(@NonNull String endpoint)
throws EasybillRestException;

@NonNull
<T extends @Initialized @NonNull Object> T getJson(
<T extends @Initialized @NonNull Object> T requestGetJson(
@NonNull String endpoint,
@NonNull TypeReference<T> typeReference
) throws EasybillRestException;

@NonNull
<T extends @Initialized @NonNull Object> T getJson(
<T extends @Initialized @NonNull Object> T requestGetJson(
@NonNull String endpoint,
@NonNull QueryRequest queryRequest,
@NonNull TypeReference<T> typeReference
) throws EasybillRestException;

void postEmpty(@NonNull String endpoint) throws EasybillRestException;
void requestPostEmpty(@NonNull String endpoint)
throws EasybillRestException;

<T extends @Initialized @NonNull Object> T postFile(
<T extends @Initialized @NonNull Object> T requestPostFile(
@NonNull String endpoint,
@NonNull File file,
TypeReference<T> typeReference
) throws EasybillRestException;

<T extends @Initialized @NonNull Object> T postJson(
<T extends @Initialized @NonNull Object> T requestPostJson(
@NonNull String endpoint,
@NonNull Object payload,
TypeReference<T> typeReference
@NonNull TypeReference<T> typeReference
) throws EasybillRestException;

<T extends @Initialized @NonNull Object> T postJson(
<T extends @Initialized @NonNull Object> T requestPostJson(
@NonNull String endpoint,
@NonNull QueryRequest queryRequest,
@NonNull Object payload,
TypeReference<T> typeReference
@NonNull TypeReference<T> typeReference
) throws EasybillRestException;

void postJson(@NonNull String endpoint, @NonNull Object payload)
void requestPostJson(@NonNull String endpoint, @NonNull Object payload)
throws EasybillRestException;

<T extends @Initialized @NonNull Object> T putJson(
<T extends @Initialized @NonNull Object> T requestPutJson(
@NonNull String endpoint,
@NonNull Object payload,
TypeReference<T> typeReference
@NonNull TypeReference<T> typeReference
) throws EasybillRestException;

<T extends @Initialized @NonNull Object> T putJson(
<T extends @Initialized @NonNull Object> T requestPutJson(
@NonNull String endpoint,
@NonNull QueryRequest queryRequest,
@NonNull Object payload,
TypeReference<T> typeReference
@NonNull TypeReference<T> typeReference
) throws EasybillRestException;

void delete(@NonNull String endpoint) throws EasybillRestException;
void requestDelete(@NonNull String endpoint) throws EasybillRestException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* This module offers a high level abstraction to work with the easybill REST API
* @see <a href="https://www.easybill.de/api/">easybill REST API Swagger</a>
*/
package io.github.bolzer.easybill_java_sdk;
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.bolzer.easybill_java_sdk.resources;

import com.fasterxml.jackson.core.type.TypeReference;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.github.bolzer.easybill_java_sdk.contracts.HttpClient;
import io.github.bolzer.easybill_java_sdk.exceptions.EasybillRestException;
import io.github.bolzer.easybill_java_sdk.models.Attachment;
Expand All @@ -19,7 +18,6 @@ public final class AttachmentResource {
public static final String RESOURCE_URL = "/attachments";

@NonNull
@SuppressFBWarnings
private final HttpClient httpClient;

public AttachmentResource(@NonNull HttpClient httpClient) {
Expand All @@ -29,7 +27,7 @@ public AttachmentResource(@NonNull HttpClient httpClient) {
public @NonNull PaginatedResponse<Attachment> fetchAttachments(
GenericListQueryRequest genericListQueryRequest
) throws EasybillRestException {
return this.httpClient.getJson(
return this.httpClient.requestGetJson(
RESOURCE_URL,
genericListQueryRequest,
new TypeReference<>() {}
Expand All @@ -38,15 +36,15 @@ public AttachmentResource(@NonNull HttpClient httpClient) {

public @NonNull Attachment fetchAttachment(long attachmentId)
throws EasybillRestException {
return this.httpClient.getJson(
return this.httpClient.requestGetJson(
RESOURCE_URL + "/" + attachmentId,
new TypeReference<>() {}
);
}

public @NonNull Attachment createAttachment(File file)
throws EasybillRestException {
return this.httpClient.postFile(
return this.httpClient.requestPostFile(
RESOURCE_URL,
file,
new TypeReference<>() {}
Expand All @@ -57,7 +55,7 @@ public AttachmentResource(@NonNull HttpClient httpClient) {
@Positive long attachmentId,
@NonNull AttachmentRequest attachmentRequest
) throws EasybillRestException {
return this.httpClient.putJson(
return this.httpClient.requestPutJson(
RESOURCE_URL + "/" + attachmentId,
attachmentRequest,
new TypeReference<>() {}
Expand All @@ -66,13 +64,13 @@ public AttachmentResource(@NonNull HttpClient httpClient) {

public @NonNull ByteBuffer fetchAttachmentContent(long attachmentId)
throws EasybillRestException {
return this.httpClient.getBytes(
return this.httpClient.requestGetBytes(
RESOURCE_URL + "/" + attachmentId + "/content"
);
}

public void deleteAttachment(@Positive long attachmentId)
throws EasybillRestException {
this.httpClient.delete(RESOURCE_URL + "/" + attachmentId);
this.httpClient.requestDelete(RESOURCE_URL + "/" + attachmentId);
}
}
Loading

0 comments on commit 6ef48ff

Please sign in to comment.