Skip to content

Commit

Permalink
0.2.0 (#9)
Browse files Browse the repository at this point in the history
* Add new query list objects
* Add attachment Resource with fetch requests
* Change naming, readmes etc. accordingly
  • Loading branch information
BolZer authored Sep 5, 2023
1 parent 3d9b26b commit eaccb6d
Show file tree
Hide file tree
Showing 247 changed files with 872 additions and 113 deletions.
14 changes: 7 additions & 7 deletions .idea/compiler.xml

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

2 changes: 1 addition & 1 deletion .idea/gradle.xml

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

4 changes: 2 additions & 2 deletions .idea/modules.xml

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

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

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

8 changes: 0 additions & 8 deletions .idea/modules/lib/easybill-java-sdk.lib.main.iml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules/lib/easybill-java-sdk.lib.test.iml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import java.net.URI

version = "0.1"
version = "0.2.0"

java {
withJavadocJar()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public final class Client {

@NonNull
public static final String USER_AGENT = "easybill-JAVA-REST-SDK-0.1";
public static final String USER_AGENT = "easybill-JAVA-REST-SDK-0.2.0";

@NonNull
@SuppressFBWarnings
Expand Down Expand Up @@ -92,4 +92,8 @@ public Client(@NonNull String bearerToken) {
public @NonNull ContactResource getContactResource() {
return new ContactResource(this.httpClient);
}

public @NonNull AttachmentResource getAttachmentResource() {
return new AttachmentResource(this.httpClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,14 @@ private void handleBadRequest(Response response)
new TypeReference<HashMap<String, Object>>() {}
);

@SuppressWarnings("unchecked")
List<@NonNull String> arguments =
(List<String>) errorResponse.getOrDefault("arguments", List.of());

throw new EasybillBadRequestException(
response.code(),
(int) errorResponse.getOrDefault("code", 0),
(List<String>) errorResponse.getOrDefault("arguments", List.of()),
arguments,
(String) errorResponse.getOrDefault("message", ""),
response.request()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.github.bolzer.easybill_java_sdk.models;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.LocalDate;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

public record Attachment(
@JsonProperty("id") long id,
@JsonProperty("size") long size,
@JsonProperty("customer_id") @Nullable Long customerId,
@JsonProperty("project_id") @Nullable Long projectId,
@JsonProperty("document_id") @Nullable Long documentId,
@JsonProperty("file_name") @NonNull String fileName,
@JsonProperty("created_at")
@NonNull
@JsonFormat(pattern = "yyyy-MM-dd")
LocalDate createdAt
) {}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public final class CustomerListQueryRequest implements QueryRequest {
map.put("page", String.valueOf(page));
map.put("limit", String.valueOf(limit));

if (firstNames.size() > 0) {
if (!firstNames.isEmpty()) {
map.put(
"first_name",
String.join(
Expand All @@ -90,7 +90,7 @@ public final class CustomerListQueryRequest implements QueryRequest {
);
}

if (lastNames.size() > 0) {
if (!lastNames.isEmpty()) {
map.put(
"last_name",
String.join(
Expand All @@ -100,7 +100,7 @@ public final class CustomerListQueryRequest implements QueryRequest {
);
}

if (companyNames.size() > 0) {
if (!companyNames.isEmpty()) {
map.put(
"company_name",
String.join(
Expand All @@ -110,21 +110,21 @@ public final class CustomerListQueryRequest implements QueryRequest {
);
}

if (numbers.size() > 0) {
if (!numbers.isEmpty()) {
map.put(
"number",
String.join(",", numbers.stream().map(String::valueOf).toList())
);
}

if (emails.size() > 0) {
if (!emails.isEmpty()) {
map.put(
"emails",
String.join(",", emails.stream().map(String::valueOf).toList())
);
}

if (zipCodes.size() > 0) {
if (!zipCodes.isEmpty()) {
map.put(
"zip_code",
String.join(
Expand All @@ -134,7 +134,7 @@ public final class CustomerListQueryRequest implements QueryRequest {
);
}

if (countries.size() > 0) {
if (!countries.isEmpty()) {
map.put(
"country",
String.join(
Expand All @@ -144,7 +144,7 @@ public final class CustomerListQueryRequest implements QueryRequest {
);
}

if (groupIds.size() > 0) {
if (!groupIds.isEmpty()) {
map.put(
"group_id",
String.join(
Expand All @@ -154,7 +154,7 @@ public final class CustomerListQueryRequest implements QueryRequest {
);
}

if (additionalGroupIds.size() > 0) {
if (!additionalGroupIds.isEmpty()) {
map.put(
"additional_group_id",
String.join(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.github.bolzer.easybill_java_sdk.requests;

import io.github.bolzer.easybill_java_sdk.contracts.QueryRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.Builder;
import lombok.Getter;
import lombok.Singular;
import org.checkerframework.checker.index.qual.Positive;
import org.checkerframework.checker.initialization.qual.Initialized;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.common.value.qual.IntRange;

@Builder
@Getter
public final class DiscountListQueryRequest implements QueryRequest {

@Builder.Default
@Positive
private int page = 1;

@Builder.Default
@IntRange(from = 100, to = 1000)
private int limit = 100;

@Singular
@NonNull
private List<@NonNull Long> customerIds;

@Override
public @Initialized @NonNull Map<@NonNull String, @NonNull String> toStringMap() {
final Map<String, String> map = new HashMap<>();
map.put("page", String.valueOf(page));
map.put("limit", String.valueOf(limit));

if (!customerIds.isEmpty()) {
map.put(
"customer_id",
String.join(
",",
this.customerIds.stream().map(String::valueOf).toList()
)
);
}

return map;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package io.github.bolzer.easybill_java_sdk.requests;

import io.github.bolzer.easybill_java_sdk.contracts.QueryRequest;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.Builder;
import lombok.Getter;
import lombok.Singular;
import org.checkerframework.checker.index.qual.Positive;
import org.checkerframework.checker.initialization.qual.Initialized;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.common.value.qual.IntRange;
import org.javatuples.Pair;

@Builder
@Getter
public final class DocumentPaymentListQueryRequest implements QueryRequest {

@Builder.Default
@Positive
private int page = 1;

@Builder.Default
@IntRange(from = 100, to = 1000)
private int limit = 100;

@Builder.Default
@Nullable
private LocalDate paymentAt = null;

@Builder.Default
@Nullable
private Pair<@NonNull LocalDate, @NonNull LocalDate> paymentBetween = null;

@Singular
@NonNull
private List<@NonNull Long> documentIds;

@Singular
@NonNull
private List<@NonNull String> references;

@Override
public @Initialized @NonNull Map<@NonNull String, @NonNull String> toStringMap() {
final Map<String, String> map = new HashMap<>();
map.put("page", String.valueOf(page));
map.put("limit", String.valueOf(limit));

if (!documentIds.isEmpty()) {
map.put(
"document_id",
String.join(
",",
this.documentIds.stream().map(String::valueOf).toList()
)
);
}

if (!references.isEmpty()) {
map.put("references", String.join(",", this.references));
}

if (Objects.nonNull(paymentAt)) {
map.put(
"payment_at",
paymentAt.format(DateTimeFormatter.ISO_LOCAL_DATE)
);
}

if (Objects.nonNull(paymentBetween)) {
Pair<@NonNull LocalDate, @NonNull LocalDate> paymentBetween =
Objects.requireNonNull(this.paymentBetween);

map.put(
"created_at",
String.join(
",",
paymentBetween
.getValue0()
.format(DateTimeFormatter.ISO_LOCAL_DATE),
paymentBetween
.getValue1()
.format(DateTimeFormatter.ISO_LOCAL_DATE)
)
);
}

return map;
}
}
Loading

0 comments on commit eaccb6d

Please sign in to comment.