From d4ea74c238617d24f9c5242d8b52068c505a65c6 Mon Sep 17 00:00:00 2001 From: "Jose M. Palomar" Date: Tue, 22 Jun 2021 15:46:24 +0200 Subject: [PATCH 1/9] Change to close Response instances --- src/main/java/com/convertapi/client/ConvertApi.java | 8 +++----- src/main/java/com/convertapi/client/Http.java | 6 ++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/convertapi/client/ConvertApi.java b/src/main/java/com/convertapi/client/ConvertApi.java index 98dbcd3..c26c5c7 100644 --- a/src/main/java/com/convertapi/client/ConvertApi.java +++ b/src/main/java/com/convertapi/client/ConvertApi.java @@ -40,7 +40,7 @@ public static CompletableFuture convert(String fromFormat, Str .addPathSegment(toFormat); for (Param param : params) { - if (param.getName().toLowerCase().equals("converter")) { + if (param.getName().equalsIgnoreCase("converter")) { try { urlBuilder = urlBuilder .addPathSegment("converter") @@ -77,8 +77,7 @@ public static CompletableFuture convert(String fromFormat, Str .build(); String bodyString; - try { - Response response = Http.getClient(config).newCall(request).execute(); + try (Response response = Http.getClient(config).newCall(request).execute()) { //noinspection ConstantConditions bodyString = response.body().string(); if (response.code() != 200) { @@ -107,8 +106,7 @@ public static User getUser(Config config) { .build(); String bodyString; - try { - Response response = Http.getClient().newCall(request).execute(); + try (Response response = Http.getClient().newCall(request).execute()) { //noinspection ConstantConditions bodyString = response.body().string(); if (response.code() != 200) { diff --git a/src/main/java/com/convertapi/client/Http.java b/src/main/java/com/convertapi/client/Http.java index e8a9635..38c7aca 100644 --- a/src/main/java/com/convertapi/client/Http.java +++ b/src/main/java/com/convertapi/client/Http.java @@ -49,8 +49,7 @@ static CompletableFuture requestGet(String url) { static CompletableFuture requestDelete(String url) { return CompletableFuture.supplyAsync(() -> { Request request = getRequestBuilder().delete().url(url).build(); - try { - getClient().newCall(request).execute(); + try (Response response = getClient().newCall(request).execute()) { } catch (IOException e) { throw new RuntimeException(e); } @@ -76,8 +75,7 @@ static RemoteUploadResponse remoteUpload(String urlToFile, Config config) { .build(); String bodyString; - try { - Response response = Http.getClient().newCall(request).execute(); + try (Response response = Http.getClient().newCall(request).execute()) { //noinspection ConstantConditions bodyString = response.body().string(); if (response.code() != 200) { From aaae1810795635cf182733eb3fb7374b140c0f63 Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 29 Nov 2022 01:57:11 +0000 Subject: [PATCH 2/9] [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 e5c02e1..9e1c844 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ convertapi jar - 2.9 + 2.10-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.9 + HEAD From dac4743248ebd65e1fc34ab4476fe803fd3ef1be Mon Sep 17 00:00:00 2001 From: Krisztian Mozsi Date: Tue, 29 Nov 2022 12:53:59 +0000 Subject: [PATCH 3/9] Increment version --- README.md | 2 +- examples/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3c3466d..322012e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Add the following dependency to your pom.xml: com.convertapi.client convertapi - 2.8 + 2.9 ``` diff --git a/examples/pom.xml b/examples/pom.xml index 142c235..1880299 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -15,7 +15,7 @@ com.convertapi.client convertapi - 2.8 + 2.9 From efba7c9b29bbb0adc4b3235ab61b8dd884810f55 Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Thu, 25 May 2023 09:32:27 +0300 Subject: [PATCH 4/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 322012e..8848355 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ CompletableFuture result = ConvertApi.convert("pptx", "pdf", #### Additional conversion parameters ConvertAPI accepts extra conversion parameters depending on converted formats. All conversion -parameters and explanations can be found [here](https://www.convertapi.com). +parameters and explanations can be found [here](https://www.convertapi.com/conversions). ```java CompletableFuture result = ConvertApi.convert("pdf", "jpg", From c1ca5e552150c5ae17dedc14f41867ca4a4adbf0 Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Tue, 4 Jul 2023 14:51:20 +0300 Subject: [PATCH 5/9] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 8848355..9117312 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,14 @@ User user = ConvertApi.getUser(); int secondsLeft = user.SecondsLeft; ``` +### Alternative domain + +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); +``` + ### More examples You can find more advanced examples in the [examples](https://github.com/ConvertAPI/convertapi-java/tree/master/examples/src/main/java/com/convertapi/examples) folder. From 4582c38034daa2756d5ae5d6d3b1ca99cb672da5 Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Tue, 22 Aug 2023 14:48:32 +0300 Subject: [PATCH 6/9] Delete GETTING-STARTED.md --- GETTING-STARTED.md | 161 --------------------------------------------- 1 file changed, 161 deletions(-) delete mode 100644 GETTING-STARTED.md diff --git a/GETTING-STARTED.md b/GETTING-STARTED.md deleted file mode 100644 index 1bb8945..0000000 --- a/GETTING-STARTED.md +++ /dev/null @@ -1,161 +0,0 @@ -#### 1. Install the ConvertAPI library - -Go to the [ConvertAPI Java client](https://github.com/ConvertAPI/convertapi-java) page and download the JAR file. -Place JAR into your project library directory. - -The library is also available in Maven. -Add the following dependency to your pom.xml: -```xml - - com.convertapi.client - convertapi - 2.2 - -``` - -#### 2.a. Simple conversion methods - -```java -import com.convertapi.*; - -Config.setDefaultSecret("your-api-secret"); - -// Simplified file to file conversion example -ConvertApi.convertFile("test.docx", "/tmp/result.pdf"); - -// Simplified web site to pdf conversion example -ConvertApi.convertUrl("http://example.com", "/tmp/example.pdf"); - -// Simplified remote file to local file conversion example -ConvertApi.convertRemoteFile("https://cdn.convertapi.com/cara/testfiles/document.docx", "/tmp/demo.pdf"); -``` - - -#### 2.b. Convert a local file - -```java -import com.convertapi.*; - -Config.setDefaultSecret("your-api-secret"); - -//Set input and output formats and pass file parameter. -//Word to PDF API. Read more https://www.convertapi.com/docx-to-pdf -ConvertApi.convert("docx", "pdf", - new Param("file", Paths.get("test.docx")) -).get().saveFile(Paths.get("/tmp")).get(); -``` - - -#### 2.c. Convert a remote file and set additional parameters - -```java -import com.convertapi.*; - -Config.setDefaultSecret("your-api-secret"); - -//Set input and output formats and pass file parameter. -//PowerPoint to PNG API. Read more https://www.convertapi.com/pptx-to-png -ConvertApi.convert("pdf", "png", - new Param("file", "https://cdn.convertapi.com/cara/testfiles/presentation.pptx"), - new Param("scaleimage", "true"), - new Param("scaleproportions", "true"), - new Param("imageheight", 300) -).get().saveFile(Paths.get("/tmp")).get(); -``` - - -#### 2.d. Convert from a stream - -```java -import com.convertapi.*; - -Config.setDefaultSecret("your-api-secret"); - -// Create stream from HTML string -String streamContent = "

My First Heading

My first paragraph.

"; -InputStream stream = new ByteArrayInputStream(streamContent.getBytes()); - -// Html to PDF API. Read more https://www.convertapi.com/html-to-pdf -CompletableFuture result = ConvertApi.convert("html", "pdf", - new Param("file", stream, "test.html") -); - -// PDF as stream -InputStream resultStream = result.get().asStream().get(); -``` - - -#### 2.e. Conversions chaining - -```java -// Split PDF document and merge first and last pages to new PDF -import com.convertapi.*; - -Config.setDefaultSecret("your-api-secret"); - -// Set input and output formats and pass file parameter. -// Split PDF API. Read more https://www.convertapi.com/pdf-to-split -CompletableFuture splitResult = ConvertApi.convert("pdf", "split", - new Param("file", Paths.get("test.pdf")) -); - -// Get result of the first conversion and use it in Merge conversion. -// Chains are executed on server without moving files. -// Merge PDF API. Read more https://www.convertapi.com/pdf-to-merge -CompletableFuture mergeResult = ConvertApi.convert("pdf", "merge", - new Param("files", splitResult, 0), - new Param("files", splitResult, -1) -); - -mergeResult.get().saveFile(Paths.get("/tmp")).get(); -``` - - -#### 3. Read account status - -```java -import com.convertapi.*; -import com.convertapi.model.*; - -Config.setDefaultSecret("your-api-secret"); - -// Read full account data -User user = ConvertApi.getUser(); - -// Find out how much seconds left -int secondsLeft = user.SecondsLeft; -``` - - -#### 4. Exception handling (asynchronous) - -```java -import com.convertapi.*; - -Config.setDefaultSecret("your-api-secret"); - -// Creating an exception -CompletableFuture resultFuture = ConvertApi.convert("pdf", "pptx", - new Param("file", Paths.get("test-files/test.pdf")), - new Param("AutoRotate","WrongParameter") -).exceptionally(t -> { - // Handling and exception - System.out.println("Error message: " + t.getMessage()); - return null; -}); - -ConversionResult result = resultFuture.get(); -// Saving file if there was no exception -if (result != null) { - result.saveFile(Paths.get("/tmp")).get(); -} -``` - - -#### 5. Supported file formats, conversions and actions - -https://www.convertapi.com/doc/supported-formats - -#### 6. GitHub - -https://github.com/ConvertAPI/convertapi-java From 4717fe9c78d0610b5c7a915b57ad158fe5b41650 Mon Sep 17 00:00:00 2001 From: Krisztian Mozsi Date: Tue, 30 Jan 2024 00:52:44 +0000 Subject: [PATCH 7/9] Remove seconds left property --- README.md | 5 +++-- .../main/java/com/convertapi/examples/UserInformation.java | 3 ++- src/main/java/com/convertapi/client/model/User.java | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9117312..feb2fe4 100644 --- a/README.md +++ b/README.md @@ -82,11 +82,12 @@ CompletableFuture result = ConvertApi.convert("pdf", "jpg", ### User information -You can always check remaining seconds amount by fetching [user information](https://www.convertapi.com/doc/user). +You can always check the remaining conversions amount and other account information by fetching [user information](https://www.convertapi.com/doc/user). ```java User user = ConvertApi.getUser(); -int secondsLeft = user.SecondsLeft; +int conversionsTotal = user.ConversionsTotal; +int conversionsConsumed = user.ConversionsConsumed; ``` ### Alternative domain diff --git a/examples/src/main/java/com/convertapi/examples/UserInformation.java b/examples/src/main/java/com/convertapi/examples/UserInformation.java index 96a0568..80095fd 100644 --- a/examples/src/main/java/com/convertapi/examples/UserInformation.java +++ b/examples/src/main/java/com/convertapi/examples/UserInformation.java @@ -22,6 +22,7 @@ public static void main(String[] args) { System.out.println("Name: " + user.FullName); System.out.println("Status: " + user.Status); System.out.println("Active: " + user.Active); - System.out.println("Seconds left: " + user.SecondsLeft); + System.out.println("Total Conversions: " + user.ConversionsTotal); + System.out.println("Conversions Consumed: " + user.ConversionsConsumed); } } diff --git a/src/main/java/com/convertapi/client/model/User.java b/src/main/java/com/convertapi/client/model/User.java index 9c385d3..ae8bb46 100644 --- a/src/main/java/com/convertapi/client/model/User.java +++ b/src/main/java/com/convertapi/client/model/User.java @@ -8,6 +8,7 @@ public class User { public boolean Active; public String FullName; public String Email; - public int SecondsLeft; + public int ConversionsTotal; + public int ConversionsConsumed; public String Status; } From a50afdea1f04baca000588d61b53ccced98313d1 Mon Sep 17 00:00:00 2001 From: Krisztian Mozsi Date: Thu, 1 Feb 2024 23:59:26 +0000 Subject: [PATCH 8/9] Set content-type --- src/main/java/com/convertapi/client/ConvertApi.java | 1 + src/main/java/com/convertapi/client/Http.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/convertapi/client/ConvertApi.java b/src/main/java/com/convertapi/client/ConvertApi.java index 2393292..f85bc20 100644 --- a/src/main/java/com/convertapi/client/ConvertApi.java +++ b/src/main/java/com/convertapi/client/ConvertApi.java @@ -71,6 +71,7 @@ public static CompletableFuture convert(String fromFormat, Str Request request = Http.getRequestBuilder() .url(url) .addHeader("Accept", "application/json") + .addHeader("Content-Type", "multipart/form-data") .post(multipartBuilder.build()) .build(); diff --git a/src/main/java/com/convertapi/client/Http.java b/src/main/java/com/convertapi/client/Http.java index 1d86a34..bca3562 100644 --- a/src/main/java/com/convertapi/client/Http.java +++ b/src/main/java/com/convertapi/client/Http.java @@ -66,6 +66,7 @@ static CompletableFuture requestDelete(String url) { } catch (IOException e) { throw new RuntimeException(e); } + return null; }); } From b48cf56c7d4aca83a5148736f66cd40df8deaf47 Mon Sep 17 00:00:00 2001 From: Krisztian Mozsi Date: Fri, 16 Feb 2024 00:25:01 +0000 Subject: [PATCH 9/9] [maven-release-plugin] prepare release v2.10 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9e1c844..e037ae0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ convertapi jar - 2.10-SNAPSHOT + 2.10 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.10