Skip to content

Commit e00cde5

Browse files
committed
Add report endpoint
1 parent c8248be commit e00cde5

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
apply plugin: 'maven'
66

77
group 'ru.redguy'
8-
version '1.1.3'
8+
version '1.1.4'
99

1010
repositories {
1111
maven {
@@ -14,8 +14,9 @@ repositories {
1414
}
1515

1616
dependencies {
17-
compile 'com.squareup.okhttp3:okhttp:4.11.0'
17+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
1818
implementation 'com.google.code.gson:gson:2.8.9'
19+
implementation 'org.jetbrains:annotations:23.0.0'
1920
}
2021

2122
//utf-8
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package ru.redguy.redguyapi.links;
22

33
import ru.redguy.redguyapi.ApiError;
4-
import ru.redguy.redguyapi.hashes.Hash;
54
import ru.redguy.redguyapi.utils.RequestUtil;
65

76
import java.io.IOException;
87
import java.util.HashMap;
98
import java.util.List;
109
import java.util.Map;
10+
import java.util.Objects;
1111

1212
public class Links {
1313
private final Map<String, String> options;
@@ -19,13 +19,19 @@ public Links(Map<String, String> options) {
1919
/**
2020
* Checks links is it safe
2121
*
22-
* @return Array of SafeEntries
22+
* @return List of SafeEntries
2323
* @throws ApiError Error from API
2424
* @throws IOException Network error
2525
*/
2626
public List<SafeEntry> isSafe(String link) throws ApiError, IOException {
27-
return RequestUtil.mainGet("v1/links/safe", SafeResponse.class, options, new HashMap<String, Object>() {{
27+
return Objects.requireNonNull(RequestUtil.mainGet("v1/links/safe", SafeResponse.class, options, new HashMap<>() {{
2828
put("link", link);
29-
}}).getDomains();
29+
}})).getDomains();
30+
}
31+
32+
public void report(String link) throws ApiError, IOException {
33+
RequestUtil.mainGet("v1/links/report", null, options, new HashMap<>() {{
34+
put("link", link);
35+
}});
3036
}
3137
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static <T extends ApiResponse> T mainGet(String path, Class<T> responseTy
2525
if (result.getCode() != 1) {
2626
throw new ApiError(result.getCode(), result.getComment());
2727
} else {
28+
if(responseType == null) return null;
2829
return GSON.GSON.fromJson(result.getResponse(), responseType);
2930
}
3031
}
@@ -46,6 +47,7 @@ public static <T extends ApiResponse> T mainPost(String path, Class<T> responseT
4647
if (result.getCode() != 1) {
4748
throw new ApiError(result.getCode(), result.getComment());
4849
} else {
50+
if(responseType == null) return null;
4951
return GSON.GSON.fromJson(result.getResponse(), responseType);
5052
}
5153
}

0 commit comments

Comments
 (0)