From 6ddd7694be500c2a94739c8d05c0627e7bb7653c Mon Sep 17 00:00:00 2001 From: Kewyn Akshlley Date: Mon, 23 Oct 2023 22:35:49 -0300 Subject: [PATCH] Fix compatibility issue with properties (#15) --- .../com/resend/core/net/impl/HttpClient.java | 11 ++++---- .../resend/core/util/PropertiesReader.java | 28 ------------------- .../java/com/resend/services/batch/Batch.java | 13 ++++++++- .../resend/services/domains/model/Domain.java | 3 ++ .../resend/services/domains/model/Record.java | 4 ++- 5 files changed, 23 insertions(+), 36 deletions(-) delete mode 100644 src/main/java/com/resend/core/util/PropertiesReader.java diff --git a/src/main/java/com/resend/core/net/impl/HttpClient.java b/src/main/java/com/resend/core/net/impl/HttpClient.java index 221c3b5..c9d2c11 100644 --- a/src/main/java/com/resend/core/net/impl/HttpClient.java +++ b/src/main/java/com/resend/core/net/impl/HttpClient.java @@ -4,7 +4,6 @@ import com.resend.core.net.HttpMethod; import com.resend.core.net.IHttpClient; -import com.resend.core.util.PropertiesReader; import okhttp3.*; import java.io.IOException; @@ -18,21 +17,21 @@ public class HttpClient implements IHttpClient { /** The base URL for the API. */ public static final String BASE_API = "https://api.resend.com"; + /** The version of the API */ + private static final String VERSION_NAME = "2.2.1"; + /** The User-Agent header value for HTTP requests. */ - public static final String USER_AGENT = "resend-java/"; + public static final String USER_AGENT = "resend-java/" + VERSION_NAME; /** The OkHttpClient instance for handling HTTP requests. */ private final OkHttpClient httpClient; - private final PropertiesReader propertiesReader; - /** * Constructs an instance of the HttpClient with the provided API key. * */ public HttpClient() { this.httpClient = new OkHttpClient(); - this.propertiesReader = new PropertiesReader(); } /** @@ -54,7 +53,7 @@ public AbstractHttpResponse perform(final String path, final String apiKey, fina Request request = new Request.Builder() .url(BASE_API + path) .addHeader("Accept", "application/json") - .addHeader("User-Agent", USER_AGENT + propertiesReader.retrieveProperty("VERSION_NAME")) + .addHeader("User-Agent", USER_AGENT) .addHeader("Authorization", "Bearer " + apiKey) .method(method.name(), requestBody) .build(); diff --git a/src/main/java/com/resend/core/util/PropertiesReader.java b/src/main/java/com/resend/core/util/PropertiesReader.java deleted file mode 100644 index ed26b65..0000000 --- a/src/main/java/com/resend/core/util/PropertiesReader.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.resend.core.util; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Properties; - -public class PropertiesReader { - private final Properties properties; - - public PropertiesReader() { - this.properties = new Properties(); - } - public String retrieveProperty(String propertyName) { - FileInputStream fis = null; - try { - fis = new FileInputStream("gradle.properties"); - properties.load(fis); - fis.close(); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } catch (IOException e) { - throw new RuntimeException(e); - } - - return properties.getProperty(propertyName); - } -} diff --git a/src/main/java/com/resend/services/batch/Batch.java b/src/main/java/com/resend/services/batch/Batch.java index e4c1140..e325b88 100644 --- a/src/main/java/com/resend/services/batch/Batch.java +++ b/src/main/java/com/resend/services/batch/Batch.java @@ -11,6 +11,9 @@ import java.util.List; +/** + * Represents the Resend Batch module. + */ public class Batch extends BaseService { /** * Constructsan instance of the {@code Batch} class. @@ -43,8 +46,16 @@ public CreateBatchEmailsResponse send(List emails) throws Rese return createBatchEmailsResponse; } - + + /** + * Creates and sends a batch of email messages based on the provided list of email requests. + * + * @param emails A list of {@link SendEmailRequest} objects representing the email messages to be sent. + * @return A {@link CreateBatchEmailsResponse} containing information about the created batch of emails. + * @throws ResendException if an error occurs during the creation and sending of the emails. + */ public CreateBatchEmailsResponse create(List emails) throws ResendException { return this.send(emails); } + } diff --git a/src/main/java/com/resend/services/domains/model/Domain.java b/src/main/java/com/resend/services/domains/model/Domain.java index bb29c01..aebe096 100644 --- a/src/main/java/com/resend/services/domains/model/Domain.java +++ b/src/main/java/com/resend/services/domains/model/Domain.java @@ -28,6 +28,9 @@ public class Domain extends AbstractDomain { @JsonProperty("dnsProvider") private String dnsProvider; + /** + * Empty constructor. + */ public Domain() { } diff --git a/src/main/java/com/resend/services/domains/model/Record.java b/src/main/java/com/resend/services/domains/model/Record.java index f605712..63a0a9d 100644 --- a/src/main/java/com/resend/services/domains/model/Record.java +++ b/src/main/java/com/resend/services/domains/model/Record.java @@ -28,7 +28,9 @@ public class Record { @JsonProperty("priority") private int priority; - + /** + * Empty constructor. + */ public Record() { }