diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8aa4596..4e728a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,20 @@
## [Unreleased]
+## [4.0.0] - 2023-12-18
+
+### Added
+
+- new dependency supercell-api-wrapper-essentials
+
+### Changed
+
+- classes in package brawljars.api.* moved to supercell.api.wrapper.essentials.api.*
+- classes in package brawljars.connector moved to supercell.api.wrapper.essentials.connector
+- classes in package brawljars.api.connector moved to supercell.api.wrapper.essentials.api.connector
+- classes in package brawljars.build moved to supercell.api.wrapper.essentials.build
+- classes in package brawljars.common moved to supercell.api.wrapper.essentials.common
+
## [3.0.8] - 2023-12-18
### Added
@@ -71,7 +85,8 @@
- Create release job #41
-[unreleased]: https://github.com/mlieshoff/brawljars/compare/v3.0.8...HEAD
+[unreleased]: https://github.com/mlieshoff/brawljars/compare/v4.0.0...HEAD
+[4.0.0]: https://github.com/mlieshoff/brawljars/compare/v3.0.8...v4.0.0
[3.0.8]: https://github.com/mlieshoff/brawljars/compare/v3.0.7...v3.0.8
[3.0.7]: https://github.com/mlieshoff/brawljars/compare/v3.0.6...v3.0.7
[3.0.6]: https://github.com/mlieshoff/brawljars/compare/v3.0.5...v3.0.6
diff --git a/README.md b/README.md
index 9e906eb..e1be464 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
[![](https://img.shields.io/badge/java-packagecloud.io-844fec.svg)](https://packagecloud.io/)
[![Nightlies](https://github.com/mlieshoff/brawljars/actions/workflows/nightlies.yml/badge.svg)](https://github.com/mlieshoff/brawljars/actions/workflows/nightlies.yml)
-# brawljars 3.0.8
+# brawljars 4.0.0
A Java Wrapper For Official Supercell Brawl Stars Api
## Why we don't use the Swagger scheme?
@@ -37,9 +37,39 @@ Proxy endpoint
https://bsproxy.royaleapi.dev/v1
```
-Use built-in http connector
+Bind essentials to your project
+```xml
+
+
+ packagecloud-supercell-api-wrapper-essentials
+ https://packagecloud.io/mlieshoff/supercell-api-wrapper-essentials/maven2
+
+ true
+
+
+ true
+
+
+
+```
+
+and use the dependency
+```xml
+
+ supercell-api-wrapper-essentials
+ supercell-api-wrapper-essentials
+ 1.0.1
+
+```
+
+Use built-in standard connector
+```java
+Connector connector = new StandardConnector();
+```
+
+or use the new filesystem cached connector
```java
- Connector connector = new StandardConnector();
+Connector connector = new FilesystemCachedConnector("brawljars")
```
or use custom implementation
@@ -268,7 +298,7 @@ All requests are returning *java.concurrent.Future*. The execution will be async
to Gradle:
```groovy
- implementation group: 'brawljars', name: 'brawljars', version: '3.0.8'
+ implementation group: 'brawljars', name: 'brawljars', version: '4.0.0'
```
to Maven:
@@ -276,7 +306,7 @@ to Maven:
brawljars
brawljars
- 3.0.8
+ 4.0.0
```
diff --git a/VERSION.txt b/VERSION.txt
index 27bb58a..f684230 100644
--- a/VERSION.txt
+++ b/VERSION.txt
@@ -1 +1 @@
-v3.0.8
\ No newline at end of file
+v4.0.0
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index f35eac0..5400ea0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
brawljars
jar
- 3.0.8
+ 4.0.0
brawljars
https://maven.apache.org
2020
@@ -12,8 +12,8 @@
michael.lieshoff (ML)
Michael Lieshoff
- michaellieshoff@gmx.de
- mili.org
+ michael.lieshoff@gmail.com
+ psiclops
Developer
@@ -135,7 +135,7 @@
java
- brawljars.build.ReleaseVersionChecker
+ supercell.api.wrapper.essentials.build.ReleaseVersionChecker
./VERSION.txt
./pom.xml
@@ -201,6 +201,11 @@
gson
${version.gson}
+
+ supercell-api-wrapper-essentials
+ supercell-api-wrapper-essentials
+ 1.0.1
+
@@ -289,5 +294,15 @@
true
+
+ packagecloud-supercell-api-wrapper-essentials
+ https://packagecloud.io/mlieshoff/supercell-api-wrapper-essentials/maven2
+
+ true
+
+
+ true
+
+
\ No newline at end of file
diff --git a/src/main/java/brawljars/BrawlJars.java b/src/main/java/brawljars/BrawlJars.java
index 20d7dd2..b29a9d6 100644
--- a/src/main/java/brawljars/BrawlJars.java
+++ b/src/main/java/brawljars/BrawlJars.java
@@ -16,14 +16,15 @@
*/
package brawljars;
-import static brawljars.common.Utils.require;
+import static supercell.api.wrapper.essentials.common.Utils.require;
import static java.util.stream.Collectors.toList;
-import brawljars.api.Api;
-import brawljars.api.ApiContext;
import brawljars.api.intern.DefaultApiClasses;
-import brawljars.connector.Connector;
+
+import supercell.api.wrapper.essentials.api.Api;
+import supercell.api.wrapper.essentials.api.ApiContext;
+import supercell.api.wrapper.essentials.connector.Connector;
import java.lang.reflect.Constructor;
import java.util.HashMap;
diff --git a/src/main/java/brawljars/api/Api.java b/src/main/java/brawljars/api/Api.java
deleted file mode 100644
index 498bc30..0000000
--- a/src/main/java/brawljars/api/Api.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.api;
-
-public interface Api {}
diff --git a/src/main/java/brawljars/api/ApiContext.java b/src/main/java/brawljars/api/ApiContext.java
deleted file mode 100644
index a5731e4..0000000
--- a/src/main/java/brawljars/api/ApiContext.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.api;
-
-import static brawljars.common.Utils.require;
-
-import brawljars.connector.Connector;
-
-public record ApiContext(String url, String apiKey, Connector connector) {
-
- public ApiContext {
- require("url", url);
- require("apiKey", apiKey);
- require("connector", connector);
- }
-}
diff --git a/src/main/java/brawljars/api/BaseApi.java b/src/main/java/brawljars/api/BaseApi.java
deleted file mode 100644
index b278c6e..0000000
--- a/src/main/java/brawljars/api/BaseApi.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.api;
-
-import static brawljars.common.Utils.require;
-
-import brawljars.common.IResponse;
-import brawljars.common.Request;
-import brawljars.connector.Connector;
-import brawljars.connector.RequestContext;
-
-import lombok.NonNull;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-
-import java.util.concurrent.Future;
-
-@Slf4j
-@RequiredArgsConstructor
-public class BaseApi implements Api {
-
- private final ExecutorServiceDecorator executorServiceDecorator =
- new ExecutorServiceDecorator();
-
- @NonNull private final ApiContext apiContext;
-
- protected Future get(
- String part, Request request, Class responseClass) {
- require("part", part);
- require("request", request);
- require("responseClass", responseClass);
- String apiKey = apiContext.apiKey();
- Connector connector = apiContext.connector();
- String url = apiContext.url() + part;
- RequestContext requestContext = new RequestContext(url, apiKey, request, responseClass);
- return executorServiceDecorator.submit(connector, requestContext);
- }
-}
diff --git a/src/main/java/brawljars/api/ExecutorServiceDecorator.java b/src/main/java/brawljars/api/ExecutorServiceDecorator.java
deleted file mode 100644
index 08cd714..0000000
--- a/src/main/java/brawljars/api/ExecutorServiceDecorator.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.api;
-
-import brawljars.common.IResponse;
-import brawljars.connector.Connector;
-import brawljars.connector.RequestContext;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-class ExecutorServiceDecorator {
-
- private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(8);
-
- public Future submit(
- Connector connector, RequestContext requestContext) {
- return EXECUTOR_SERVICE.submit(() -> connector.get(requestContext));
- }
-}
diff --git a/src/main/java/brawljars/api/intern/DefaultApiClasses.java b/src/main/java/brawljars/api/intern/DefaultApiClasses.java
index 53e0cad..6bfa23d 100644
--- a/src/main/java/brawljars/api/intern/DefaultApiClasses.java
+++ b/src/main/java/brawljars/api/intern/DefaultApiClasses.java
@@ -16,7 +16,6 @@
*/
package brawljars.api.intern;
-import brawljars.api.Api;
import brawljars.api.intern.brawlers.BrawlerApi;
import brawljars.api.intern.clubs.ClubApi;
import brawljars.api.intern.events.EventApi;
@@ -25,6 +24,8 @@
import lombok.Getter;
+import supercell.api.wrapper.essentials.api.Api;
+
import java.util.Map;
@Getter
diff --git a/src/main/java/brawljars/api/intern/brawlers/BrawlerApi.java b/src/main/java/brawljars/api/intern/brawlers/BrawlerApi.java
index 144f055..14040db 100644
--- a/src/main/java/brawljars/api/intern/brawlers/BrawlerApi.java
+++ b/src/main/java/brawljars/api/intern/brawlers/BrawlerApi.java
@@ -16,7 +16,7 @@
*/
package brawljars.api.intern.brawlers;
-import brawljars.api.Api;
+import supercell.api.wrapper.essentials.api.Api;
import java.util.concurrent.Future;
diff --git a/src/main/java/brawljars/api/intern/brawlers/BrawlerApiImpl.java b/src/main/java/brawljars/api/intern/brawlers/BrawlerApiImpl.java
index 90ffdfe..6c97cd0 100644
--- a/src/main/java/brawljars/api/intern/brawlers/BrawlerApiImpl.java
+++ b/src/main/java/brawljars/api/intern/brawlers/BrawlerApiImpl.java
@@ -16,8 +16,8 @@
*/
package brawljars.api.intern.brawlers;
-import brawljars.api.ApiContext;
-import brawljars.api.BaseApi;
+import supercell.api.wrapper.essentials.api.ApiContext;
+import supercell.api.wrapper.essentials.api.BaseApi;
import java.util.concurrent.Future;
diff --git a/src/main/java/brawljars/api/intern/brawlers/BrawlerRequest.java b/src/main/java/brawljars/api/intern/brawlers/BrawlerRequest.java
index b66c8e9..9ae0eef 100644
--- a/src/main/java/brawljars/api/intern/brawlers/BrawlerRequest.java
+++ b/src/main/java/brawljars/api/intern/brawlers/BrawlerRequest.java
@@ -16,10 +16,10 @@
*/
package brawljars.api.intern.brawlers;
-import brawljars.common.Request;
-
import lombok.Builder;
+import supercell.api.wrapper.essentials.common.Request;
+
import java.util.Map;
public class BrawlerRequest extends Request {
diff --git a/src/main/java/brawljars/api/intern/brawlers/BrawlerResponse.java b/src/main/java/brawljars/api/intern/brawlers/BrawlerResponse.java
index 439a3b9..12df16d 100644
--- a/src/main/java/brawljars/api/intern/brawlers/BrawlerResponse.java
+++ b/src/main/java/brawljars/api/intern/brawlers/BrawlerResponse.java
@@ -16,14 +16,14 @@
*/
package brawljars.api.intern.brawlers;
-import brawljars.common.IResponse;
-import brawljars.common.RawResponse;
-
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
+import supercell.api.wrapper.essentials.common.IResponse;
+import supercell.api.wrapper.essentials.common.RawResponse;
+
@Data
@EqualsAndHashCode(callSuper = true)
public class BrawlerResponse extends Brawler implements IResponse {
diff --git a/src/main/java/brawljars/api/intern/brawlers/BrawlersRequest.java b/src/main/java/brawljars/api/intern/brawlers/BrawlersRequest.java
index 952f35d..dd341ea 100644
--- a/src/main/java/brawljars/api/intern/brawlers/BrawlersRequest.java
+++ b/src/main/java/brawljars/api/intern/brawlers/BrawlersRequest.java
@@ -16,10 +16,10 @@
*/
package brawljars.api.intern.brawlers;
-import brawljars.common.PaginationRequest;
-
import lombok.Builder;
+import supercell.api.wrapper.essentials.common.PaginationRequest;
+
public class BrawlersRequest extends PaginationRequest {
@Builder
diff --git a/src/main/java/brawljars/api/intern/brawlers/BrawlersResponse.java b/src/main/java/brawljars/api/intern/brawlers/BrawlersResponse.java
index 88c1df3..14f5851 100644
--- a/src/main/java/brawljars/api/intern/brawlers/BrawlersResponse.java
+++ b/src/main/java/brawljars/api/intern/brawlers/BrawlersResponse.java
@@ -16,6 +16,6 @@
*/
package brawljars.api.intern.brawlers;
-import brawljars.common.PaginationResponse;
+import supercell.api.wrapper.essentials.common.PaginationResponse;
public class BrawlersResponse extends PaginationResponse {}
diff --git a/src/main/java/brawljars/api/intern/clubs/ClubApi.java b/src/main/java/brawljars/api/intern/clubs/ClubApi.java
index 64d63c4..71c15c4 100644
--- a/src/main/java/brawljars/api/intern/clubs/ClubApi.java
+++ b/src/main/java/brawljars/api/intern/clubs/ClubApi.java
@@ -16,12 +16,13 @@
*/
package brawljars.api.intern.clubs;
-import brawljars.api.Api;
import brawljars.api.intern.clubs.info.ClubRequest;
import brawljars.api.intern.clubs.info.ClubResponse;
import brawljars.api.intern.clubs.member.ClubMembersRequest;
import brawljars.api.intern.clubs.member.ClubMembersResponse;
+import supercell.api.wrapper.essentials.api.Api;
+
import java.util.concurrent.Future;
public interface ClubApi extends Api {
diff --git a/src/main/java/brawljars/api/intern/clubs/ClubApiImpl.java b/src/main/java/brawljars/api/intern/clubs/ClubApiImpl.java
index aaa5af5..da60831 100644
--- a/src/main/java/brawljars/api/intern/clubs/ClubApiImpl.java
+++ b/src/main/java/brawljars/api/intern/clubs/ClubApiImpl.java
@@ -16,13 +16,14 @@
*/
package brawljars.api.intern.clubs;
-import brawljars.api.ApiContext;
-import brawljars.api.BaseApi;
import brawljars.api.intern.clubs.info.ClubRequest;
import brawljars.api.intern.clubs.info.ClubResponse;
import brawljars.api.intern.clubs.member.ClubMembersRequest;
import brawljars.api.intern.clubs.member.ClubMembersResponse;
+import supercell.api.wrapper.essentials.api.ApiContext;
+import supercell.api.wrapper.essentials.api.BaseApi;
+
import java.util.concurrent.Future;
class ClubApiImpl extends BaseApi implements ClubApi {
diff --git a/src/main/java/brawljars/api/intern/clubs/info/ClubRequest.java b/src/main/java/brawljars/api/intern/clubs/info/ClubRequest.java
index 6638329..2c740fb 100644
--- a/src/main/java/brawljars/api/intern/clubs/info/ClubRequest.java
+++ b/src/main/java/brawljars/api/intern/clubs/info/ClubRequest.java
@@ -16,10 +16,10 @@
*/
package brawljars.api.intern.clubs.info;
-import brawljars.common.Request;
-
import lombok.Builder;
+import supercell.api.wrapper.essentials.common.Request;
+
import java.util.Map;
public class ClubRequest extends Request {
diff --git a/src/main/java/brawljars/api/intern/clubs/info/ClubResponse.java b/src/main/java/brawljars/api/intern/clubs/info/ClubResponse.java
index dbc1ad0..873f352 100644
--- a/src/main/java/brawljars/api/intern/clubs/info/ClubResponse.java
+++ b/src/main/java/brawljars/api/intern/clubs/info/ClubResponse.java
@@ -16,14 +16,14 @@
*/
package brawljars.api.intern.clubs.info;
-import brawljars.common.IResponse;
-import brawljars.common.RawResponse;
-
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
+import supercell.api.wrapper.essentials.common.IResponse;
+import supercell.api.wrapper.essentials.common.RawResponse;
+
@Data
@EqualsAndHashCode(callSuper = true)
public class ClubResponse extends Club implements IResponse {
diff --git a/src/main/java/brawljars/api/intern/clubs/member/ClubMembersRequest.java b/src/main/java/brawljars/api/intern/clubs/member/ClubMembersRequest.java
index 002d0b1..b68cab2 100644
--- a/src/main/java/brawljars/api/intern/clubs/member/ClubMembersRequest.java
+++ b/src/main/java/brawljars/api/intern/clubs/member/ClubMembersRequest.java
@@ -16,10 +16,10 @@
*/
package brawljars.api.intern.clubs.member;
-import brawljars.common.PaginationRequest;
-
import lombok.Builder;
+import supercell.api.wrapper.essentials.common.PaginationRequest;
+
import java.util.Map;
public class ClubMembersRequest extends PaginationRequest {
diff --git a/src/main/java/brawljars/api/intern/clubs/member/ClubMembersResponse.java b/src/main/java/brawljars/api/intern/clubs/member/ClubMembersResponse.java
index 4fdd80c..225da91 100644
--- a/src/main/java/brawljars/api/intern/clubs/member/ClubMembersResponse.java
+++ b/src/main/java/brawljars/api/intern/clubs/member/ClubMembersResponse.java
@@ -16,6 +16,6 @@
*/
package brawljars.api.intern.clubs.member;
-import brawljars.common.PaginationResponse;
+import supercell.api.wrapper.essentials.common.PaginationResponse;
public class ClubMembersResponse extends PaginationResponse {}
diff --git a/src/main/java/brawljars/api/intern/events/EventApi.java b/src/main/java/brawljars/api/intern/events/EventApi.java
index 35095dd..aa4b9e8 100644
--- a/src/main/java/brawljars/api/intern/events/EventApi.java
+++ b/src/main/java/brawljars/api/intern/events/EventApi.java
@@ -16,7 +16,7 @@
*/
package brawljars.api.intern.events;
-import brawljars.api.Api;
+import supercell.api.wrapper.essentials.api.Api;
import java.util.concurrent.Future;
diff --git a/src/main/java/brawljars/api/intern/events/EventApiImpl.java b/src/main/java/brawljars/api/intern/events/EventApiImpl.java
index 6ee1b62..22deaba 100644
--- a/src/main/java/brawljars/api/intern/events/EventApiImpl.java
+++ b/src/main/java/brawljars/api/intern/events/EventApiImpl.java
@@ -16,8 +16,8 @@
*/
package brawljars.api.intern.events;
-import brawljars.api.ApiContext;
-import brawljars.api.BaseApi;
+import supercell.api.wrapper.essentials.api.ApiContext;
+import supercell.api.wrapper.essentials.api.BaseApi;
import java.util.concurrent.Future;
diff --git a/src/main/java/brawljars/api/intern/events/EventRotationRequest.java b/src/main/java/brawljars/api/intern/events/EventRotationRequest.java
index f1ff06b..9f4a53a 100644
--- a/src/main/java/brawljars/api/intern/events/EventRotationRequest.java
+++ b/src/main/java/brawljars/api/intern/events/EventRotationRequest.java
@@ -16,10 +16,10 @@
*/
package brawljars.api.intern.events;
-import brawljars.common.Request;
-
import lombok.Builder;
+import supercell.api.wrapper.essentials.common.Request;
+
public class EventRotationRequest extends Request {
@Builder
diff --git a/src/main/java/brawljars/api/intern/events/EventRotationResponse.java b/src/main/java/brawljars/api/intern/events/EventRotationResponse.java
index 2a74f6c..6aa92eb 100644
--- a/src/main/java/brawljars/api/intern/events/EventRotationResponse.java
+++ b/src/main/java/brawljars/api/intern/events/EventRotationResponse.java
@@ -16,14 +16,14 @@
*/
package brawljars.api.intern.events;
-import brawljars.common.IResponse;
-import brawljars.common.RawResponse;
-
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
+import supercell.api.wrapper.essentials.common.IResponse;
+import supercell.api.wrapper.essentials.common.RawResponse;
+
@Data
@EqualsAndHashCode(callSuper = true)
public class EventRotationResponse extends EventRotation implements IResponse {
diff --git a/src/main/java/brawljars/api/intern/players/PlayerApi.java b/src/main/java/brawljars/api/intern/players/PlayerApi.java
index a3e8b35..b7020e4 100644
--- a/src/main/java/brawljars/api/intern/players/PlayerApi.java
+++ b/src/main/java/brawljars/api/intern/players/PlayerApi.java
@@ -16,12 +16,13 @@
*/
package brawljars.api.intern.players;
-import brawljars.api.Api;
import brawljars.api.intern.players.battlelog.BattleLogRequest;
import brawljars.api.intern.players.battlelog.BattleLogResponse;
import brawljars.api.intern.players.info.PlayerRequest;
import brawljars.api.intern.players.info.PlayerResponse;
+import supercell.api.wrapper.essentials.api.Api;
+
import java.util.concurrent.Future;
public interface PlayerApi extends Api {
diff --git a/src/main/java/brawljars/api/intern/players/PlayerApiImpl.java b/src/main/java/brawljars/api/intern/players/PlayerApiImpl.java
index 9d44d1d..e432456 100644
--- a/src/main/java/brawljars/api/intern/players/PlayerApiImpl.java
+++ b/src/main/java/brawljars/api/intern/players/PlayerApiImpl.java
@@ -16,13 +16,14 @@
*/
package brawljars.api.intern.players;
-import brawljars.api.ApiContext;
-import brawljars.api.BaseApi;
import brawljars.api.intern.players.battlelog.BattleLogRequest;
import brawljars.api.intern.players.battlelog.BattleLogResponse;
import brawljars.api.intern.players.info.PlayerRequest;
import brawljars.api.intern.players.info.PlayerResponse;
+import supercell.api.wrapper.essentials.api.ApiContext;
+import supercell.api.wrapper.essentials.api.BaseApi;
+
import java.util.concurrent.Future;
class PlayerApiImpl extends BaseApi implements PlayerApi {
diff --git a/src/main/java/brawljars/api/intern/players/battlelog/BattleLogRequest.java b/src/main/java/brawljars/api/intern/players/battlelog/BattleLogRequest.java
index 893f754..8968664 100644
--- a/src/main/java/brawljars/api/intern/players/battlelog/BattleLogRequest.java
+++ b/src/main/java/brawljars/api/intern/players/battlelog/BattleLogRequest.java
@@ -16,10 +16,10 @@
*/
package brawljars.api.intern.players.battlelog;
-import brawljars.common.PaginationRequest;
-
import lombok.Builder;
+import supercell.api.wrapper.essentials.common.PaginationRequest;
+
import java.util.Map;
public class BattleLogRequest extends PaginationRequest {
diff --git a/src/main/java/brawljars/api/intern/players/battlelog/BattleLogResponse.java b/src/main/java/brawljars/api/intern/players/battlelog/BattleLogResponse.java
index 933266c..0a79b5c 100644
--- a/src/main/java/brawljars/api/intern/players/battlelog/BattleLogResponse.java
+++ b/src/main/java/brawljars/api/intern/players/battlelog/BattleLogResponse.java
@@ -16,6 +16,6 @@
*/
package brawljars.api.intern.players.battlelog;
-import brawljars.common.PaginationResponse;
+import supercell.api.wrapper.essentials.common.PaginationResponse;
public class BattleLogResponse extends PaginationResponse {}
diff --git a/src/main/java/brawljars/api/intern/players/info/PlayerRequest.java b/src/main/java/brawljars/api/intern/players/info/PlayerRequest.java
index 26db76f..a7afcc6 100644
--- a/src/main/java/brawljars/api/intern/players/info/PlayerRequest.java
+++ b/src/main/java/brawljars/api/intern/players/info/PlayerRequest.java
@@ -16,10 +16,10 @@
*/
package brawljars.api.intern.players.info;
-import brawljars.common.Request;
-
import lombok.Builder;
+import supercell.api.wrapper.essentials.common.Request;
+
import java.util.Map;
public class PlayerRequest extends Request {
diff --git a/src/main/java/brawljars/api/intern/players/info/PlayerResponse.java b/src/main/java/brawljars/api/intern/players/info/PlayerResponse.java
index 23d540c..27f383e 100644
--- a/src/main/java/brawljars/api/intern/players/info/PlayerResponse.java
+++ b/src/main/java/brawljars/api/intern/players/info/PlayerResponse.java
@@ -16,14 +16,14 @@
*/
package brawljars.api.intern.players.info;
-import brawljars.common.IResponse;
-import brawljars.common.RawResponse;
-
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.EqualsAndHashCode;
+import supercell.api.wrapper.essentials.common.IResponse;
+import supercell.api.wrapper.essentials.common.RawResponse;
+
@Data
@EqualsAndHashCode(callSuper = true)
public class PlayerResponse extends Player implements IResponse {
diff --git a/src/main/java/brawljars/api/intern/rankings/RankingApi.java b/src/main/java/brawljars/api/intern/rankings/RankingApi.java
index 004736a..d14ec3e 100644
--- a/src/main/java/brawljars/api/intern/rankings/RankingApi.java
+++ b/src/main/java/brawljars/api/intern/rankings/RankingApi.java
@@ -16,7 +16,6 @@
*/
package brawljars.api.intern.rankings;
-import brawljars.api.Api;
import brawljars.api.intern.rankings.brawler.BrawlerRankingsRequest;
import brawljars.api.intern.rankings.brawler.BrawlerRankingsResponse;
import brawljars.api.intern.rankings.club.ClubRankingsRequest;
@@ -28,6 +27,8 @@
import brawljars.api.intern.rankings.powerplay.PowerplayRankingsSeasonsRequest;
import brawljars.api.intern.rankings.powerplay.PowerplayRankingsSeasonsResponse;
+import supercell.api.wrapper.essentials.api.Api;
+
import java.util.concurrent.Future;
public interface RankingApi extends Api {
diff --git a/src/main/java/brawljars/api/intern/rankings/RankingApiImpl.java b/src/main/java/brawljars/api/intern/rankings/RankingApiImpl.java
index ad591f2..6461c37 100644
--- a/src/main/java/brawljars/api/intern/rankings/RankingApiImpl.java
+++ b/src/main/java/brawljars/api/intern/rankings/RankingApiImpl.java
@@ -16,8 +16,6 @@
*/
package brawljars.api.intern.rankings;
-import brawljars.api.ApiContext;
-import brawljars.api.BaseApi;
import brawljars.api.intern.rankings.brawler.BrawlerRankingsRequest;
import brawljars.api.intern.rankings.brawler.BrawlerRankingsResponse;
import brawljars.api.intern.rankings.club.ClubRankingsRequest;
@@ -29,6 +27,9 @@
import brawljars.api.intern.rankings.powerplay.PowerplayRankingsSeasonsRequest;
import brawljars.api.intern.rankings.powerplay.PowerplayRankingsSeasonsResponse;
+import supercell.api.wrapper.essentials.api.ApiContext;
+import supercell.api.wrapper.essentials.api.BaseApi;
+
import java.util.concurrent.Future;
class RankingApiImpl extends BaseApi implements RankingApi {
diff --git a/src/main/java/brawljars/api/intern/rankings/brawler/BrawlerRankingsRequest.java b/src/main/java/brawljars/api/intern/rankings/brawler/BrawlerRankingsRequest.java
index d0171b6..c8d9a4a 100644
--- a/src/main/java/brawljars/api/intern/rankings/brawler/BrawlerRankingsRequest.java
+++ b/src/main/java/brawljars/api/intern/rankings/brawler/BrawlerRankingsRequest.java
@@ -16,10 +16,10 @@
*/
package brawljars.api.intern.rankings.brawler;
-import brawljars.common.PaginationRequest;
-
import lombok.Builder;
+import supercell.api.wrapper.essentials.common.PaginationRequest;
+
import java.util.Map;
public class BrawlerRankingsRequest extends PaginationRequest {
diff --git a/src/main/java/brawljars/api/intern/rankings/brawler/BrawlerRankingsResponse.java b/src/main/java/brawljars/api/intern/rankings/brawler/BrawlerRankingsResponse.java
index bcba9cf..87e1690 100644
--- a/src/main/java/brawljars/api/intern/rankings/brawler/BrawlerRankingsResponse.java
+++ b/src/main/java/brawljars/api/intern/rankings/brawler/BrawlerRankingsResponse.java
@@ -16,6 +16,6 @@
*/
package brawljars.api.intern.rankings.brawler;
-import brawljars.common.PaginationResponse;
+import supercell.api.wrapper.essentials.common.PaginationResponse;
public class BrawlerRankingsResponse extends PaginationResponse {}
diff --git a/src/main/java/brawljars/api/intern/rankings/club/ClubRankingsRequest.java b/src/main/java/brawljars/api/intern/rankings/club/ClubRankingsRequest.java
index 7e12751..eb71b97 100644
--- a/src/main/java/brawljars/api/intern/rankings/club/ClubRankingsRequest.java
+++ b/src/main/java/brawljars/api/intern/rankings/club/ClubRankingsRequest.java
@@ -16,10 +16,10 @@
*/
package brawljars.api.intern.rankings.club;
-import brawljars.common.PaginationRequest;
-
import lombok.Builder;
+import supercell.api.wrapper.essentials.common.PaginationRequest;
+
import java.util.Map;
public class ClubRankingsRequest extends PaginationRequest {
diff --git a/src/main/java/brawljars/api/intern/rankings/club/ClubRankingsResponse.java b/src/main/java/brawljars/api/intern/rankings/club/ClubRankingsResponse.java
index 5c41664..1c8f024 100644
--- a/src/main/java/brawljars/api/intern/rankings/club/ClubRankingsResponse.java
+++ b/src/main/java/brawljars/api/intern/rankings/club/ClubRankingsResponse.java
@@ -16,6 +16,6 @@
*/
package brawljars.api.intern.rankings.club;
-import brawljars.common.PaginationResponse;
+import supercell.api.wrapper.essentials.common.PaginationResponse;
public class ClubRankingsResponse extends PaginationResponse {}
diff --git a/src/main/java/brawljars/api/intern/rankings/player/PlayerRankingsRequest.java b/src/main/java/brawljars/api/intern/rankings/player/PlayerRankingsRequest.java
index 8f23138..33b5fe0 100644
--- a/src/main/java/brawljars/api/intern/rankings/player/PlayerRankingsRequest.java
+++ b/src/main/java/brawljars/api/intern/rankings/player/PlayerRankingsRequest.java
@@ -16,10 +16,10 @@
*/
package brawljars.api.intern.rankings.player;
-import brawljars.common.PaginationRequest;
-
import lombok.Builder;
+import supercell.api.wrapper.essentials.common.PaginationRequest;
+
import java.util.Map;
public class PlayerRankingsRequest extends PaginationRequest {
diff --git a/src/main/java/brawljars/api/intern/rankings/player/PlayerRankingsResponse.java b/src/main/java/brawljars/api/intern/rankings/player/PlayerRankingsResponse.java
index c4bd94e..aed1eb5 100644
--- a/src/main/java/brawljars/api/intern/rankings/player/PlayerRankingsResponse.java
+++ b/src/main/java/brawljars/api/intern/rankings/player/PlayerRankingsResponse.java
@@ -16,6 +16,6 @@
*/
package brawljars.api.intern.rankings.player;
-import brawljars.common.PaginationResponse;
+import supercell.api.wrapper.essentials.common.PaginationResponse;
public class PlayerRankingsResponse extends PaginationResponse {}
diff --git a/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsRequest.java b/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsRequest.java
index b42a3ef..bd48657 100644
--- a/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsRequest.java
+++ b/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsRequest.java
@@ -16,10 +16,10 @@
*/
package brawljars.api.intern.rankings.powerplay;
-import brawljars.common.PaginationRequest;
-
import lombok.Builder;
+import supercell.api.wrapper.essentials.common.PaginationRequest;
+
import java.util.Map;
public class PowerplayRankingsRequest extends PaginationRequest {
diff --git a/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsResponse.java b/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsResponse.java
index 61113d1..26549d3 100644
--- a/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsResponse.java
+++ b/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsResponse.java
@@ -16,6 +16,6 @@
*/
package brawljars.api.intern.rankings.powerplay;
-import brawljars.common.PaginationResponse;
+import supercell.api.wrapper.essentials.common.PaginationResponse;
public class PowerplayRankingsResponse extends PaginationResponse {}
diff --git a/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsSeasonsRequest.java b/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsSeasonsRequest.java
index 78baf58..c0b8ded 100644
--- a/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsSeasonsRequest.java
+++ b/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsSeasonsRequest.java
@@ -16,10 +16,10 @@
*/
package brawljars.api.intern.rankings.powerplay;
-import brawljars.common.PaginationRequest;
-
import lombok.Builder;
+import supercell.api.wrapper.essentials.common.PaginationRequest;
+
import java.util.Map;
public class PowerplayRankingsSeasonsRequest extends PaginationRequest {
diff --git a/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsSeasonsResponse.java b/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsSeasonsResponse.java
index 9f63f4c..cd484d5 100644
--- a/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsSeasonsResponse.java
+++ b/src/main/java/brawljars/api/intern/rankings/powerplay/PowerplayRankingsSeasonsResponse.java
@@ -16,6 +16,6 @@
*/
package brawljars.api.intern.rankings.powerplay;
-import brawljars.common.PaginationResponse;
+import supercell.api.wrapper.essentials.common.PaginationResponse;
public class PowerplayRankingsSeasonsResponse extends PaginationResponse {}
diff --git a/src/main/java/brawljars/build/ReleaseVersionChecker.java b/src/main/java/brawljars/build/ReleaseVersionChecker.java
deleted file mode 100644
index f317417..0000000
--- a/src/main/java/brawljars/build/ReleaseVersionChecker.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package brawljars.build;
-
-import lombok.extern.slf4j.Slf4j;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-@Slf4j
-public class ReleaseVersionChecker {
-
- public static void main(String[] args) {
- String versionTxt = readFileToString(args[0]).substring(1);
- String pom = readFileToString(args[1]);
- int start = pom.indexOf("");
- int end = pom.indexOf("");
- String pomVersion = pom.substring(start + 9, end);
- if (!versionTxt.equals(pomVersion)) {
- log.error("*************************************************");
- log.error("*** POM VERSION DON'T MATCHES VERSION.TXT !!! ***");
- log.error("*************************************************");
- throw new IllegalStateException("Versions are not matching!");
- }
- }
-
- private static String readFileToString(String filename) {
- File file = new File(filename);
- try (FileInputStream fileInputStream = new FileInputStream(file)) {
- return new String(fileInputStream.readAllBytes());
- } catch (IOException e) {
- throw new IllegalStateException(
- "release version checker could not read file: " + filename);
- }
- }
-}
diff --git a/src/main/java/brawljars/common/IResponse.java b/src/main/java/brawljars/common/IResponse.java
deleted file mode 100644
index d929e95..0000000
--- a/src/main/java/brawljars/common/IResponse.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.common;
-
-public interface IResponse {
-
- String getMessage();
-
- void setMessage(String message);
-
- String getReason();
-
- void setReason(String reason);
-
- RawResponse getRawResponse();
-
- void setRawResponse(RawResponse rawResponse);
-}
diff --git a/src/main/java/brawljars/common/PaginationRequest.java b/src/main/java/brawljars/common/PaginationRequest.java
deleted file mode 100644
index 69755bc..0000000
--- a/src/main/java/brawljars/common/PaginationRequest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.common;
-
-import static brawljars.common.Utils.isNotBlank;
-
-import java.util.Map;
-
-public class PaginationRequest extends Request {
-
- static final String QUERY_PARAM_LIMIT = "limit";
- static final String QUERY_PARAM_AFTER = "after";
- static final String QUERY_PARAM_BEFORE = "before";
-
- private final int limit;
-
- private final String after;
- private final String before;
-
- protected PaginationRequest(int limit, String after, String before, boolean storeRawResponse) {
- super(storeRawResponse);
- this.limit = limit;
- this.after = after;
- this.before = before;
- }
-
- public Map getQueryParameters() {
- Map map = super.getQueryParameters();
- if (limit > 0) {
- map.put(QUERY_PARAM_LIMIT, String.valueOf(limit));
- }
- if (isNotBlank(after)) {
- map.put(QUERY_PARAM_AFTER, after);
- }
- if (isNotBlank(before)) {
- map.put(QUERY_PARAM_BEFORE, before);
- }
- return map;
- }
-}
diff --git a/src/main/java/brawljars/common/PaginationResponse.java b/src/main/java/brawljars/common/PaginationResponse.java
deleted file mode 100644
index ef98132..0000000
--- a/src/main/java/brawljars/common/PaginationResponse.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.common;
-
-import com.google.gson.annotations.SerializedName;
-
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.ToString;
-
-import java.util.Collection;
-
-@Data
-@EqualsAndHashCode(callSuper = true)
-@ToString(callSuper = true)
-public class PaginationResponse extends Response {
-
- @SerializedName("items")
- private Collection items;
-
- @SerializedName("paging")
- private Paging paging;
-
- @Data
- public static class Paging {
-
- @SerializedName("cursors")
- private Cursors cursors;
-
- @Data
- public static class Cursors {
-
- @SerializedName("after")
- private String after;
-
- @SerializedName("before")
- private String before;
- }
- }
-}
diff --git a/src/main/java/brawljars/common/RawResponse.java b/src/main/java/brawljars/common/RawResponse.java
deleted file mode 100644
index 4925a8a..0000000
--- a/src/main/java/brawljars/common/RawResponse.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.common;
-
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-
-import java.util.HashMap;
-import java.util.Map;
-
-@Getter
-@Setter
-@ToString
-public class RawResponse {
-
- private final Map responseHeaders = new HashMap<>();
-
- private String raw;
-}
diff --git a/src/main/java/brawljars/common/Request.java b/src/main/java/brawljars/common/Request.java
deleted file mode 100644
index 469c84c..0000000
--- a/src/main/java/brawljars/common/Request.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.common;
-
-import lombok.Getter;
-
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-@Getter
-public class Request {
-
- private final boolean storeRawResponse;
-
- protected Request(boolean storeRawResponse) {
- this.storeRawResponse = storeRawResponse;
- }
-
- public Map getQueryParameters() {
- return new LinkedHashMap<>();
- }
-
- public Map getRestParameters() {
- return new HashMap<>();
- }
-}
diff --git a/src/main/java/brawljars/common/Response.java b/src/main/java/brawljars/common/Response.java
deleted file mode 100644
index 926cdd0..0000000
--- a/src/main/java/brawljars/common/Response.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.common;
-
-import com.google.gson.annotations.SerializedName;
-
-import lombok.Data;
-
-@Data
-public class Response implements IResponse {
-
- @SerializedName("reason")
- private String reason;
-
- @SerializedName("message")
- private String message;
-
- private transient RawResponse rawResponse;
-}
diff --git a/src/main/java/brawljars/common/Utils.java b/src/main/java/brawljars/common/Utils.java
deleted file mode 100644
index 062d133..0000000
--- a/src/main/java/brawljars/common/Utils.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.common;
-
-import java.util.Map;
-
-public class Utils {
-
- public static boolean isNotEmpty(Map, ?> map) {
- return map != null && !map.isEmpty();
- }
-
- public static boolean isNotEmpty(Object[] array) {
- return array != null && array.length > 0;
- }
-
- public static boolean isBlank(String s) {
- return s == null || s.isEmpty();
- }
-
- public static boolean isNotBlank(String s) {
- return !isBlank(s);
- }
-
- public static void require(String key, String s) {
- if (isBlank(s)) {
- throw new IllegalArgumentException(key + " must be set! But was: " + s);
- }
- }
-
- public static void require(String key, Object o) {
- if (o == null) {
- throw new IllegalArgumentException(key + " must be set!");
- }
- }
-}
diff --git a/src/main/java/brawljars/connector/Connector.java b/src/main/java/brawljars/connector/Connector.java
deleted file mode 100644
index 3d1a733..0000000
--- a/src/main/java/brawljars/connector/Connector.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.connector;
-
-import brawljars.common.IResponse;
-
-public interface Connector {
-
- T get(RequestContext requestContext) throws ConnectorException;
-}
diff --git a/src/main/java/brawljars/connector/ConnectorException.java b/src/main/java/brawljars/connector/ConnectorException.java
deleted file mode 100644
index 0e8c8fe..0000000
--- a/src/main/java/brawljars/connector/ConnectorException.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.connector;
-
-
-public class ConnectorException extends RuntimeException {
-
- public ConnectorException(String s) {
- super(s);
- }
-
- public ConnectorException(Exception e) {
- super(e);
- }
-}
diff --git a/src/main/java/brawljars/connector/RequestContext.java b/src/main/java/brawljars/connector/RequestContext.java
deleted file mode 100644
index 7d53d8c..0000000
--- a/src/main/java/brawljars/connector/RequestContext.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.connector;
-
-import brawljars.common.Request;
-
-public record RequestContext(String url, String apiKey, Request request, Class> responseClass) {}
diff --git a/src/main/java/brawljars/connector/StandardConnector.java b/src/main/java/brawljars/connector/StandardConnector.java
deleted file mode 100644
index 4912507..0000000
--- a/src/main/java/brawljars/connector/StandardConnector.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.connector;
-
-import static brawljars.common.Utils.isNotEmpty;
-import static brawljars.common.Utils.require;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-
-import brawljars.common.IResponse;
-import brawljars.common.RawResponse;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-import lombok.extern.slf4j.Slf4j;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URLEncoder;
-import java.net.http.HttpClient;
-import java.net.http.HttpHeaders;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-@Slf4j
-public class StandardConnector implements Connector {
-
- private static final Gson GSON = new GsonBuilder().disableHtmlEscaping().create();
-
- @Override
- public T get(RequestContext requestContext) throws ConnectorException {
- require("requestContext", requestContext);
- try {
- String url = requestContext.url();
- String replacedUrl =
- appendToUrl(
- url,
- requestContext.request().getQueryParameters(),
- requestContext.request().getRestParameters());
- String json = getInitialValue(replacedUrl);
- boolean makeRequest = json == null || json.isEmpty();
- HttpResponse response = null;
- if (makeRequest) {
- HttpRequest request =
- HttpRequest.newBuilder()
- .uri(new URI(replacedUrl))
- .header("Authorization", "Bearer " + requestContext.apiKey())
- .GET()
- .build();
- response =
- HttpClient.newBuilder()
- .build()
- .send(request, HttpResponse.BodyHandlers.ofString());
- logResponse(response);
- if (response.statusCode() != 200) {
- throw new ConnectorException(String.valueOf(response.statusCode()));
- }
- json = response.body();
- onJsonReceived(replacedUrl, json);
- }
- HttpResponse checkedResponse = checkResponse(json, response);
- log.info(" response content: {}", json);
- T result = (T) GSON.fromJson(json, requestContext.responseClass());
- if (requestContext.request().isStoreRawResponse()) {
- setRawResponse(result, json, checkedResponse);
- }
- return result;
- } catch (InterruptedException | URISyntaxException | IOException e) {
- throw new ConnectorException(e);
- }
- }
-
- private String appendToUrl(
- String url, Map parameters, Map restParameters) {
- StringBuilder appendedUrl = new StringBuilder(url);
- List queries = new ArrayList<>();
- if (isNotEmpty(parameters)) {
- for (Map.Entry entry : parameters.entrySet()) {
- String name = entry.getKey();
- Object value = entry.getValue();
- if (value != null) {
- queries.add(name + '=' + encode(String.valueOf(value)));
- }
- }
- if (!queries.isEmpty()) {
- appendedUrl.append('?');
- for (Iterator iterator = queries.iterator(); iterator.hasNext(); ) {
- appendedUrl.append(iterator.next());
- if (iterator.hasNext()) {
- appendedUrl.append('&');
- }
- }
- }
- }
- String result = appendedUrl.toString();
- for (Map.Entry entry : restParameters.entrySet()) {
- String encodedValue = encode(String.valueOf(entry.getValue()));
- result = result.replace('{' + entry.getKey() + '}', encodedValue);
- }
- log.info("request to: {}", result);
- return result;
- }
-
- private static String encode(String s) {
- return URLEncoder.encode(s, UTF_8);
- }
-
- protected String getInitialValue(String url) throws IOException {
- return null;
- }
-
- private static void logResponse(HttpResponse httpResponse) {
- if (log.isInfoEnabled()) {
- for (Map.Entry> entry : httpResponse.headers().map().entrySet()) {
- String name = entry.getKey();
- List values = entry.getValue();
- log.info(" response header: {}={}", name, String.join(",", values));
- }
- int code = httpResponse.statusCode();
- log.info(" status code: {}- {}", code, httpResponse.body());
- }
- }
-
- protected void onJsonReceived(String url, String json) throws IOException {
- // do nothing here
- }
-
- protected HttpResponse checkResponse(String json, HttpResponse response) {
- return response;
- }
-
- private void setRawResponse(
- T result, String json, HttpResponse response) {
- RawResponse rawResponse = new RawResponse();
- rawResponse.setRaw(json);
- HttpHeaders headers = response.headers();
- if (headers != null) {
- for (Map.Entry> entry : headers.map().entrySet()) {
- String name = entry.getKey();
- List values = entry.getValue();
- rawResponse
- .getResponseHeaders()
- .put(name.toLowerCase(Locale.ROOT), String.join(",", values));
- }
- }
- result.setRawResponse(rawResponse);
- }
-}
diff --git a/src/test/java/brawljars/BrawlJarsTest.java b/src/test/java/brawljars/BrawlJarsTest.java
index 13be744..aef0762 100644
--- a/src/test/java/brawljars/BrawlJarsTest.java
+++ b/src/test/java/brawljars/BrawlJarsTest.java
@@ -20,11 +20,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import brawljars.api.Api;
-import brawljars.api.ApiContext;
-import brawljars.api.BaseApi;
import brawljars.api.intern.players.PlayerApi;
-import brawljars.connector.Connector;
import lombok.NonNull;
@@ -36,6 +32,11 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+import supercell.api.wrapper.essentials.api.Api;
+import supercell.api.wrapper.essentials.api.ApiContext;
+import supercell.api.wrapper.essentials.api.BaseApi;
+import supercell.api.wrapper.essentials.connector.Connector;
+
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -95,6 +96,12 @@ void registerAndGetApi_whenWithValidParameter_shouldRegister() {
assertNotNull(actual);
}
+ @Test
+ void getApi_whenClassNotFound_thenThrowException() {
+
+ assertThrows(IllegalStateException.class, () -> unitUnderTest.getApi(FooApi.class));
+ }
+
public interface FooApi extends Api {}
public static class FooApiImpl extends BaseApi implements FooApi {
diff --git a/src/test/java/brawljars/EndToEnd.java b/src/test/java/brawljars/EndToEnd.java
index faf4586..f564af8 100644
--- a/src/test/java/brawljars/EndToEnd.java
+++ b/src/test/java/brawljars/EndToEnd.java
@@ -20,7 +20,6 @@
import static wiremock.org.apache.commons.lang3.StringUtils.EMPTY;
-import brawljars.api.connector.FilesystemCachedConnector;
import brawljars.api.intern.brawlers.BrawlerApi;
import brawljars.api.intern.brawlers.BrawlerRequest;
import brawljars.api.intern.brawlers.BrawlerResponse;
@@ -57,6 +56,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import supercell.api.wrapper.essentials.connector.FilesystemCachedConnector;
+
import java.io.StringReader;
import javax.json.Json;
@@ -89,7 +90,7 @@ void setUp() {
new BrawlJars(
"https://bsproxy.royaleapi.dev/v1",
System.getProperty("apiKey", System.getenv("API_KEY")),
- new FilesystemCachedConnector());
+ new FilesystemCachedConnector("brawljars"));
brawlerApi = brawlJars.getApi(BrawlerApi.class);
rankingApi = brawlJars.getApi(RankingApi.class);
playerApi = brawlJars.getApi(PlayerApi.class);
diff --git a/src/test/java/brawljars/IntegrationTestBase.java b/src/test/java/brawljars/IntegrationTestBase.java
index 1db3aca..ec2979b 100644
--- a/src/test/java/brawljars/IntegrationTestBase.java
+++ b/src/test/java/brawljars/IntegrationTestBase.java
@@ -37,11 +37,6 @@
import static java.util.Collections.emptyMap;
-import brawljars.common.IResponse;
-import brawljars.common.PaginationRequest;
-import brawljars.common.Request;
-import brawljars.connector.StandardConnector;
-
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.google.gson.Gson;
@@ -51,6 +46,11 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
+import supercell.api.wrapper.essentials.common.IResponse;
+import supercell.api.wrapper.essentials.common.PaginationRequest;
+import supercell.api.wrapper.essentials.common.Request;
+import supercell.api.wrapper.essentials.connector.StandardConnector;
+
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -149,7 +149,9 @@ protected void prepareWithErrorAndRun(
testRunner.execute();
fail();
} catch (Exception e) {
- assertEquals("brawljars.connector.ConnectorException: 400", e.getMessage());
+ assertEquals(
+ "supercell.api.wrapper.essentials.connector.ConnectorException: 400",
+ e.getMessage());
}
}
diff --git a/src/test/java/brawljars/api/ApiContextTest.java b/src/test/java/brawljars/api/ApiContextTest.java
deleted file mode 100644
index 4cf1a16..0000000
--- a/src/test/java/brawljars/api/ApiContextTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.api;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-import brawljars.connector.Connector;
-
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.CsvSource;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-@ExtendWith(MockitoExtension.class)
-class ApiContextTest {
-
- private static final String API_KEY = "apiKey";
- private static final String URL = "url";
-
- @Mock private Connector connector;
-
- @ParameterizedTest
- @CsvSource(value = "null,", nullValues = "null")
- void construct_withoutUrl_shouldThrowException(String actual) {
-
- assertThrows(
- IllegalArgumentException.class, () -> new ApiContext(actual, API_KEY, connector));
- }
-
- @ParameterizedTest
- @CsvSource(value = "null,", nullValues = "null")
- void construct_withoutApiKey_shouldThrowException(String actual) {
-
- assertThrows(IllegalArgumentException.class, () -> new ApiContext(URL, actual, connector));
- }
-
- @Test
- void construct_withoutConnector_shouldThrowException() {
-
- assertThrows(IllegalArgumentException.class, () -> new ApiContext(URL, API_KEY, null));
- }
-
- @Test
- void construct_whenWithParameters_shouldSetValues() {
- ApiContext actual = new ApiContext(URL, API_KEY, connector);
-
- assertEquals(URL, actual.url());
- assertEquals(API_KEY, actual.apiKey());
- assertEquals(connector, actual.connector());
- }
-}
diff --git a/src/test/java/brawljars/api/BaseApiTest.java b/src/test/java/brawljars/api/BaseApiTest.java
deleted file mode 100644
index e2be9bc..0000000
--- a/src/test/java/brawljars/api/BaseApiTest.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package brawljars.api;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.argThat;
-import static org.mockito.Mockito.when;
-
-import static wiremock.org.apache.commons.lang3.StringUtils.EMPTY;
-
-import brawljars.common.PaginationRequest;
-import brawljars.common.PaginationResponse;
-import brawljars.connector.Connector;
-import brawljars.connector.ConnectorException;
-import brawljars.connector.RequestContext;
-
-import lombok.Getter;
-import lombok.Setter;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.ArgumentMatcher;
-import org.mockito.Mock;
-import org.mockito.junit.jupiter.MockitoExtension;
-
-import java.util.Map;
-import java.util.concurrent.ExecutionException;
-
-@ExtendWith(MockitoExtension.class)
-class BaseApiTest {
-
- private static final String API_KEY = "apiKey";
- private static final String PART = "part";
- private static final String URL = "url";
-
- private BaseApi unitUnderTest;
-
- @Mock private Connector connector;
-
- private PaginationRequest request;
-
- private static ArgumentMatcher createRequestContextArgumentMatcher(
- RequestContext expected) {
- return actual -> {
- assertEquals(expected, actual);
- return true;
- };
- }
-
- @BeforeEach
- void setUp() {
- ApiContext apiContext = new ApiContext(URL, API_KEY, connector);
- request = new FooRequest(100, "after", "before", true);
- unitUnderTest = new BaseApi(apiContext);
- }
-
- @Test
- void get_whenWithNullPart_shouldThrowException() {
-
- assertThrows(
- IllegalArgumentException.class,
- () -> unitUnderTest.get(null, request, FooResponse.class));
- }
-
- @Test
- void get_whenWithEmptyPart_shouldThrowException() {
-
- assertThrows(
- IllegalArgumentException.class,
- () -> unitUnderTest.get(EMPTY, request, FooResponse.class));
- }
-
- @Test
- void get_whenWithNullRequest_shouldThrowException() {
-
- assertThrows(
- IllegalArgumentException.class,
- () -> unitUnderTest.get(URL, null, FooResponse.class));
- }
-
- @Test
- void get_whenWithNullResponseClass_shouldThrowException() {
-
- assertThrows(IllegalArgumentException.class, () -> unitUnderTest.get(URL, request, null));
- }
-
- @Test
- void get_whenWithConnectorException_shouldThrowApiException() {
- when(connector.get(any(RequestContext.class))).thenThrow(ConnectorException.class);
-
- assertThrows(
- ExecutionException.class,
- () -> unitUnderTest.get(URL, request, FooResponse.class).get());
- }
-
- @Test
- void get_whenWithException_shouldThrowIllegalStateException() {
- when(connector.get(any(RequestContext.class))).thenThrow(IllegalStateException.class);
-
- assertThrows(
- ExecutionException.class,
- () -> unitUnderTest.get(URL, request, FooResponse.class).get());
- }
-
- @Test
- void get_whenWithValidParameters_shouldReturnResponse() throws Exception {
- FooResponse expected = new FooResponse();
- RequestContext requestContext =
- new RequestContext(URL + PART, API_KEY, request, FooResponse.class);
- when(connector.get(argThat(createRequestContextArgumentMatcher(requestContext))))
- .thenReturn(expected);
-
- FooResponse actual = unitUnderTest.get(PART, request, FooResponse.class).get();
-
- assertEquals(expected, actual);
- }
-
- @Getter
- @Setter
- static class FooResponse extends PaginationResponse {}
-
- @Getter
- @Setter
- static class FooRequest extends PaginationRequest {
-
- protected FooRequest(int limit, String after, String before, boolean storeRawResponse) {
- super(limit, after, before, storeRawResponse);
- }
-
- @Override
- public Map getRestParameters() {
- Map map = super.getRestParameters();
- map.put("param", "value");
- return map;
- }
- }
-}
diff --git a/src/test/java/brawljars/api/connector/FilesystemCachedConnector.java b/src/test/java/brawljars/api/connector/FilesystemCachedConnector.java
deleted file mode 100644
index 9901f54..0000000
--- a/src/test/java/brawljars/api/connector/FilesystemCachedConnector.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package brawljars.api.connector;
-
-import brawljars.connector.StandardConnector;
-
-import lombok.extern.slf4j.Slf4j;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URI;
-import java.net.http.HttpClient;
-import java.net.http.HttpHeaders;
-import java.net.http.HttpRequest;
-import java.net.http.HttpResponse;
-import java.nio.file.Files;
-import java.time.Duration;
-import java.util.Date;
-import java.util.Optional;
-
-import javax.net.ssl.SSLSession;
-
-@Slf4j
-public class FilesystemCachedConnector extends StandardConnector {
-
- public static final Duration CACHE_TIMEOUT = Duration.ofMinutes(5);
-
- private static final File DIR = new File(System.getProperty("java.io.tmpdir") + "/brawljars");
-
- static {
- if (!DIR.mkdirs()) {
- log.warn("couldn't create tmp dir {}", DIR.getAbsolutePath());
- }
- }
-
- @Override
- protected String getInitialValue(String url) throws IOException {
- String json = null;
- String hash = String.valueOf(url.hashCode());
- File file = new File(DIR, hash + ".json");
- boolean makeRequest;
- if (file.exists()) {
- log.info("found cached file {} for {}", file.getAbsolutePath(), url);
- long millis = file.lastModified();
- long validTo = millis + CACHE_TIMEOUT.toMillis();
- Date now = new Date();
- json = Files.readString(file.toPath());
- makeRequest = json == null || json.isEmpty() || now.getTime() > validTo;
- if (makeRequest) {
- log.info(
- "cached file {} with size {} at {} for {} was invalid at {}",
- file.getAbsolutePath(),
- json != null ? json.length() : 0,
- new Date(validTo),
- url,
- now);
- json = null;
- } else {
- log.info("use cached file {} for {}", file.getAbsolutePath(), url);
- }
- } else {
- log.info("no cached file {} found for {}", file.getAbsolutePath(), url);
- }
- return json;
- }
-
- @Override
- protected HttpResponse checkResponse(String json, HttpResponse response) {
- return new CachedHttpResponse<>(200, json);
- }
-
- @Override
- protected void onJsonReceived(String url, String json) throws IOException {
- if (json == null || json.isEmpty()) {
- log.info("received empty JSON for {}, skip saving.", url);
- return;
- }
- String hash = String.valueOf(url.hashCode());
- File file = new File(DIR, hash + ".json");
- Files.writeString(file.toPath(), json);
- log.info("save file {} for cache of {}", file.getAbsolutePath(), url);
- }
-
- record CachedHttpResponse(int statusCode, T body) implements HttpResponse {
-
- @Override
- public HttpRequest request() {
- return null;
- }
-
- @Override
- public Optional> previousResponse() {
- return Optional.empty();
- }
-
- @Override
- public HttpHeaders headers() {
- return null;
- }
-
- @Override
- public Optional sslSession() {
- return Optional.empty();
- }
-
- @Override
- public URI uri() {
- return null;
- }
-
- @Override
- public HttpClient.Version version() {
- return HttpClient.Version.HTTP_1_1;
- }
- }
-}