|
1 | 1 | package io.ipgeolocation.api; |
2 | 2 |
|
3 | | -import java.util.Map; |
| 3 | +import java.util.Objects; |
| 4 | +import org.json.JSONObject; |
4 | 5 |
|
5 | 6 | public class GeolocationSecurity { |
6 | | - private final Integer threatScore; |
7 | | - private final Boolean isTor; |
8 | | - private final Boolean isProxy; |
9 | | - private final String proxyType; |
10 | | - private final Boolean isAnonymous; |
11 | | - private final Boolean isKnownAttacker; |
12 | | - private final Boolean isBot; |
13 | | - private final Boolean isSpam; |
14 | | - private final Boolean isCloudProvider; |
| 7 | + private final int threatScore; |
| 8 | + private final boolean tor; |
| 9 | + private final boolean proxy; |
| 10 | + private final String proxyType; |
| 11 | + private final boolean anonymous; |
| 12 | + private final boolean knownAttacker; |
| 13 | + private final boolean bot; |
| 14 | + private final boolean spam; |
| 15 | + private final boolean cloudProvider; |
| 16 | + private final JSONObject json; |
15 | 17 |
|
16 | | - GeolocationSecurity(Map<String, Object> json) { |
17 | | - this.threatScore = (Integer) json.get("threat_score"); |
18 | | - this.isTor = (Boolean) json.get("is_tor"); |
19 | | - this.isProxy = (Boolean) json.get("is_proxy"); |
20 | | - this.proxyType = (String) json.get("proxy_type"); |
21 | | - this.isAnonymous = (Boolean) json.get("is_anonymous"); |
22 | | - this.isKnownAttacker = (Boolean) json.get("is_known_attacker"); |
23 | | - this.isBot = (Boolean) json.get("is_bot"); |
24 | | - this.isSpam = (Boolean) json.get("is_spam"); |
25 | | - this.isCloudProvider = (Boolean) json.get("is_cloud_provider"); |
| 18 | + GeolocationSecurity(JSONObject json) { |
| 19 | + if (Objects.isNull(json)) { |
| 20 | + throw new IllegalArgumentException("'json' must not be null"); |
26 | 21 | } |
27 | 22 |
|
28 | | - public Integer getThreatScore() { |
29 | | - return threatScore; |
| 23 | + if (json.isEmpty()) { |
| 24 | + throw new IllegalArgumentException("'json' must not be empty"); |
30 | 25 | } |
31 | 26 |
|
32 | | - public Boolean isTor() { |
33 | | - return isTor; |
34 | | - } |
| 27 | + this.threatScore = json.getInt("threat_score"); |
| 28 | + this.tor = json.getBoolean("is_tor"); |
| 29 | + this.proxy = json.getBoolean("is_proxy"); |
| 30 | + this.proxyType = json.getString("proxy_type"); |
| 31 | + this.anonymous = json.getBoolean("is_anonymous"); |
| 32 | + this.knownAttacker = json.getBoolean("is_known_attacker"); |
| 33 | + this.bot = json.getBoolean("is_bot"); |
| 34 | + this.spam = json.getBoolean("is_spam"); |
| 35 | + this.cloudProvider = json.getBoolean("is_cloud_provider"); |
| 36 | + this.json = json; |
| 37 | + } |
35 | 38 |
|
36 | | - public Boolean isProxy() { |
37 | | - return isProxy; |
38 | | - } |
| 39 | + public int getThreatScore() { |
| 40 | + return threatScore; |
| 41 | + } |
39 | 42 |
|
40 | | - public String getProxyType() { |
41 | | - return proxyType; |
42 | | - } |
| 43 | + public boolean isTor() { |
| 44 | + return tor; |
| 45 | + } |
43 | 46 |
|
44 | | - public Boolean isAnonymous() { |
45 | | - return isAnonymous; |
46 | | - } |
| 47 | + public boolean isProxy() { |
| 48 | + return proxy; |
| 49 | + } |
47 | 50 |
|
48 | | - public Boolean isKnownAttacker() { |
49 | | - return isKnownAttacker; |
50 | | - } |
| 51 | + public String getProxyType() { |
| 52 | + return proxyType; |
| 53 | + } |
51 | 54 |
|
52 | | - public Boolean isBot() { |
53 | | - return isBot; |
54 | | - } |
| 55 | + public boolean isAnonymous() { |
| 56 | + return anonymous; |
| 57 | + } |
55 | 58 |
|
56 | | - public Boolean isSpam() { |
57 | | - return isSpam; |
58 | | - } |
| 59 | + public boolean isKnownAttacker() { |
| 60 | + return knownAttacker; |
| 61 | + } |
59 | 62 |
|
60 | | - public Boolean isCloudProvider() { |
61 | | - return isCloudProvider; |
62 | | - } |
| 63 | + public boolean isBot() { |
| 64 | + return bot; |
| 65 | + } |
| 66 | + |
| 67 | + public boolean isSpam() { |
| 68 | + return spam; |
| 69 | + } |
| 70 | + |
| 71 | + public boolean isCloudProvider() { |
| 72 | + return cloudProvider; |
| 73 | + } |
63 | 74 |
|
| 75 | + @Override |
| 76 | + public String toString() { |
| 77 | + return json.toString(2); |
| 78 | + } |
64 | 79 | } |
0 commit comments