From f19475a142b47eced7522771d547463870c466c1 Mon Sep 17 00:00:00 2001 From: Krisztian Mozsi Date: Thu, 12 Sep 2024 23:58:20 +0100 Subject: [PATCH 1/2] 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 2/2] 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!