Skip to content

Commit b1ccdd1

Browse files
Merge pull request #3 from botlify-net/dev
fix: plan when creating new zone throw a JSON error
2 parents 212fbf1 + 39c54bb commit b1ccdd1

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>net.botlify.brightdata</groupId>
88
<artifactId>bright-data-api</artifactId>
9-
<version>1.1</version>
9+
<version>1.2</version>
1010

1111
<name>BrightData API</name>
1212
<url>https://github.com/botlify-io/bright-data-api</url>
@@ -107,9 +107,9 @@
107107
</profiles>
108108

109109
<scm>
110+
<url>https://github.com/botlify-net/bright-data-api</url>
110111
<connection>scm:github:https://github.com/botlify-net/bright-data-api</connection>
111112
<developerConnection>scm:github:https://github.com/botlify-net/bright-data-api</developerConnection>
112-
<url>https://github.com/botlify-net/bright-data-api</url>
113113
<tag>master</tag>
114114
</scm>
115115

src/main/java/net/botlify/brightdata/BrightDataAPI.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,12 @@ public boolean testProxyValidity(@NotNull final String host,
140140
.build();
141141

142142
try (Response response = client.newCall(request).execute()) {
143-
final String body = response.body().string();
144143
final int code = response.code();
144+
if (code == 407) {
145+
log.trace("Fail to test the proxy validity because of a proxy authentication error.");
146+
return (false);
147+
}
148+
final String body = response.body().string();
145149
assertResponse(code, body);
146150
return (response.code() == 200);
147151
} catch (Exception e) {

src/main/java/net/botlify/brightdata/object/Plan.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import lombok.Getter;
77
import lombok.ToString;
88
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
910
import org.json.JSONObject;
1011

1112
import java.time.Instant;
@@ -39,8 +40,8 @@ public class Plan {
3940
/**
4041
* The ip fallback number of the plan.
4142
*/
42-
@Getter
43-
private final int ipFallback;
43+
@Getter @Nullable
44+
private final Integer ipFallback;
4445

4546
/**
4647
* The type of ips of the plan.
@@ -69,8 +70,8 @@ public class Plan {
6970
/**
7071
* The number of new ips of the plan.
7172
*/
72-
@Getter
73-
private final int ips_new;
73+
@Getter @Nullable
74+
private final Integer ips_new;
7475

7576
/**
7677
* Constructor of the plan from the JSON object.
@@ -80,12 +81,20 @@ public Plan(@NotNull final JSONObject jsonObject) {
8081
this.start = Instant.parse(jsonObject.getString("start"));
8182
this.product = jsonObject.getString("product");
8283
this.type = Objects.requireNonNull(PlanType.fromString(jsonObject.getString("type")));
83-
this.ipFallback = jsonObject.getInt("ip_fallback");
8484
this.ipsType = Objects.requireNonNull(IpType.fromString(jsonObject.getString("ips_type")));
8585
this.ips = jsonObject.getInt("ips");
8686
this.country = jsonObject.getString("country");
8787
this.bandwidth = jsonObject.getString("bandwidth");
88-
this.ips_new = jsonObject.getInt("ips_new");
88+
// Ip fallback
89+
if (jsonObject.has("ip_fallback"))
90+
this.ipFallback = jsonObject.getInt("ip_fallback");
91+
else
92+
this.ipFallback = null;
93+
// Ips new
94+
if (jsonObject.has("ips_new"))
95+
this.ips_new = jsonObject.getInt("ips_new");
96+
else
97+
this.ips_new = null;
8998
}
9099

91100
/**
@@ -130,12 +139,12 @@ public Plan(@NotNull final Instant start,
130139
jsonObject.put("start", start.toString());
131140
jsonObject.put("product", product);
132141
jsonObject.put("type", type.toString());
133-
jsonObject.put("ip_fallback", ipFallback);
142+
jsonObject.put("ip_fallback", (ipFallback == null) ? JSONObject.NULL : ipFallback);
134143
jsonObject.put("ips_type", ipsType.toString());
135144
jsonObject.put("ips", ips);
136145
jsonObject.put("country", country);
137146
jsonObject.put("bandwidth", bandwidth);
138-
jsonObject.put("ips_new", ips_new);
147+
jsonObject.put("ips_new", (ips_new == null) ? JSONObject.NULL : ips_new);
139148
return jsonObject;
140149
}
141150

0 commit comments

Comments
 (0)