Skip to content

Commit d2b9895

Browse files
committed
Lock text changes
1 parent e339bcf commit d2b9895

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import ru.redguy.redguyapi.links.Links;
77
import ru.redguy.redguyapi.minecraft.Minecraft;
88
import ru.redguy.redguyapi.news.News;
9+
import ru.redguy.redguyapi.text.Text;
910
import ru.redguy.redguyapi.token.Token;
1011
import ru.redguy.redguyapi.users.Users;
1112

@@ -99,4 +100,8 @@ public Hashes hashes() {
99100
public Links links() {
100101
return new Links(options);
101102
}
103+
104+
public Text text() {
105+
return new Text(options);
106+
}
102107
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package ru.redguy.redguyapi.text;
2+
3+
import ru.redguy.redguyapi.ApiError;
4+
import ru.redguy.redguyapi.links.SafeEntry;
5+
import ru.redguy.redguyapi.links.SafeResponse;
6+
import ru.redguy.redguyapi.utils.RequestUtil;
7+
8+
import java.io.IOException;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
13+
public class Text {
14+
private final Map<String, String> options;
15+
16+
public Text(Map<String, String> options) {
17+
this.options = options;
18+
}
19+
20+
/**
21+
* Parses text and returns a json object with found entities, requires text:parse permission
22+
*
23+
* @return Array of SafeEntries
24+
* @throws ApiError Error from API
25+
* @throws IOException Network error
26+
*/
27+
public TextParseResponse parse(String texts, String lang) throws ApiError, IOException {
28+
return RequestUtil.mainPost("v1/text/parse", TextParseResponse.class, options, new Object() {{
29+
30+
}});
31+
}
32+
33+
/**
34+
* Parses text and returns a json object with found entities with ru_ru language, requires text:parse permission
35+
*
36+
* @return Array of SafeEntries
37+
* @throws ApiError Error from API
38+
* @throws IOException Network error
39+
*/
40+
public TextParseResponse parse(String text) throws ApiError, IOException {
41+
return parse(text, "ru_ru");
42+
}
43+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package ru.redguy.redguyapi.text;
2+
3+
import ru.redguy.redguyapi.links.SafeEntry;
4+
import ru.redguy.redguyapi.utils.RequestUtil;
5+
6+
import java.util.List;
7+
8+
public class TextParseResponse implements RequestUtil.ApiResponse {
9+
private String body;
10+
private int start;
11+
private int end;
12+
private String dim;
13+
private boolean latent;
14+
}

src/main/java/ru/redguy/redguyapi/utils/RequestUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.IOException;
99
import java.io.UnsupportedEncodingException;
1010
import java.net.URLEncoder;
11+
import java.util.HashMap;
1112
import java.util.Map;
1213

1314
public class RequestUtil {
@@ -28,6 +29,10 @@ public static <T extends ApiResponse> T mainGet(String path, Class<T> responseTy
2829
}
2930
}
3031

32+
public static <T extends ApiResponse> T mainPost(String path, Class<T> responseType, @NotNull Map<String, String> options, Object body) throws ApiError, IOException {
33+
return mainPost(path, responseType, options, GSON.GSON.toJson(body), new HashMap<>());
34+
}
35+
3136
public static <T extends ApiResponse> T mainPost(String path, Class<T> responseType, @NotNull Map<String, String> options, String body, @NotNull Map<String, Object> params) throws ApiError, IOException {
3237
params.put("token", options.get("token"));
3338

0 commit comments

Comments
 (0)