Skip to content

Commit 8d35a29

Browse files
authored
Merge pull request #18 from ConvertAPI/fix/user-agent-header
Fix error with convertapi version in user agent header
2 parents 57e5bc5 + 3e89fb6 commit 8d35a29

14 files changed

+38
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Add the following dependency to your pom.xml:
1919
<dependency>
2020
<groupId>com.convertapi.client</groupId>
2121
<artifactId>convertapi</artifactId>
22-
<version>2.4</version>
22+
<version>2.5</version>
2323
</dependency>
2424
```
2525

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<artifactId>convertapi</artifactId>
55
<packaging>jar</packaging>
66

7-
<version>2.5-SNAPSHOT </version>
7+
<version>2.5-SNAPSHOT</version>
88
<name>ConvertAPI Java Client</name>
99
<description>
1010
The ConvertAPI helps converting various file formats.

src/main/java/com/convertapi/client/Config.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.function.Function;
66

77
public class Config {
8+
89
private static String defaultSecret;
910
private static int defaultTimeout = 0; // Infinite read waiting
1011
private static Function<OkHttpClient.Builder, OkHttpClient.Builder> defaultHttpClientBuilder = b -> b;
@@ -75,4 +76,4 @@ String getSecret() {
7576
Function<OkHttpClient.Builder, OkHttpClient.Builder> getHttpClientBuilder() {
7677
return httpClientBuilder;
7778
}
78-
}
79+
}

src/main/java/com/convertapi/client/ConversionException.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.convertapi.client;
22

33
public class ConversionException extends RuntimeException {
4+
45
private final int httpStatusCode;
56

67
public ConversionException(String message, int httpStatusCode) {
@@ -11,4 +12,4 @@ public ConversionException(String message, int httpStatusCode) {
1112
public int getHttpStatusCode() {
1213
return httpStatusCode;
1314
}
14-
}
15+
}

src/main/java/com/convertapi/client/ConversionResult.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
@SuppressWarnings("WeakerAccess")
1616
public class ConversionResult {
17+
1718
private final ConversionResponse response;
1819

1920
@SuppressWarnings("unused")
@@ -27,8 +28,11 @@ public Integer fileCount() {
2728
}
2829

2930
public List<String> urls() {
30-
@SuppressWarnings("unchecked") List<String> valueList = new ArrayList();
31-
for (ConversionResponseFile file : response.Files) valueList.add(file.Url);
31+
@SuppressWarnings("unchecked")
32+
List<String> valueList = new ArrayList();
33+
for (ConversionResponseFile file : response.Files) {
34+
valueList.add(file.Url);
35+
}
3236
return valueList;
3337
}
3438

@@ -38,7 +42,9 @@ public Integer conversionCost() {
3842
}
3943

4044
public ConversionResultFile getFile(int index) {
41-
if (index < 0) index = response.Files.length + index;
45+
if (index < 0) {
46+
index = response.Files.length + index;
47+
}
4248
return new ConversionResultFile(response.Files[index]);
4349
}
4450

@@ -52,8 +58,9 @@ public CompletableFuture<Path> saveFile(Path file) {
5258

5359
@SuppressWarnings("WeakerAccess")
5460
public List<CompletableFuture<Path>> saveFiles(Path directory) {
55-
if (!Files.isDirectory(directory))
61+
if (!Files.isDirectory(directory)) {
5662
throw new RuntimeException("Directory expected, but received: " + directory.toString());
63+
}
5764
List<CompletableFuture<Path>> paths = new ArrayList<>();
5865
for (int i = 0; i < response.Files.length; i++) {
5966
paths.add(getFile(i).saveFile(directory));
@@ -92,4 +99,4 @@ public void deleteSync() {
9299
}
93100
});
94101
}
95-
}
102+
}

src/main/java/com/convertapi/client/ConversionResultFile.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.concurrent.CompletableFuture;
1212

1313
public class ConversionResultFile {
14+
1415
private final ConversionResponseFile conversionResponseFile;
1516

1617
public ConversionResultFile(ConversionResponseFile conversionResponseFile) {
@@ -53,4 +54,4 @@ public CompletableFuture<Path> saveFile(Path path) {
5354
public CompletableFuture delete() {
5455
return Http.requestDelete(getUrl());
5556
}
56-
}
57+
}

src/main/java/com/convertapi/client/ConvertApi.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
@SuppressWarnings("WeakerAccess")
2323
public class ConvertApi {
24+
2425
@SuppressWarnings("SpellCheckingInspection")
2526
private static final List<String> IGNORE_PARAMS = Arrays.asList("storefile", "async", "jobid");
2627

@@ -39,7 +40,7 @@ public static CompletableFuture<ConversionResult> convert(String fromFormat, Str
3940
.addPathSegment(toFormat);
4041

4142
for (Param param : params) {
42-
if (param.getName() == "converter") {
43+
if (param.getName().equals("converter")) {
4344
try {
4445
urlBuilder = urlBuilder
4546
.addPathSegment("converter")
@@ -183,7 +184,7 @@ public static Path convertRemoteFile(String url, String toPathToFile, String sec
183184
try {
184185
Path toPath = Paths.get(toPathToFile);
185186
return convert(response.FileExt, getFileExtension(toPath), new Param[]{
186-
new Param("file", response.FileId)
187+
new Param("file", response.FileId)
187188
}, Config.defaults(secret)).get().saveFile(toPath).get();
188189
} catch (ExecutionException | InterruptedException e) {
189190
throw new RuntimeException(e);
@@ -224,4 +225,4 @@ private static HashMap<String, List<String>> getParamValues(Param[] params) {
224225

225226
return result;
226227
}
227-
}
228+
}

src/main/java/com/convertapi/client/Http.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.concurrent.TimeUnit;
1111

1212
class Http {
13+
1314
private static final OkHttpClient client = new OkHttpClient();
1415

1516
static OkHttpClient getClient() {
@@ -58,7 +59,7 @@ static CompletableFuture<Void> requestDelete(String url) {
5859
}
5960

6061
static Request.Builder getRequestBuilder() {
61-
String agent = String.format("ConvertAPI-Java/%.1f (%s)", Http.class.getPackage().getImplementationVersion(), System.getProperty("os.name"));
62+
String agent = String.format("ConvertAPI-Java/%s (%s)", Http.class.getPackage().getImplementationVersion(), System.getProperty("os.name"));
6263
return new Request.Builder().header("User-Agent", agent);
6364
}
6465

src/main/java/com/convertapi/client/Param.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
@SuppressWarnings("WeakerAccess")
2020
public class Param {
21+
2122
private final String name;
2223
private CompletableFuture<List<String>> value;
2324
private boolean isUploadedFile = false;
@@ -130,4 +131,4 @@ public static Param[] concat(Param[] a, Param[] b) {
130131
System.arraycopy(b, 0, result, a.length, b.length);
131132
return result;
132133
}
133-
}
134+
}

src/main/java/com/convertapi/client/RequestBodyStream.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.io.InputStream;
1212

1313
class RequestBodyStream {
14+
1415
static RequestBody create(final MediaType mediaType, final InputStream inputStream) {
1516
return new RequestBody() {
1617
@Override
@@ -39,4 +40,4 @@ public void writeTo(BufferedSink sink) throws IOException {
3940
}
4041
};
4142
}
42-
}
43+
}

0 commit comments

Comments
 (0)