Skip to content
This repository was archived by the owner on Nov 24, 2018. It is now read-only.

Commit 91f11e9

Browse files
authored
Merge pull request #30 from Qup42/master
Code cleanup and additional checks
2 parents 76b3d8d + 01d6dc2 commit 91f11e9

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/main/java/me/checkium/vhackapi/Utils.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,22 @@ public static String readJson(Reader rd) throws IOException {
4040
public static JSONObject JSONRequest(String format, String data, String php){
4141
JSONObject json = null;
4242
String jsonText = StringRequest(format, data, php);
43-
if (jsonText.length() == 1) {
43+
if("".equals(jsonText))
44+
{
45+
throw new RuntimeException("Old API URL");
46+
}
47+
else if("8".equals(jsonText))
48+
{
49+
throw new RuntimeException("Wrong Password/User");
50+
}
51+
else if (jsonText.length() == 1) {
4452
return null;
4553
}
4654
json = new JSONObject(jsonText);
4755
return json;
4856
}
4957

58+
//it'll just do the request without any checks
5059
public static String StringRequest(String format, String data, String php)
5160
{
5261
System.setProperty("http.agent", "Chrome");

src/main/java/me/checkium/vhackapi/vHackAPI.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
package me.checkium.vhackapi;
22

3-
import java.io.BufferedReader;
4-
import java.io.IOException;
5-
import java.io.InputStream;
6-
import java.io.InputStreamReader;
7-
import java.net.URL;
8-
import java.nio.charset.Charset;
93
import java.util.concurrent.TimeUnit;
104

115
import org.json.JSONObject;
@@ -43,19 +37,8 @@ public String getStats(Stats stat) {
4337
} catch (InterruptedException e1) {
4438
e1.printStackTrace();
4539
}
46-
JSONObject json = null;
47-
InputStream is;
48-
try {
49-
is = new URL(Utils.generateURL("user::::pass::::uhash", username + "::::" + password + "::::" + userHash, "vh_update.php")).openStream();
50-
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
51-
String jsonText = Utils.readJson(rd);
52-
json = new JSONObject(jsonText);
53-
if (json.getString(stat.toString()) == null) {
54-
return null;
55-
}
56-
} catch (IOException e) {
57-
e.printStackTrace();
58-
}
40+
JSONObject json = Utils.JSONRequest("user::::pass::::uhash", username + "::::" + password + "::::" + userHash, "vh_update.php");
41+
5942
return json.getString(stat.toString());
6043
}
6144

0 commit comments

Comments
 (0)