Skip to content

Commit

Permalink
Add new endpoint /leaderboards (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlieshoff authored Jun 25, 2024
1 parent c8122dd commit 66d9ac8
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 8 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

## [4.0.7] - 2024-06-25

### Added

- New endpoint /leaderboards (#196)

## [4.0.6] - 2024-06-25

### Changed
Expand Down Expand Up @@ -233,7 +239,7 @@

- Create a Release job (#152)

[unreleased]: https://github.com/mlieshoff/jcrapi2/compare/v4.0.6...HEAD
[unreleased]: https://github.com/mlieshoff/jcrapi2/compare/v4.0.7...HEAD
[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
23 changes: 20 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.6
# jcrapi2 4.0.7
A Java Wrapper For Official Supercell Clash Royal Api

## Why we don't use the Swagger scheme?
Expand Down Expand Up @@ -417,6 +417,23 @@ list all supported apis
.build()
).get();
```
#### LeaderboardApi
```java
// create an instance for the api
LeaderboardApi api = jCrApi.getApi(LeaderboardApi.class);
```
```java
// findAll
LeaderboardsResponse response = api.findAll(leaderboardsRequest.builder()
// pagination
.limit()
.after()
.before()
// store raw response
.storeRawResponse()
.build()
).get();
```

## Add or replace registered API's

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

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

to Maven:
```xml
<dependency>
<groupId>jcrapi2</groupId>
<artifactId>jcrapi2</artifactId>
<version>4.0.6</version>
<version>4.0.7</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.6
v4.0.7
2 changes: 1 addition & 1 deletion 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.6</version>
<version>4.0.7</version>
<groupId>jcrapi2</groupId>
<url>https://maven.apache.org</url>
<inceptionYear>2018</inceptionYear>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/jcrapi2/api/intern/DefaultApiClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import jcrapi2.api.intern.challenges.ChallengeApi;
import jcrapi2.api.intern.clans.ClanApi;
import jcrapi2.api.intern.globaltournaments.GlobalTournamentApi;
import jcrapi2.api.intern.leaderboards.LeaderboardApi;
import jcrapi2.api.intern.locations.LocationApi;
import jcrapi2.api.intern.players.PlayerApi;
import jcrapi2.api.intern.tournaments.TournamentApi;
Expand All @@ -42,5 +43,6 @@ public class DefaultApiClasses {
LocationApi.class, "jcrapi2.api.intern.locations.LocationApiImpl",
ChallengeApi.class, "jcrapi2.api.intern.challenges.ChallengeApiImpl",
GlobalTournamentApi.class,
"jcrapi2.api.intern.globaltournaments.GlobalTournamentApiImpl");
"jcrapi2.api.intern.globaltournaments.GlobalTournamentApiImpl",
LeaderboardApi.class, "jcrapi2.api.intern.leaderboards.LeaderboardApiImpl");
}
31 changes: 31 additions & 0 deletions src/main/java/jcrapi2/api/intern/leaderboards/Leaderboard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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;

import com.google.gson.annotations.SerializedName;

import lombok.Data;

@Data
public class Leaderboard {

@SerializedName("id")
private long id;

@SerializedName("name")
private String name;
}
26 changes: 26 additions & 0 deletions src/main/java/jcrapi2/api/intern/leaderboards/LeaderboardApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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;

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

import java.util.concurrent.Future;

public interface LeaderboardApi extends Api {

Future<LeaderboardsResponse> findAll(LeaderboardsRequest leaderboardsRequest);
}
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;

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

import java.util.concurrent.Future;

class LeaderboardApiImpl extends BaseApi implements LeaderboardApi {

LeaderboardApiImpl(ApiContext apiContext) {
super(apiContext);
}

@Override
public Future<LeaderboardsResponse> findAll(LeaderboardsRequest leaderboardsRequest) {
return get("/leaderboards", leaderboardsRequest, LeaderboardsResponse.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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;

import lombok.Builder;

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

public class LeaderboardsRequest extends PaginationRequest {

@Builder
private LeaderboardsRequest(int limit, String after, String before, boolean storeRawResponse) {
super(limit, after, before, storeRawResponse);
}

public static LeaderboardsRequestBuilder builder() {
return new LeaderboardsRequestBuilder();
}
}
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;

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

public class LeaderboardsResponse extends PaginationResponse<Leaderboard> {}
22 changes: 22 additions & 0 deletions src/test/java/jcrapi2/EndToEnd.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
import jcrapi2.api.intern.globaltournaments.GlobalTournamentApi;
import jcrapi2.api.intern.globaltournaments.GlobalTournamentsRequest;
import jcrapi2.api.intern.globaltournaments.GlobalTournamentsResponse;
import jcrapi2.api.intern.leaderboards.LeaderboardApi;
import jcrapi2.api.intern.leaderboards.LeaderboardsRequest;
import jcrapi2.api.intern.leaderboards.LeaderboardsResponse;
import jcrapi2.api.intern.locations.LocationApi;
import jcrapi2.api.intern.locations.LocationsRequest;
import jcrapi2.api.intern.locations.LocationsResponse;
Expand Down Expand Up @@ -125,6 +128,8 @@ class EndToEnd {

private GlobalTournamentApi globalTournamentApi;

private LeaderboardApi leaderboardApi;

@BeforeEach
void setUp() {
JCrApi jCrApi =
Expand All @@ -139,6 +144,7 @@ void setUp() {
locationApi = jCrApi.getApi(LocationApi.class);
challengeApi = jCrApi.getApi(ChallengeApi.class);
globalTournamentApi = jCrApi.getApi(GlobalTournamentApi.class);
leaderboardApi = jCrApi.getApi(LeaderboardApi.class);
}

private static void assertDiff(String expected, String actual) {
Expand Down Expand Up @@ -561,4 +567,20 @@ void locations_getTopPlayerPathOfLegendRankings() throws Exception {

assertDiff(expected, actual);
}

@Test
void leaderboards_findAll() throws Exception {
LeaderboardsResponse response =
leaderboardApi
.findAll(
LeaderboardsRequest.builder()
.storeRawResponse(true)
.limit(10)
.build())
.get();
String actual = GSON.toJson(response);
String expected = response.getRawResponse().getRaw();

assertDiff(expected, actual);
}
}
3 changes: 2 additions & 1 deletion src/test/java/jcrapi2/JCrApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ void listApis_whenCalled_shouldReturnListOfApiInterfaceNames() {
"jcrapi2.api.intern.globaltournaments.GlobalTournamentApi",
"jcrapi2.api.intern.locations.LocationApi",
"jcrapi2.api.intern.players.PlayerApi",
"jcrapi2.api.intern.tournaments.TournamentApi"));
"jcrapi2.api.intern.tournaments.TournamentApi",
"jcrapi2.api.intern.leaderboards.LeaderboardApi"));

List<String> actual = unitUnderTest.listApis();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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;

import jcrapi2.IntegrationTestBase;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class LeaderboardApiImplIntegrationTest extends IntegrationTestBase {

private LeaderboardApi unitUnderTest;

@BeforeEach
void setUp() {
unitUnderTest = getJCrApi().getApi(LeaderboardApi.class);
}

@Test
void findAll() throws Exception {
jcrapi2.api.intern.leaderboards.LeaderboardsRequest.LeaderboardsRequestBuilder builder =
jcrapi2.api.intern.leaderboards.LeaderboardsRequest.builder();
jcrapi2.api.intern.leaderboards.LeaderboardsRequest request =
builder.limit(100).before("zzz").after("aaa").storeRawResponse(true).build();
prepare("/leaderboards", EMPTY, "src/test/resources/leaderboard-findAll.json", request);

jcrapi2.api.intern.leaderboards.LeaderboardsResponse expected =
toJson(jcrapi2.api.intern.leaderboards.LeaderboardsResponse.class, getExpected());

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

@Test
void findAll_whenWithException() {
jcrapi2.api.intern.leaderboards.LeaderboardsRequest.LeaderboardsRequestBuilder builder =
jcrapi2.api.intern.leaderboards.LeaderboardsRequest.builder();
jcrapi2.api.intern.leaderboards.LeaderboardsRequest request =
builder.limit(100).before("zzz").after("aaa").storeRawResponse(true).build();

prepareWithErrorAndRun(
"/leaderboards", EMPTY, request, () -> unitUnderTest.findAll(request).get());
}
}
8 changes: 8 additions & 0 deletions src/test/resources/leaderboard-findAll.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"items": [
{
"id": 170000001,
"name": "Goblin Queen's Journey"
}
]
}

0 comments on commit 66d9ac8

Please sign in to comment.