Skip to content

Commit

Permalink
1. Some Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
megoRU committed Jul 1, 2023
1 parent 87e9be8 commit c93cab2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.boticordjava.api</groupId>
<artifactId>boticordjava</artifactId>
<version>5.1</version>
<version>5.2</version>

<properties>
<maven.compiler.source>16</maven.compiler.source>
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/org/boticordjava/api/impl/BotiCordAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class BotiCordAPIImpl implements BotiCordAPI {
private final String searchURL = "https://api.boticord.top/search/";
private final Gson gson;
private final String token;
private final String searchApiKey;
private String searchApiKey = null;
private final boolean devMode;

protected BotiCordAPIImpl(String token, boolean devMode) {
Expand All @@ -74,13 +74,6 @@ public LocalDateTime deserialize(JsonElement json, Type type, JsonDeserializatio
}

}).setPrettyPrinting().create();

try {
this.searchApiKey = getSearchApiKey().getKey();
} catch (UnsuccessfulHttpException e) {
throw new RuntimeException(e);
}

}

private SearchApiKey getSearchApiKey() throws UnsuccessfulHttpException {
Expand Down Expand Up @@ -129,9 +122,19 @@ public ServerInfo getServerInfo(@NotNull String serverId) throws UnsuccessfulHtt
return get(url, new DefaultResponseTransformer<>(gson, ServerInfo.class)).getResult();
}

private void getApiSearchKey() {
try {
if (searchApiKey == null) {
this.searchApiKey = getSearchApiKey().getKey();
}
} catch (UnsuccessfulHttpException e) {
throw new RuntimeException(e);
}
}

@Override
public List<ServersSearch> searchServers(@NotNull String text) throws MeilisearchException, IllegalArgumentException, JsonProcessingException {
if (searchApiKey == null) throw new IllegalArgumentException("SearchApiKey is NULL!");
getApiSearchKey();
Client client = new Client(new Config(searchURL, searchApiKey));
Index index = client.index("servers");
SearchResult searchResult = index.search(text);
Expand All @@ -148,7 +151,7 @@ public List<ServersSearch> searchServers(@NotNull String text) throws Meilisearc

@Override
public List<BotsSearch> searchBots(@NotNull String text) throws MeilisearchException, IllegalArgumentException, JsonProcessingException {
if (searchApiKey == null) throw new IllegalArgumentException("SearchApiKey is NULL!");
getApiSearchKey();
Client client = new Client(new Config(searchURL, searchApiKey));
Index index = client.index("bots");
SearchResult searchResult = index.search(text);
Expand All @@ -166,7 +169,7 @@ public List<BotsSearch> searchBots(@NotNull String text) throws MeilisearchExcep

@Override
public List<UsersCommentSearch> searchUserComments(@NotNull String resourceId) throws MeilisearchException, IllegalArgumentException, JsonProcessingException {
if (searchApiKey == null) throw new IllegalArgumentException("SearchApiKey is NULL!");
getApiSearchKey();
Client client = new Client(new Config(searchURL, searchApiKey));
String format = String.format("resource = %s", resourceId);
String[] filter = new String[]{format};
Expand Down

0 comments on commit c93cab2

Please sign in to comment.