Skip to content

Commit ebe3b07

Browse files
committed
Update libs
1 parent 709cccb commit ebe3b07

File tree

8 files changed

+35
-53
lines changed

8 files changed

+35
-53
lines changed

build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ plugins {
44
apply plugin: 'maven-publish'
55

66
group 'ru.redguy'
7-
version '1.0.2'
7+
version '1.0.3'
88

99
repositories {
1010
mavenCentral()
1111
}
1212

1313
dependencies {
14-
compile files("libs/ApacheFluentAPI-1.0.0.jar")
15-
compile files("libs/commonhttp-1.0.0.jar")
14+
compile files("libs/ApacheFluentAPI-1.0.2.jar")
1615
compile group: 'org.json', name: 'json', version: '20200518'
1716
}
1817

libs/ApacheFluentAPI-1.0.0.jar

-5.85 KB
Binary file not shown.

libs/ApacheFluentAPI-1.0.2.jar

1.4 MB
Binary file not shown.

libs/commonhttp-1.0.0.jar

-5.5 KB
Binary file not shown.

src/main/java/ru/redguy/redguyapi/ApiError.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ public ApiError(int code, String comment) {
1010
this.code = code;
1111
this.comment = comment;
1212
}
13+
14+
@Override
15+
public String getMessage() {
16+
return comment;
17+
}
1318
}

src/main/java/ru/redguy/redguyapi/math/Math.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,31 @@
22

33
import org.json.JSONObject;
44
import ru.redguy.redguyapi.ApiError;
5+
import ru.redguy.redguyapi.ApiRequest;
56
import ru.redguy.rednetworker.clients.http.ApacheFluentAPI;
6-
import ru.redguy.rednetworker.clients.http.exceptions.OpenConnectionException;
77

8+
import java.io.IOException;
89
import java.util.HashMap;
910
import java.util.Map;
1011

1112
public class Math {
1213

1314
private final Map<String, String> options;
14-
private final ApacheFluentAPI apacheFluentAPI;
1515

1616
public Math(Map<String, String> options) {
1717
this.options = options;
18-
apacheFluentAPI = new ApacheFluentAPI();
1918
}
2019

21-
public int get(NumberLevels level, int number) throws OpenConnectionException, URLException, ApiError {
22-
String data = apacheFluentAPI.getString("https://api.redguy.ru/math/get/", new HashMap<String, Object>() {{
23-
put("token", options.get("token"));
24-
put("v", options.get("v"));
20+
public int get(NumberLevels level, int number) throws ApiError, IOException {
21+
return ApiRequest.mainGet("math/get",options,new HashMap<String, Object>() {{
2522
put("level",level.getLevel());
2623
put("number",String.valueOf(number));
27-
}});
28-
JSONObject json = new JSONObject(data);
29-
if (json.getInt("code") != 1) {
30-
throw new ApiError(json.getInt("code"),json.getString("comment"));
31-
} else {
32-
return json.getJSONObject("response").getInt("result");
33-
}
24+
}}).getInt("result");
3425
}
3526

36-
public int max(NumberLevels level) throws OpenConnectionException, URLException, ApiError {
37-
String data = apacheFluentAPI.getString("https://api.redguy.ru/math/max/", new HashMap<String, Object>() {{
38-
put("token", options.get("token"));
39-
put("v", options.get("v"));
27+
public int max(NumberLevels level) throws ApiError, IOException {
28+
return ApiRequest.mainGet("math/max",options,new HashMap<String, Object>() {{
4029
put("level",level.getLevel());
41-
}});
42-
JSONObject json = new JSONObject(data);
43-
if (json.getInt("code") != 1) {
44-
throw new ApiError(json.getInt("code"),json.getString("comment"));
45-
} else {
46-
return json.getJSONObject("response").getInt("max");
47-
}
30+
}}).getInt("max");
4831
}
4932
}

src/main/java/ru/redguy/redguyapi/users/Users.java

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,32 @@
22

33
import org.json.JSONObject;
44
import ru.redguy.redguyapi.ApiError;
5+
import ru.redguy.redguyapi.ApiRequest;
56
import ru.redguy.rednetworker.clients.http.ApacheFluentAPI;
67
import ru.redguy.rednetworker.clients.http.exceptions.OpenConnectionException;
7-
import ru.redguy.rednetworker.clients.http.exceptions.URLException;
88

9+
import java.io.IOException;
910
import java.util.HashMap;
1011
import java.util.Map;
1112

1213
public class Users {
1314

1415
private Map<String, String> options;
15-
private ApacheFluentAPI apacheFluentAPI;
1616

1717
public Users(Map<String, String> options) {
1818
this.options = options;
19-
apacheFluentAPI = new ApacheFluentAPI();
2019
}
2120

22-
public User get(int id, Additional additional) throws OpenConnectionException, URLException, ApiError {
23-
String data = apacheFluentAPI.getString("https://api.redguy.ru/users/get/", new HashMap<String, Object>() {{
24-
put("token", options.get("token"));
25-
put("v", options.get("v"));
21+
public User get(int id, Additional additional) throws ApiError, IOException {
22+
return new User(ApiRequest.mainGet("users/get",options,new HashMap<String, Object>() {{
2623
put("id",id);
2724
put("additional",additional.getResult());
28-
}});
29-
JSONObject json = new JSONObject(data);
30-
if (json.getInt("code") != 1) {
31-
throw new ApiError(json.getInt("code"),json.getString("comment"));
32-
} else {
33-
return new User(json.getJSONObject("response"));
34-
}
25+
}}));
3526
}
3627

37-
public User get(int id) throws OpenConnectionException, URLException, ApiError {
38-
String data = apacheFluentAPI.getString("https://api.redguy.ru/users/get/", new HashMap<String, Object>() {{
39-
put("token", options.get("token"));
40-
put("v", options.get("v"));
28+
public User get(int id) throws ApiError, IOException {
29+
return new User(ApiRequest.mainGet("users/get",options,new HashMap<String, Object>() {{
4130
put("id",id);
42-
}});
43-
JSONObject json = new JSONObject(data);
44-
if (json.getInt("code") != 1) {
45-
throw new ApiError(json.getInt("code"),json.getString("comment"));
46-
} else {
47-
return new User(json.getJSONObject("response"));
48-
}
31+
}}));
4932
}
5033
}

src/test/java/Main.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ru.redguy.redguyapi.RedGuyApi;
2+
import ru.redguy.redguyapi.ValueChange;
23
import ru.redguy.redguyapi.math.NumberLevels;
34

45
public class Main {
@@ -15,5 +16,16 @@ public static void main(String[] args) throws Exception {
1516
} else {
1617
System.out.println("users.get - OK!");
1718
}
19+
20+
int wins = redGuyApi.event().Wins().get("b12");
21+
ValueChange add = redGuyApi.event().Wins().add("b12",1);
22+
if((int)add.getOldValue() != wins) {
23+
throw new Exception("Incorrect result!");
24+
}
25+
ValueChange set = redGuyApi.event().Wins().set("b12",wins);
26+
if((int)set.getNewValue() != wins) {
27+
throw new Exception("Incorrect result!");
28+
}
29+
System.out.println("Event.Wins.* - OK!");
1830
}
1931
}

0 commit comments

Comments
 (0)