-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxyExample.java
More file actions
49 lines (43 loc) · 1.76 KB
/
Copy pathProxyExample.java
File metadata and controls
49 lines (43 loc) · 1.76 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
package com.novada.examples.proxy;
import com.novada.NovadaClient;
import com.novada.exception.ApiException;
import com.novada.exception.AuthException;
import com.novada.exception.RateLimitException;
import com.novada.exception.ValidationException;
import com.novada.proxy.Product;
import com.novada.proxy.model.AddWhitelistParams;
import com.novada.proxy.model.ListWhitelistParams;
import com.novada.proxy.model.WhitelistList;
/**
* Runnable proxy example. Reads the API key from the {@code NOVADA_API_KEY} environment variable.
*
* <pre>{@code
* mvn -q compile
* javac -cp target/classes -d target/examples examples/proxy/ProxyExample.java
* java -cp target/classes:target/examples com.novada.examples.proxy.ProxyExample
* }</pre>
*/
public final class ProxyExample {
private ProxyExample() {}
public static void main(String[] args) {
NovadaClient client = NovadaClient.of(""); // "" falls back to NOVADA_API_KEY
try {
client
.proxy()
.whitelist()
.add(new AddWhitelistParams(Product.RESIDENTIAL, "10.10.10.1", "example"));
WhitelistList list =
client.proxy().whitelist().list(ListWhitelistParams.builder(Product.RESIDENTIAL).build());
System.out.printf("whitelist total=%d%n", list.total());
list.list().forEach(ip -> System.out.println(" " + ip.markIp() + " (id=" + ip.id() + ")"));
} catch (ValidationException e) {
System.err.println(e.method() + ": missing required field(s): " + e.fields());
} catch (AuthException e) {
System.err.println("invalid API key");
} catch (RateLimitException e) {
System.err.println("rate limited, try again later");
} catch (ApiException e) {
System.err.println("business error code=" + e.code() + ": " + e.getMessage());
}
}
}