Skip to content

Commit

Permalink
Add new endpoint /leaderboards/{leaderboardId} (#199)
Browse files Browse the repository at this point in the history
* Add new endpoint /leaderboards/{leaderboardId}

* Correct version

* Upgrade wiremock
  • Loading branch information
mlieshoff authored Jun 25, 2024
1 parent 66d9ac8 commit 18cd687
Show file tree
Hide file tree
Showing 13 changed files with 360 additions and 8 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## [4.0.8] - 2024-06-25

### Added

- New endpoint /leaderboard/{leaderboardId} (#196)

## [4.0.7] - 2024-06-25

### Added
Expand Down Expand Up @@ -239,7 +245,9 @@

- Create a Release job (#152)

[unreleased]: https://github.com/mlieshoff/jcrapi2/compare/v4.0.7...HEAD
[unreleased]: https://github.com/mlieshoff/jcrapi2/compare/v4.0.8...HEAD
[4.0.8]: https://github.com/mlieshoff/jcrapi2/compare/v4.0.7...4.0.8
[4.0.7]: https://github.com/mlieshoff/jcrapi2/compare/v4.0.6...4.0.7
[4.0.6]: https://github.com/mlieshoff/jcrapi2/compare/v4.0.5...4.0.6
[4.0.5]: https://github.com/mlieshoff/jcrapi2/compare/v4.0.4...4.0.5
[4.0.4]: https://github.com/mlieshoff/jcrapi2/compare/v4.0.3...4.0.4
Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![](https://img.shields.io/badge/java-packagecloud.io-844fec.svg)](https://packagecloud.io/)
[![Nightlies](https://github.com/mlieshoff/jcrapi2/actions/workflows/nightlies.yml/badge.svg)](https://github.com/mlieshoff/jcrapi2/actions/workflows/nightlies.yml)

# jcrapi2 4.0.7
# jcrapi2 4.0.8
A Java Wrapper For Official Supercell Clash Royal Api

## Why we don't use the Swagger scheme?
Expand Down Expand Up @@ -434,6 +434,19 @@ list all supported apis
.build()
).get();
```
```java
// findById
LeaderboardResponse response = api.findById(leaderboardRequest.builder()
.leaderboardId()
// pagination
.limit()
.after()
.before()
// store raw response
.storeRawResponse()
.build()
).get();
```

## Add or replace registered API's

Expand Down Expand Up @@ -471,15 +484,15 @@ All requests are returning *java.concurrent.Future*. The execution will be async

to Gradle:
```groovy
implementation group: 'jcrapi2', name: 'jcrapi2', version: '4.0.7'
implementation group: 'jcrapi2', name: 'jcrapi2', version: '4.0.8'
```

to Maven:
```xml
<dependency>
<groupId>jcrapi2</groupId>
<artifactId>jcrapi2</artifactId>
<version>4.0.7</version>
<version>4.0.8</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v4.0.7
v4.0.8
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>jcrapi2</artifactId>
<packaging>jar</packaging>
<version>4.0.7</version>
<version>4.0.8</version>
<groupId>jcrapi2</groupId>
<url>https://maven.apache.org</url>
<inceptionYear>2018</inceptionYear>
Expand Down Expand Up @@ -49,7 +49,7 @@
<version.mockito>5.11.0</version.mockito>
<version.slf4j>2.0.13</version.slf4j>
<version.supercell.api.wrapper.essentials>1.0.1</version.supercell.api.wrapper.essentials>
<version.wiremock>3.5.4</version.wiremock>
<version.wiremock>3.7.0</version.wiremock>
</properties>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
*/
package jcrapi2.api.intern.leaderboards;

import jcrapi2.api.intern.leaderboards.info.LeaderboardRequest;
import jcrapi2.api.intern.leaderboards.info.LeaderboardResponse;

import supercell.api.wrapper.essentials.api.Api;

import java.util.concurrent.Future;

public interface LeaderboardApi extends Api {

Future<LeaderboardsResponse> findAll(LeaderboardsRequest leaderboardsRequest);

Future<LeaderboardResponse> findById(LeaderboardRequest leaderboardRequest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package jcrapi2.api.intern.leaderboards;

import jcrapi2.api.intern.leaderboards.info.LeaderboardRequest;
import jcrapi2.api.intern.leaderboards.info.LeaderboardResponse;

import supercell.api.wrapper.essentials.api.ApiContext;
import supercell.api.wrapper.essentials.api.BaseApi;

Expand All @@ -31,4 +34,8 @@ class LeaderboardApiImpl extends BaseApi implements LeaderboardApi {
public Future<LeaderboardsResponse> findAll(LeaderboardsRequest leaderboardsRequest) {
return get("/leaderboards", leaderboardsRequest, LeaderboardsResponse.class);
}

public Future<LeaderboardResponse> findById(LeaderboardRequest leaderboardRequest) {
return get("/leaderboard/{leaderboardId}", leaderboardRequest, LeaderboardResponse.class);
}
}
34 changes: 34 additions & 0 deletions src/main/java/jcrapi2/api/intern/leaderboards/info/Clan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 jcrapi2.api.intern.leaderboards.info;

import com.google.gson.annotations.SerializedName;

import lombok.Data;

@Data
public class Clan {

@SerializedName("tag")
private String tag;

@SerializedName("name")
private String name;

@SerializedName("badgeId")
private long badgeId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 jcrapi2.api.intern.leaderboards.info;

import com.google.gson.annotations.SerializedName;

import lombok.Data;

@Data
public class Leaderboard {

@SerializedName("tag")
private String tag;

@SerializedName("name")
private String name;

@SerializedName("score")
private int score;

@SerializedName("rank")
private int rank;

@SerializedName("clan")
private Clan clan;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 jcrapi2.api.intern.leaderboards.info;

import lombok.Builder;

import supercell.api.wrapper.essentials.common.PaginationRequest;

import java.util.Map;

public class LeaderboardRequest extends PaginationRequest {

private final long leaderboardId;

@Builder
private LeaderboardRequest(
int limit, String after, String before, boolean storeRawResponse, long leaderboardId) {
super(limit, after, before, storeRawResponse);
this.leaderboardId = leaderboardId;
}

public static LeaderboardRequestBuilder builder(long leaderboardId) {
return new LeaderboardRequestBuilder().leaderboardId(leaderboardId);
}

@Override
public Map<String, Object> getRestParameters() {
Map<String, Object> map = super.getRestParameters();
map.put("leaderboardId", leaderboardId);
return map;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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 jcrapi2.api.intern.leaderboards.info;

import supercell.api.wrapper.essentials.common.PaginationResponse;

public class LeaderboardResponse extends PaginationResponse<Leaderboard> {}
29 changes: 28 additions & 1 deletion src/test/java/jcrapi2/EndToEnd.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import jcrapi2.api.intern.leaderboards.LeaderboardApi;
import jcrapi2.api.intern.leaderboards.LeaderboardsRequest;
import jcrapi2.api.intern.leaderboards.LeaderboardsResponse;
import jcrapi2.api.intern.leaderboards.info.LeaderboardRequest;
import jcrapi2.api.intern.leaderboards.info.LeaderboardResponse;
import jcrapi2.api.intern.locations.LocationApi;
import jcrapi2.api.intern.locations.LocationsRequest;
import jcrapi2.api.intern.locations.LocationsResponse;
Expand Down Expand Up @@ -89,17 +91,20 @@
import jcrapi2.api.intern.tournaments.info.TournamentRequest;
import jcrapi2.api.intern.tournaments.info.TournamentResponse;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import supercell.api.wrapper.essentials.connector.FilesystemCachedConnector;

import java.io.StringReader;
import java.util.concurrent.ExecutionException;

import javax.json.Json;
import javax.json.JsonPatch;
import javax.json.JsonValue;

@Slf4j
class EndToEnd {

private static final Gson GSON = new GsonBuilder().disableHtmlEscaping().create();
Expand All @@ -112,6 +117,7 @@ class EndToEnd {
private static final String TOURNAMENT_TAG = "#U2QQQL2";
private static final String SEASON_ID = "2022-04";

private static final long LEADERBOARD_ID = 170000001L;
private static final long LOCATION_ID = 57000256L;

private ClanApi clanApi;
Expand Down Expand Up @@ -583,4 +589,25 @@ void leaderboards_findAll() throws Exception {

assertDiff(expected, actual);
}
}

@Test
void leaderboards_findById() throws Exception {
try {
LeaderboardResponse response =
leaderboardApi
.findById(
LeaderboardRequest.builder(LEADERBOARD_ID)
.storeRawResponse(true)
.limit(10)
.build())
.get();
String actual = GSON.toJson(response);
String expected = response.getRawResponse().getRaw();

assertDiff(expected, actual);
} catch (ExecutionException e) {
log.warn("FLAKE TEST DETECTED: leaderboards_findById", e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,41 @@ void findAll_whenWithException() {
prepareWithErrorAndRun(
"/leaderboards", EMPTY, request, () -> unitUnderTest.findAll(request).get());
}

@Test
void findById() throws Exception {
long leaderboardId = 4711L;
jcrapi2.api.intern.leaderboards.info.LeaderboardRequest.LeaderboardRequestBuilder builder =
jcrapi2.api.intern.leaderboards.info.LeaderboardRequest.builder(leaderboardId);
jcrapi2.api.intern.leaderboards.info.LeaderboardRequest request =
builder.limit(100).before("zzz").after("aaa").storeRawResponse(true).build();
prepare(
"/leaderboard/{leaderboardId}"
.replace("{leaderboardId}", String.valueOf(leaderboardId)),
EMPTY,
"src/test/resources/leaderboard-findById.json",
request);
jcrapi2.api.intern.leaderboards.info.LeaderboardResponse expected =
toJson(
jcrapi2.api.intern.leaderboards.info.LeaderboardResponse.class,
getExpected());

run(expected, () -> unitUnderTest.findById(request).get());
}

@Test
void findById_whenWithException() {
long leaderboardId = 4711L;
jcrapi2.api.intern.leaderboards.info.LeaderboardRequest.LeaderboardRequestBuilder builder =
jcrapi2.api.intern.leaderboards.info.LeaderboardRequest.builder(leaderboardId);
jcrapi2.api.intern.leaderboards.info.LeaderboardRequest request =
builder.limit(100).before("zzz").after("aaa").storeRawResponse(true).build();

prepareWithErrorAndRun(
"/leaderboard/{leaderboardId}"
.replace("{leaderboardId}", String.valueOf(leaderboardId)),
EMPTY,
request,
() -> unitUnderTest.findById(request).get());
}
}
Loading

0 comments on commit 18cd687

Please sign in to comment.