From e5d2ce01f3c34947448221cbcb0ff8e6bb02b9a6 Mon Sep 17 00:00:00 2001 From: Krisztian Mozsi Date: Fri, 16 Feb 2024 00:25:01 +0000 Subject: [PATCH 1/7] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e037ae0..cd8e03c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ convertapi jar - 2.10 + 2.11-SNAPSHOT ConvertAPI Java Client The ConvertAPI helps converting various file formats. @@ -48,7 +48,7 @@ scm:git:git://github.com/ConvertAPI/convertapi-java.git scm:git:git@github.com:ConvertAPI/convertapi-java.git https://github.com/ConvertAPI/convertapi-java - v2.10 + HEAD From dff49fd45cafaa6e2527f6e1a833e5078ad9450e Mon Sep 17 00:00:00 2001 From: Krisztian Mozsi Date: Fri, 16 Feb 2024 01:22:50 +0000 Subject: [PATCH 2/7] Fix release script --- Dockerfile | 2 +- README.md | 2 +- examples/pom.xml | 2 +- maven-release.sh | 4 +--- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 85a747c..add5885 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ENV GPG_PASSPHRASE= ARG GIT_EMAIL= ARG FULL_NAME= -ARG MAVEN_VERSION=3.3.9 +ARG MAVEN_VERSION=3.9.6 ARG USER_HOME_DIR="/root" ENV MAVEN_HOME /usr/share/maven ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2" diff --git a/README.md b/README.md index feb2fe4..34bbbb4 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Add the following dependency to your pom.xml: com.convertapi.client convertapi - 2.9 + 2.10 ``` diff --git a/examples/pom.xml b/examples/pom.xml index 1880299..2177648 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -15,7 +15,7 @@ com.convertapi.client convertapi - 2.9 + 2.10 diff --git a/maven-release.sh b/maven-release.sh index 21409a4..2fac3bc 100644 --- a/maven-release.sh +++ b/maven-release.sh @@ -7,11 +7,9 @@ echo "Set private key..." cp -vr /gpg ~/.gnupg echo "pinentry-mode loopback" > ~/.gnupg/gpg.conf cp -vpr /maven ~/.m2 -cp -vr /ssh ~/.ssh echo "Cloning convertapi-java..." -ssh-keyscan github.com >> ~/.ssh/known_hosts -git clone git@github.com:ConvertAPI/convertapi-java.git +git clone https://${GIT_USERNAME}:${GIT_SECRET}@github.com/ConvertAPI/convertapi-java.git cd convertapi-java echo "Switching to the release branch..." From 6500a849cf38b2886ab36ca52809ffbdc7cdf918 Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Tue, 9 Apr 2024 14:43:49 +0300 Subject: [PATCH 3/7] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 34bbbb4..77a5fe0 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ You can get your secret at https://www.convertapi.com/a ```java Config.setDefaultSecret("your-api-secret"); +// or token authentication +Config.setDefaultToken("your-token"); +Config.setDefaultApiKey("your-api-key"); ``` ### File conversion From dafd887d7d1414f4faa41d278b26f58b746865a5 Mon Sep 17 00:00:00 2001 From: Krisztian Mozsi Date: Tue, 10 Sep 2024 00:55:45 +0100 Subject: [PATCH 4/7] Use bearer auth --- .../java/com/convertapi/client/Config.java | 73 ++++--------------- .../com/convertapi/client/ConvertApi.java | 58 ++++----------- src/main/java/com/convertapi/client/Http.java | 25 ++++--- .../java/com/convertapi/client/Param.java | 2 +- 4 files changed, 42 insertions(+), 116 deletions(-) diff --git a/src/main/java/com/convertapi/client/Config.java b/src/main/java/com/convertapi/client/Config.java index ead84dc..109656f 100644 --- a/src/main/java/com/convertapi/client/Config.java +++ b/src/main/java/com/convertapi/client/Config.java @@ -6,83 +6,44 @@ public class Config { - private static String defaultSecret; - private static String defaultToken; - private static String defaultApiKey; + private static String defaultApiCredentials; private static int defaultTimeout = 0; // Infinite read waiting private static Function defaultHttpClientBuilder = b -> b; private static final String SCHEME = "https"; private static final String HOST = "v2.convertapi.com"; private final String scheme; private final String host; - private final String secret; - private final String token; - private final String apiKey; + private final String apiCredentials; private final int timeout; private final Function httpClientBuilder; @SuppressWarnings("unused") - public Config(String secret, String scheme, String host, int timeout, Function httpClientBuilder) { + public Config(String apiCredentials, String scheme, String host, int timeout, Function httpClientBuilder) { this.scheme = scheme; this.host = host; - this.secret = secret; - this.token = null; - this.apiKey = null; - this.timeout = timeout; - this.httpClientBuilder = httpClientBuilder; - } - - @SuppressWarnings("unused") - public Config(String token, String apiKey, String scheme, String host, int timeout, Function httpClientBuilder) { - this.scheme = scheme; - this.host = host; - this.secret = null; - this.token = token; - this.apiKey = apiKey; + this.apiCredentials = apiCredentials; this.timeout = timeout; this.httpClientBuilder = httpClientBuilder; } @SuppressWarnings("WeakerAccess") public static Config defaults() { - if (Config.defaultSecret != null) - return new Config(Config.defaultSecret, SCHEME, HOST, defaultTimeout, Config.defaultHttpClientBuilder); - return new Config(Config.defaultToken, Config.defaultApiKey, SCHEME, HOST, defaultTimeout, Config.defaultHttpClientBuilder); - } - - @SuppressWarnings("WeakerAccess") - public static Config defaults(String secret) { - return new Config(secret, SCHEME, HOST, defaultTimeout, Config.defaultHttpClientBuilder); + return new Config(Config.defaultApiCredentials, SCHEME, HOST, defaultTimeout, Config.defaultHttpClientBuilder); } @SuppressWarnings("WeakerAccess") - public static Config defaults(String token, String apiKey) { - return new Config(token, apiKey, SCHEME, HOST, defaultTimeout, Config.defaultHttpClientBuilder); + public static Config defaults(String apiCredentials) { + return new Config(apiCredentials, SCHEME, HOST, defaultTimeout, Config.defaultHttpClientBuilder); } @SuppressWarnings("WeakerAccess") - public static Config defaults(String secret, Function httpClientBuilder) { - return new Config(secret, SCHEME, HOST, defaultTimeout, httpClientBuilder); - } - - @SuppressWarnings("WeakerAccess") - public static Config defaults(String token, String apiKey, Function httpClientBuilder) { - return new Config(token, apiKey, SCHEME, HOST, defaultTimeout, httpClientBuilder); - } - - @SuppressWarnings("unused") - public static void setDefaultSecret(String defaultSecret) { - Config.defaultSecret = defaultSecret; + public static Config defaults(String apiCredentials, Function httpClientBuilder) { + return new Config(apiCredentials, SCHEME, HOST, defaultTimeout, httpClientBuilder); } @SuppressWarnings("unused") - public static void setDefaultToken(String defaultToken) { - Config.defaultToken = defaultToken; - } - - @SuppressWarnings("unused") - public static void setDefaultApiKey(String defaultApiKey) { - Config.defaultApiKey = defaultApiKey; + public static void setDefaultApiCredentials(String defaultApiCredentials) { + Config.defaultApiCredentials = defaultApiCredentials; } @SuppressWarnings("unused") @@ -107,16 +68,8 @@ String getHost() { return host; } - String getSecret() { - return secret; - } - - String getToken() { - return token; - } - - String getApiKey() { - return apiKey; + String getApiCredentials() { + return apiCredentials; } Function getHttpClientBuilder() { diff --git a/src/main/java/com/convertapi/client/ConvertApi.java b/src/main/java/com/convertapi/client/ConvertApi.java index f85bc20..f7f5054 100644 --- a/src/main/java/com/convertapi/client/ConvertApi.java +++ b/src/main/java/com/convertapi/client/ConvertApi.java @@ -68,7 +68,7 @@ public static CompletableFuture convert(String fromFormat, Str } } - Request request = Http.getRequestBuilder() + Request request = Http.getRequestBuilder(config) .url(url) .addHeader("Accept", "application/json") .addHeader("Content-Type", "multipart/form-data") @@ -99,7 +99,7 @@ public static User getUser() { public static User getUser(Config config) { HttpUrl url = Http.getUrlBuilder(config).addPathSegment("user").build(); - Request request = Http.getRequestBuilder() + Request request = Http.getRequestBuilder(config) .url(url) .addHeader("Accept", "application/json") .build(); @@ -124,13 +124,8 @@ public static CompletableFuture convertFile(Path fromFile, Str } @SuppressWarnings("unused") - public static CompletableFuture convertFile(Path fromFile, String toFormat, String secret, Param... params) throws IOException { - return convertFile(fromFile, toFormat, Config.defaults(secret), params); - } - - @SuppressWarnings("unused") - public static CompletableFuture convertFile(Path fromFile, String toFormat, String token, String apiKey, Param... params) throws IOException { - return convertFile(fromFile, toFormat, Config.defaults(token, apiKey), params); + public static CompletableFuture convertFile(Path fromFile, String toFormat, String apiCredentials, Param... params) throws IOException { + return convertFile(fromFile, toFormat, Config.defaults(apiCredentials), params); } public static CompletableFuture convertFile(Path fromFile, String toFormat, Config config, Param... params) throws IOException { @@ -144,13 +139,8 @@ public static void convertFile(String fromPathToFile, String toPathToFile) { } @SuppressWarnings("unused") - public static void convertFile(String fromPathToFile, String toPathToFile, String secret) { - convertFile(fromPathToFile, toPathToFile, Config.defaults(secret)); - } - - @SuppressWarnings("unused") - public static void convertFile(String fromPathToFile, String toPathToFile, String token, String apiKey) { - convertFile(fromPathToFile, toPathToFile, Config.defaults(token, apiKey)); + public static void convertFile(String fromPathToFile, String toPathToFile, String apiCredentials) { + convertFile(fromPathToFile, toPathToFile, Config.defaults(apiCredentials)); } public static void convertFile(String fromPathToFile, String toPathToFile, Config config) { @@ -169,13 +159,8 @@ public static List convertFileToDir(String fromPathToFile, String toFormat } @SuppressWarnings("unused") - public static List convertFileToDir(String fromPathToFile, String toFormat, String outputDirectory, String secret, Param... params) { - return convertFileToDir(fromPathToFile, toFormat, outputDirectory, Config.defaults(secret), params); - } - - @SuppressWarnings("unused") - public static List convertFileToDir(String fromPathToFile, String toFormat, String outputDirectory, String token, String apiKey, Param... params) { - return convertFileToDir(fromPathToFile, toFormat, outputDirectory, Config.defaults(token, apiKey), params); + public static List convertFileToDir(String fromPathToFile, String toFormat, String outputDirectory, String apiCredentials, Param... params) { + return convertFileToDir(fromPathToFile, toFormat, outputDirectory, Config.defaults(apiCredentials), params); } public static List convertFileToDir(String fromPathToFile, String toFormat, String outputDirectory, Config config, Param... params) { @@ -194,13 +179,8 @@ public static Path convertUrl(String url, String toPathToFile, Param... params) } @SuppressWarnings("unused") - public static Path convertUrl(String url, String toPathToFile, String secret, Param... params) { - return convertUrl(url, toPathToFile, Config.defaults(secret), params); - } - - @SuppressWarnings("unused") - public static Path convertUrl(String url, String toPathToFile, String token, String apiKey, Param... params) { - return convertUrl(url, toPathToFile, Config.defaults(token, apiKey), params); + public static Path convertUrl(String url, String toPathToFile, String apiCredentials, Param... params) { + return convertUrl(url, toPathToFile, Config.defaults(apiCredentials), params); } public static Path convertUrl(String url, String toPathToFile, Config config, Param... params) { @@ -219,13 +199,8 @@ public static Path convertRemoteFile(String url, String toPathToFile, Param... p } @SuppressWarnings("unused") - public static Path convertRemoteFile(String url, String toPathToFile, String secret, Param... params) { - return convertRemoteFile(url, toPathToFile, Config.defaults(secret), params); - } - - @SuppressWarnings("unused") - public static Path convertRemoteFile(String url, String toPathToFile, String token, String apiKey, Param... params) { - return convertRemoteFile(url, toPathToFile, Config.defaults(token, apiKey), params); + public static Path convertRemoteFile(String url, String toPathToFile, String apiCredentials, Param... params) { + return convertRemoteFile(url, toPathToFile, Config.defaults(apiCredentials), params); } public static Path convertRemoteFile(String url, String toPathToFile, Config config, Param... params) { @@ -245,13 +220,8 @@ public static List convertRemoteFileToDir(String url, String toFormat, Str } @SuppressWarnings("unused") - public static List convertRemoteFileToDir(String url, String toFormat, String outputDirectory, String secret, Param... params) { - return convertRemoteFileToDir(url, toFormat, outputDirectory, Config.defaults(secret), params); - } - - @SuppressWarnings("unused") - public static List convertRemoteFileToDir(String url, String toFormat, String outputDirectory, String token, String apiKey, Param... params) { - return convertRemoteFileToDir(url, toFormat, outputDirectory, Config.defaults(token, apiKey), params); + public static List convertRemoteFileToDir(String url, String toFormat, String outputDirectory, String apiCredentials, Param... params) { + return convertRemoteFileToDir(url, toFormat, outputDirectory, Config.defaults(apiCredentials), params); } public static List convertRemoteFileToDir(String url, String toFormat, String outputDirectory, Config config, Param... params) { diff --git a/src/main/java/com/convertapi/client/Http.java b/src/main/java/com/convertapi/client/Http.java index bca3562..19c8755 100644 --- a/src/main/java/com/convertapi/client/Http.java +++ b/src/main/java/com/convertapi/client/Http.java @@ -3,6 +3,7 @@ import com.convertapi.client.model.RemoteUploadResponse; import com.google.gson.Gson; import okhttp3.*; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.InputStream; @@ -26,17 +27,9 @@ static OkHttpClient getClient(Config config) { } static HttpUrl.Builder getUrlBuilder(Config config) { - HttpUrl.Builder urlBuilder = new HttpUrl.Builder() + return new HttpUrl.Builder() .scheme(config.getScheme()) .host(config.getHost()); - - if (config.getSecret() != null) { - return urlBuilder.addQueryParameter("secret", config.getSecret()); - } else { - return urlBuilder - .addQueryParameter("token", config.getToken()) - .addQueryParameter("apikey", config.getApiKey()); - } } static CompletableFuture requestGet(String url) { @@ -71,8 +64,18 @@ static CompletableFuture requestDelete(String url) { } static Request.Builder getRequestBuilder() { + return getRequestBuilder(null); + } + + static Request.Builder getRequestBuilder(@Nullable Config config) { String agent = String.format("ConvertAPI-Java/%s (%s)", Http.class.getPackage().getImplementationVersion(), System.getProperty("os.name")); - return new Request.Builder().header("User-Agent", agent); + Request.Builder request = new Request.Builder() + .header("User-Agent", agent); + + if (config != null) { + request = request.header("Authorization", "Bearer " + config.getApiCredentials()); + } + return request; } static RemoteUploadResponse remoteUpload(String urlToFile, Config config) { @@ -81,7 +84,7 @@ static RemoteUploadResponse remoteUpload(String urlToFile, Config config) { .addQueryParameter("url", urlToFile) .build(); - Request request = Http.getRequestBuilder() + Request request = Http.getRequestBuilder(config) .url(url) .method("POST", RequestBody.create("", null)) .addHeader("Accept", "application/json") diff --git a/src/main/java/com/convertapi/client/Param.java b/src/main/java/com/convertapi/client/Param.java index 4344729..8a7ee27 100644 --- a/src/main/java/com/convertapi/client/Param.java +++ b/src/main/java/com/convertapi/client/Param.java @@ -105,7 +105,7 @@ public List getValue() throws ExecutionException, InterruptedException { private static CompletableFuture> upload(InputStream stream, String fileName, Config config) { return CompletableFuture.supplyAsync(() -> { - Request request = Http.getRequestBuilder() + Request request = Http.getRequestBuilder(config) .url(Http.getUrlBuilder(config).addPathSegment("upload") .addQueryParameter("filename", fileName) .build()) From f19475a142b47eced7522771d547463870c466c1 Mon Sep 17 00:00:00 2001 From: Krisztian Mozsi Date: Thu, 12 Sep 2024 23:58:20 +0100 Subject: [PATCH 5/7] Remove alternative converter support --- examples/pom.xml | 2 +- .../com/convertapi/examples/Advanced.java | 2 +- .../examples/AlternativeConverter.java | 37 ------------------- .../examples/ConversionChaining.java | 2 +- .../examples/ConvertRemoteFile.java | 2 +- .../convertapi/examples/ConvertStream.java | 2 +- .../convertapi/examples/ConvertWebToPdf.java | 2 +- .../examples/ConvertWordToPdfAndPng.java | 2 +- .../examples/CreatePdfThumbnail.java | 2 +- .../convertapi/examples/SimpleConversion.java | 2 +- .../convertapi/examples/SplitAndMergePdf.java | 2 +- .../examples/TokenAuthentication.java | 24 ------------ .../convertapi/examples/UserInformation.java | 2 +- .../com/convertapi/client/ConvertApi.java | 12 ------ 14 files changed, 11 insertions(+), 84 deletions(-) delete mode 100644 examples/src/main/java/com/convertapi/examples/AlternativeConverter.java delete mode 100644 examples/src/main/java/com/convertapi/examples/TokenAuthentication.java diff --git a/examples/pom.xml b/examples/pom.xml index 2177648..b5401d2 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -15,7 +15,7 @@ com.convertapi.client convertapi - 2.10 + 2.11 diff --git a/examples/src/main/java/com/convertapi/examples/Advanced.java b/examples/src/main/java/com/convertapi/examples/Advanced.java index ce5861d..afeb269 100644 --- a/examples/src/main/java/com/convertapi/examples/Advanced.java +++ b/examples/src/main/java/com/convertapi/examples/Advanced.java @@ -21,7 +21,7 @@ public class Advanced { public static void main(String[] args) throws ExecutionException, InterruptedException { - Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a + Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS")); //Get your api credentials at https://www.convertapi.com/a // Advanced HTTP client setup Config.setDefaultHttpBuilder(builder -> { diff --git a/examples/src/main/java/com/convertapi/examples/AlternativeConverter.java b/examples/src/main/java/com/convertapi/examples/AlternativeConverter.java deleted file mode 100644 index 07bfc3a..0000000 --- a/examples/src/main/java/com/convertapi/examples/AlternativeConverter.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.convertapi.examples; - -import com.convertapi.client.Config; -import com.convertapi.client.ConversionResult; -import com.convertapi.client.ConvertApi; -import com.convertapi.client.Param; - -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -import static java.lang.System.getenv; - -/** - * Example of saving Word docx to PDF using alternative OpenOffice converter - * Conversion is made by using same file parameter and processing two conversions simultaneously - * https://www.convertapi.com/docx-to-pdf - * https://www.convertapi.com/docx-to-png - */ - -public class AlternativeConverter { - - public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { - Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a - Path tempDir = Paths.get(System.getProperty("java.io.tmpdir")); - - System.out.println("Converting DOCX to PDF with OpenOffice converter"); - Param docxFileParam = new Param("file", Paths.get("files/test.docx")); - Param converterParam = new Param("converter", "openoffice"); - - CompletableFuture pdfResult = ConvertApi.convert("docx", "pdf", docxFileParam, converterParam); - - System.out.println("PDF file saved to: " + pdfResult.get().saveFile(tempDir).get()); - } -} \ No newline at end of file diff --git a/examples/src/main/java/com/convertapi/examples/ConversionChaining.java b/examples/src/main/java/com/convertapi/examples/ConversionChaining.java index 33aa2c2..f41e3f4 100644 --- a/examples/src/main/java/com/convertapi/examples/ConversionChaining.java +++ b/examples/src/main/java/com/convertapi/examples/ConversionChaining.java @@ -21,7 +21,7 @@ public class ConversionChaining { public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { - Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a + Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS")); //Get your api credentials at https://www.convertapi.com/a System.out.println("Converting PDF to JPG and compressing result files with ZIP"); CompletableFuture jpgResult = ConvertApi.convert("docx", "jpg", new Param("file", Paths.get("files/test.docx"))); diff --git a/examples/src/main/java/com/convertapi/examples/ConvertRemoteFile.java b/examples/src/main/java/com/convertapi/examples/ConvertRemoteFile.java index ee5b52b..37c2a38 100644 --- a/examples/src/main/java/com/convertapi/examples/ConvertRemoteFile.java +++ b/examples/src/main/java/com/convertapi/examples/ConvertRemoteFile.java @@ -20,7 +20,7 @@ public class ConvertRemoteFile { public static void main(String[] args) throws ExecutionException, InterruptedException { - Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a + Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS")); //Get your api credentials at https://www.convertapi.com/a System.out.println("Converting remote PPTX to PDF"); CompletableFuture result = ConvertApi.convert("pptx", "pdf", diff --git a/examples/src/main/java/com/convertapi/examples/ConvertStream.java b/examples/src/main/java/com/convertapi/examples/ConvertStream.java index 96a32dc..da392bb 100644 --- a/examples/src/main/java/com/convertapi/examples/ConvertStream.java +++ b/examples/src/main/java/com/convertapi/examples/ConvertStream.java @@ -22,7 +22,7 @@ public class ConvertStream { public static void main(String[] args) throws ExecutionException, InterruptedException, IOException { - Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a + Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS")); //Get your api credentials at https://www.convertapi.com/a // Creating file data stream InputStream stream = Files.newInputStream(new File("src/main/resources/test.docx").toPath()); diff --git a/examples/src/main/java/com/convertapi/examples/ConvertWebToPdf.java b/examples/src/main/java/com/convertapi/examples/ConvertWebToPdf.java index 681c941..ad35ca1 100644 --- a/examples/src/main/java/com/convertapi/examples/ConvertWebToPdf.java +++ b/examples/src/main/java/com/convertapi/examples/ConvertWebToPdf.java @@ -20,7 +20,7 @@ public class ConvertWebToPdf { public static void main(String[] args) throws ExecutionException, InterruptedException { - Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a + Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS")); //Get your api credentials at https://www.convertapi.com/a System.out.println("Converting WEB to PDF"); CompletableFuture result = ConvertApi.convert("web", "pdf", diff --git a/examples/src/main/java/com/convertapi/examples/ConvertWordToPdfAndPng.java b/examples/src/main/java/com/convertapi/examples/ConvertWordToPdfAndPng.java index c49f7ab..f7c8f14 100644 --- a/examples/src/main/java/com/convertapi/examples/ConvertWordToPdfAndPng.java +++ b/examples/src/main/java/com/convertapi/examples/ConvertWordToPdfAndPng.java @@ -23,7 +23,7 @@ public class ConvertWordToPdfAndPng { public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { - Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a + Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS")); //Get your api credentials at https://www.convertapi.com/a Path tempDir = Paths.get(System.getProperty("java.io.tmpdir")); System.out.println("Converting DOCX to PDF and JPG in parallel"); diff --git a/examples/src/main/java/com/convertapi/examples/CreatePdfThumbnail.java b/examples/src/main/java/com/convertapi/examples/CreatePdfThumbnail.java index c5faeef..ddca452 100644 --- a/examples/src/main/java/com/convertapi/examples/CreatePdfThumbnail.java +++ b/examples/src/main/java/com/convertapi/examples/CreatePdfThumbnail.java @@ -21,7 +21,7 @@ public class CreatePdfThumbnail { public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { - Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a + Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS")); //Get your api credentials at https://www.convertapi.com/a Path tempDir = Paths.get(System.getProperty("java.io.tmpdir")); System.out.println("Creating PDF thumbnail"); diff --git a/examples/src/main/java/com/convertapi/examples/SimpleConversion.java b/examples/src/main/java/com/convertapi/examples/SimpleConversion.java index 8a378ac..97b290d 100644 --- a/examples/src/main/java/com/convertapi/examples/SimpleConversion.java +++ b/examples/src/main/java/com/convertapi/examples/SimpleConversion.java @@ -11,7 +11,7 @@ public class SimpleConversion { public static void main(String[] args) { - Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a + Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS")); //Get your api credentials at https://www.convertapi.com/a String resourcePath = "files/test.docx"; String tmpDir = System.getProperty("java.io.tmpdir") + "/"; diff --git a/examples/src/main/java/com/convertapi/examples/SplitAndMergePdf.java b/examples/src/main/java/com/convertapi/examples/SplitAndMergePdf.java index 716fa66..22d0498 100644 --- a/examples/src/main/java/com/convertapi/examples/SplitAndMergePdf.java +++ b/examples/src/main/java/com/convertapi/examples/SplitAndMergePdf.java @@ -21,7 +21,7 @@ public class SplitAndMergePdf { public static void main(String[] args) throws IOException, ExecutionException, InterruptedException { - Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a + Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS")); //Get your api credentials at https://www.convertapi.com/a Path tempDir = Paths.get(System.getProperty("java.io.tmpdir")); System.out.println("Creating PDF with the first and the last pages"); diff --git a/examples/src/main/java/com/convertapi/examples/TokenAuthentication.java b/examples/src/main/java/com/convertapi/examples/TokenAuthentication.java deleted file mode 100644 index 994e238..0000000 --- a/examples/src/main/java/com/convertapi/examples/TokenAuthentication.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.convertapi.examples; - -import com.convertapi.client.Config; -import com.convertapi.client.ConvertApi; - -import static java.lang.System.getenv; - -/** - * Most simple conversion example with token authentication - */ -public class TokenAuthentication { - - public static void main(String[] args) { - Config.setDefaultToken(getenv("CONVERTAPI_TOKEN")); // Generate your token: https://www.convertapi.com/doc/auth - Config.setDefaultApiKey(getenv("CONVERTAPI_APIKEY")); // Get your api key: https://www.convertapi.com/a - String resourcePath = "files/test.docx"; - String tmpDir = System.getProperty("java.io.tmpdir") + "/"; - - // Simplified file to file conversion example - ConvertApi.convertFile(resourcePath, tmpDir + "/result.pdf"); - - System.out.println("PDF file saved to: " + tmpDir + "result.pdf"); - } -} diff --git a/examples/src/main/java/com/convertapi/examples/UserInformation.java b/examples/src/main/java/com/convertapi/examples/UserInformation.java index 80095fd..c09a38e 100644 --- a/examples/src/main/java/com/convertapi/examples/UserInformation.java +++ b/examples/src/main/java/com/convertapi/examples/UserInformation.java @@ -13,7 +13,7 @@ public class UserInformation { public static void main(String[] args) { - Config.setDefaultSecret(getenv("CONVERTAPI_SECRET")); //Get your secret at https://www.convertapi.com/a + Config.setDefaultApiCredentials(getenv("CONVERTAPI_CREDENTIALS")); //Get your api credentials at https://www.convertapi.com/a User user = ConvertApi.getUser(); System.out.println("API Key: " + user.ApiKey); diff --git a/src/main/java/com/convertapi/client/ConvertApi.java b/src/main/java/com/convertapi/client/ConvertApi.java index f7f5054..a1e558b 100644 --- a/src/main/java/com/convertapi/client/ConvertApi.java +++ b/src/main/java/com/convertapi/client/ConvertApi.java @@ -38,18 +38,6 @@ public static CompletableFuture convert(String fromFormat, Str .addPathSegment("to") .addPathSegment(toFormat); - for (Param param : params) { - if (param.getName().equalsIgnoreCase("converter")) { - try { - urlBuilder = urlBuilder - .addPathSegment("converter") - .addPathSegment(param.getValue().get(0)); - } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(e); - } - } - } - HttpUrl url = urlBuilder.addQueryParameter("storefile", "true").build(); MultipartBody.Builder multipartBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM); From 0da940fd939c848f4934a0851c00065c71c587f4 Mon Sep 17 00:00:00 2001 From: Krisztian Mozsi Date: Fri, 13 Sep 2024 00:10:25 +0100 Subject: [PATCH 6/7] Update readme --- README.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 77a5fe0..2c1eae4 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ And many others files manipulations. In just few minutes you can integrate it into your application and use it easily. The ConvertAPI-Java library makes it easier to use the Convert API from your Java 8 projects without having to build your own API calls. -You can get your free API secret at https://www.convertapi.com/a +You can get your free API credentials at https://www.convertapi.com/a ## Installation @@ -19,7 +19,7 @@ Add the following dependency to your pom.xml: com.convertapi.client convertapi - 2.10 + 2.11 ``` @@ -27,13 +27,10 @@ Add the following dependency to your pom.xml: ### Configuration -You can get your secret at https://www.convertapi.com/a +You can get your credentials at https://www.convertapi.com/a ```java -Config.setDefaultSecret("your-api-secret"); -// or token authentication -Config.setDefaultToken("your-token"); -Config.setDefaultApiKey("your-api-key"); +Config.setDefaultApiCredentials("your-api-secret"); ``` ### File conversion @@ -98,7 +95,7 @@ int conversionsConsumed = user.ConversionsConsumed; Create `Config` instance with the alternative domain and provide it in `convert` method. Dedicated to the region [domain list](https://www.convertapi.com/doc/servers-location). ```java -Config config = new Config(secret, "https", "eu-v2.convertapi.com", 0, httpClientBuilder); +Config config = new Config(credentials, "https", "eu-v2.convertapi.com", 0, httpClientBuilder); ``` ### More examples @@ -114,13 +111,13 @@ import com.convertapi.ConvertApi; public class SimpleConversion { public static void main(String[] args) { - ConvertApi.convert("source.docx", "result.pdf", "your-api-secret"); + ConvertApi.convert("source.docx", "result.pdf", "your-api-credentials"); } } ``` This is the bare-minimum to convert a file using the ConvertAPI client, but you can do a great deal more with the ConvertAPI Java library. -Take special note that you should replace `your-api-secret` with the secret you obtained in item two of the pre-requisites. +Take special note that you should replace `your-api-credentials` with the secret you obtained in item two of the pre-requisites. ### Issues & Comments Please leave all comments, bugs, requests, and issues on the Issues page. We'll respond to your request ASAP! From c3ecf997df98294e5009742f2e9c1db0816fde1e Mon Sep 17 00:00:00 2001 From: Krisztian Mozsi Date: Fri, 13 Sep 2024 00:58:23 +0100 Subject: [PATCH 7/7] [maven-release-plugin] prepare release v2.11 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index cd8e03c..b017070 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ convertapi jar - 2.11-SNAPSHOT + 2.11 ConvertAPI Java Client The ConvertAPI helps converting various file formats. @@ -48,7 +48,7 @@ scm:git:git://github.com/ConvertAPI/convertapi-java.git scm:git:git@github.com:ConvertAPI/convertapi-java.git https://github.com/ConvertAPI/convertapi-java - HEAD + v2.11