-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathTinify.java
More file actions
87 lines (72 loc) · 2.08 KB
/
Copy pathTinify.java
File metadata and controls
87 lines (72 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.tinify;
import java.io.IOException;
import java.net.URL;
public class Tinify {
private static String key;
private static String appIdentifier;
private static String proxy;
private static int compressionCount = 0;
private static Client client;
public static Client client() {
if (key == null) {
throw new AccountException("Provide an API key with Tinify.setKey(...)");
}
if (client != null) {
return client;
} else {
synchronized (Tinify.class) {
if (client == null) {
client = new Client(key, appIdentifier, proxy);
}
}
return client;
}
}
public static void setKey(final String key) {
Tinify.key = key;
client = null;
}
public static void setProxy(final String proxy) {
Tinify.proxy = proxy;
client = null;
}
public static void setAppIdentifier(final String identifier) {
Tinify.appIdentifier = identifier;
client = null;
}
public static Source fromFile(final String path) throws IOException {
return Source.fromFile(path);
}
public static Source fromBuffer(final byte[] buffer) {
return Source.fromBuffer(buffer);
}
public static Source fromUrl(final String url) {
return Source.fromUrl(url);
}
public static boolean validate() {
try {
client().request(Client.Method.POST, "/shrink");
} catch (AccountException ex) {
if (ex.status == 429) return true;
throw ex;
} catch (ClientException ex) {
return true;
}
return false;
}
public static String key() {
return key;
}
public static String proxy() {
return proxy;
}
public static String appIdentifier() {
return appIdentifier;
}
public static void setCompressionCount(final int count) {
compressionCount = count;
}
public static int compressionCount() {
return compressionCount;
}
}