项目作者: mlieshoff

项目描述 :
A Java Wrapper For Official Supercell Clash Royal Api
高级语言: Java
项目地址: git://github.com/mlieshoff/jcrapi2.git
创建时间: 2018-08-23T10:30:11Z
项目社区:https://github.com/mlieshoff/jcrapi2

开源协议:

下载



Nightlies

jcrapi2 4.0.15

A Java Wrapper For Official Supercell Clash Royal Api

Why we don’t use the Swagger scheme?

A big sorry for that, but the quality of that scheme changes from day to day.
Another big sorry, but the OpenApi Java generator is producing code quality we like much.
That’s simple why :) If you think the same way (it may differ from case to case of course), feel free to continue using our wrapper.

Why we moved to the amazing services of packagecloud?

We moved to packagecloud.io because the bintray closed their nice hosting… And packagecloud.io is a really nice place to be :)

Join us on Discord

https://discord.gg/WNb5c8hn

Simplest Usage

Note: Please combine the builder methods as it makes sense. The demonstrated is showing only all possibilities.
For more information please check

https://developer.clashroyale.com/#/documentation

Use one of these endpoints:

Official endpoint

  1. https://api.clashroyale.com/v1

Proxy endpoint

  1. https://crproxy.royaleapi.dev/v1

Bind essentials to your project

  1. <repositories>
  2. <repository>
  3. <id>packagecloud-supercell-api-wrapper-essentials</id>
  4. <url>https://packagecloud.io/mlieshoff/supercell-api-wrapper-essentials/maven2</url>
  5. <releases>
  6. <enabled>true</enabled>
  7. </releases>
  8. <snapshots>
  9. <enabled>true</enabled>
  10. </snapshots>
  11. </repository>
  12. </repositories>

and use the dependency

  1. <dependency>
  2. <groupId>supercell-api-wrapper-essentials</groupId>
  3. <artifactId>supercell-api-wrapper-essentials</artifactId>
  4. <version>1.0.1</version>
  5. </dependency>

Use built-in standard connector

  1. Connector connector = new StandardConnector();

or use the new filesystem cached connector

  1. Connector connector = new FilesystemCachedConnector("jcrapi2")

or use custom implementation

  1. Connector connector = new Connector() {
  2. @Override
  3. public <T extends IResponse> T get(RequestContext requestContext) throws ConnectorException {
  4. // do not forget to use auth header with *Bearer*
  5. String authHeader = "Authorization: Bearer " + requestContext.getApiKey();
  6. }
  7. }
  8. );

connect to the api with creating a ClashRoyale instance.

  1. JCrApi jCrApi = new JCrApi("https://crproxy.royaleapi.dev/v1", "my-api-key", connector);

list all supported apis

  1. System.out.println(jCrApi.listApis());

List of APIs and example usages

ClanApi

  1. // create an instance for the api
  2. ClanApi api = jCrApi.getApi(ClanApi.class);
  1. // findAll
  2. ClansResponse response = api.findAll(clansRequest.builder()
  3. .name()
  4. .locationId()
  5. .minMembers()
  6. .maxMembers()
  7. // pagination
  8. .limit()
  9. .after()
  10. .before()
  11. // store raw response
  12. .storeRawResponse()
  13. .build()
  14. ).get();
  1. // findByTag
  2. ClanResponse response = api.findByTag(clanRequest.builder()
  3. .clanTag()
  4. // store raw response
  5. .storeRawResponse()
  6. .build()
  7. ).get();
  1. // getRiverRaceLog
  2. RiverRaceLogResponse response = api.getRiverRaceLog(riverRaceLogRequest.builder()
  3. .clanTag()
  4. // pagination
  5. .limit()
  6. .after()
  7. .before()
  8. // store raw response
  9. .storeRawResponse()
  10. .build()
  11. ).get();
  1. // getMembers
  2. ClanMembersResponse response = api.getMembers(clanMembersRequest.builder()
  3. .clanTag()
  4. // pagination
  5. .limit()
  6. .after()
  7. .before()
  8. // store raw response
  9. .storeRawResponse()
  10. .build()
  11. ).get();
  1. // getCurrentRiverRace
  2. CurrentRiverRaceResponse response = api.getCurrentRiverRace(currentRiverRaceRequest.builder()
  3. .clanTag()
  4. // store raw response
  5. .storeRawResponse()
  6. .build()
  7. ).get();

PlayerApi

  1. // create an instance for the api
  2. PlayerApi api = jCrApi.getApi(PlayerApi.class);
  1. // findByTag
  2. PlayerResponse response = api.findByTag(playerRequest.builder()
  3. .playerTag()
  4. // store raw response
  5. .storeRawResponse()
  6. .build()
  7. ).get();
  1. // getUpcomingChests
  2. UpcomingChestsResponse response = api.getUpcomingChests(upcomingChestsRequest.builder()
  3. .playerTag()
  4. // store raw response
  5. .storeRawResponse()
  6. .build()
  7. ).get();
  1. // getBattleLog
  2. BattleLogResponse response = api.getBattleLog(battleLogRequest.builder()
  3. .playerTag()
  4. // store raw response
  5. .storeRawResponse()
  6. .build()
  7. ).get();

CardApi

  1. // create an instance for the api
  2. CardApi api = jCrApi.getApi(CardApi.class);
  1. // findAll
  2. CardsResponse response = api.findAll(cardsRequest.builder()
  3. // store raw response
  4. .storeRawResponse()
  5. .build()
  6. ).get();

TournamentApi

  1. // create an instance for the api
  2. TournamentApi api = jCrApi.getApi(TournamentApi.class);
  1. // findAll
  2. TournamentsResponse response = api.findAll(tournamentsRequest.builder()
  3. .name()
  4. // pagination
  5. .limit()
  6. .after()
  7. .before()
  8. // store raw response
  9. .storeRawResponse()
  10. .build()
  11. ).get();
  1. // findByTag
  2. TournamentResponse response = api.findByTag(tournamentRequest.builder()
  3. .tournamentTag()
  4. // pagination
  5. .limit()
  6. .after()
  7. .before()
  8. // store raw response
  9. .storeRawResponse()
  10. .build()
  11. ).get();

LocationApi

  1. // create an instance for the api
  2. LocationApi api = jCrApi.getApi(LocationApi.class);
  1. // findAll
  2. LocationsResponse response = api.findAll(locationsRequest.builder()
  3. // pagination
  4. .limit()
  5. .after()
  6. .before()
  7. // store raw response
  8. .storeRawResponse()
  9. .build()
  10. ).get();
  1. // findById
  2. LocationResponse response = api.findById(locationRequest.builder()
  3. .locationId()
  4. // store raw response
  5. .storeRawResponse()
  6. .build()
  7. ).get();
  1. // getClanRankings
  2. ClanRankingsResponse response = api.getClanRankings(clanRankingsRequest.builder()
  3. .locationId()
  4. // pagination
  5. .limit()
  6. .after()
  7. .before()
  8. // store raw response
  9. .storeRawResponse()
  10. .build()
  11. ).get();
  1. // getPlayerRankings
  2. PlayerRankingsResponse response = api.getPlayerRankings(playerRankingsRequest.builder()
  3. .locationId()
  4. // pagination
  5. .limit()
  6. .after()
  7. .before()
  8. // store raw response
  9. .storeRawResponse()
  10. .build()
  11. ).get();
  1. // getClanWarRankings
  2. ClanWarRankingsResponse response = api.getClanWarRankings(clanWarRankingsRequest.builder()
  3. .locationId()
  4. // pagination
  5. .limit()
  6. .after()
  7. .before()
  8. // store raw response
  9. .storeRawResponse()
  10. .build()
  11. ).get();
  1. // getTopPlayerLeagueSeasons
  2. TopPlayerLeagueSeasonsResponse response = api.getTopPlayerLeagueSeasons(topPlayerLeagueSeasonsRequest.builder()
  3. // pagination
  4. .limit()
  5. .after()
  6. .before()
  7. // store raw response
  8. .storeRawResponse()
  9. .build()
  10. ).get();
  1. // getTopPlayerLeagueSeason
  2. TopPlayerLeagueSeasonResponse response = api.getTopPlayerLeagueSeason(topPlayerLeagueSeasonRequest.builder()
  3. .seasonId()
  4. // store raw response
  5. .storeRawResponse()
  6. .build()
  7. ).get();
  1. // getTopPlayerLeagueSeasonRankings
  2. TopPlayerLeagueSeasonRankingsResponse response = api.getTopPlayerLeagueSeasonRankings(topPlayerLeagueSeasonRankingsRequest.builder()
  3. .seasonId()
  4. // pagination
  5. .limit()
  6. .after()
  7. .before()
  8. // store raw response
  9. .storeRawResponse()
  10. .build()
  11. ).get();
  1. // getTopPlayerPathOfLegendSeasonRankings
  2. TopPlayerPathOfLegendSeasonRankingsResponse response = api.getTopPlayerPathOfLegendSeasonRankings(topPlayerPathOfLegendSeasonRankingsRequest.builder()
  3. .seasonId()
  4. // pagination
  5. .limit()
  6. .after()
  7. .before()
  8. // store raw response
  9. .storeRawResponse()
  10. .build()
  11. ).get();
  1. // getTopPlayerPathOfLegendRankings
  2. TopPlayerPathOfLegendRankingsResponse response = api.getTopPlayerPathOfLegendRankings(topPlayerPathOfLegendRankingsRequest.builder()
  3. .locationId()
  4. // pagination
  5. .limit()
  6. .after()
  7. .before()
  8. // store raw response
  9. .storeRawResponse()
  10. .build()
  11. ).get();
  1. // getTopPlayerTournamentRankings
  2. TopPlayerTournamentRankingsResponse response = api.getTopPlayerTournamentRankings(topPlayerTournamentRankingsRequest.builder()
  3. .tournamentTag()
  4. // pagination
  5. .limit()
  6. .after()
  7. .before()
  8. // store raw response
  9. .storeRawResponse()
  10. .build()
  11. ).get();
  1. // getTopPlayerLeagueSeasonsV2
  2. TopPlayerLeagueSeasonsV2Response response = api.getTopPlayerLeagueSeasonsV2(topPlayerLeagueSeasonsV2Request.builder()
  3. // pagination
  4. .limit()
  5. .after()
  6. .before()
  7. // store raw response
  8. .storeRawResponse()
  9. .build()
  10. ).get();

ChallengeApi

  1. // create an instance for the api
  2. ChallengeApi api = jCrApi.getApi(ChallengeApi.class);
  1. // findAll
  2. ChallengesResponse response = api.findAll(challengesRequest.builder()
  3. // store raw response
  4. .storeRawResponse()
  5. .build()
  6. ).get();

GlobalTournamentApi

  1. // create an instance for the api
  2. GlobalTournamentApi api = jCrApi.getApi(GlobalTournamentApi.class);
  1. // findAll
  2. GlobalTournamentsResponse response = api.findAll(globalTournamentsRequest.builder()
  3. // pagination
  4. .limit()
  5. .after()
  6. .before()
  7. // store raw response
  8. .storeRawResponse()
  9. .build()
  10. ).get();

LeaderboardApi

  1. // create an instance for the api
  2. LeaderboardApi api = jCrApi.getApi(LeaderboardApi.class);
  1. // findAll
  2. LeaderboardsResponse response = api.findAll(leaderboardsRequest.builder()
  3. // pagination
  4. .limit()
  5. .after()
  6. .before()
  7. // store raw response
  8. .storeRawResponse()
  9. .build()
  10. ).get();
  1. // findById
  2. LeaderboardResponse response = api.findById(leaderboardRequest.builder()
  3. .leaderboardId()
  4. // pagination
  5. .limit()
  6. .after()
  7. .before()
  8. // store raw response
  9. .storeRawResponse()
  10. .build()
  11. ).get();

Add or replace registered API’s

  1. JCrApi jCrApi = new JCrApi(...);
  2. jCrApi.register(MyApi.class, MyApiImpl.class.getName());
  3. MyApi myApi = jCrApi.getApi(MyApi.class);
  4. GoodiesResponse goodiesResponse = myApi.findAllGoodies(new GoodiesRequest(...))).get();

Custom API implementations just need to inherit from BaseApi.

Asynchronous usage

All requests are returning java.concurrent.Future. The execution will be asynchronous by default.

How to bind the packagecloud repository

  1. <repositories>
  2. <repository>
  3. <id>packagecloud-jcrapi2</id>
  4. <url>https://packagecloud.io/mlieshoff/jcrapi2/maven2</url>
  5. <releases>
  6. <enabled>true</enabled>
  7. </releases>
  8. <snapshots>
  9. <enabled>true</enabled>
  10. </snapshots>
  11. </repository>
  12. </repositories>

Add dependency

to Gradle:

  1. implementation group: 'jcrapi2', name: 'jcrapi2', version: '4.0.15'

to Maven:

  1. <dependency>
  2. <groupId>jcrapi2</groupId>
  3. <artifactId>jcrapi2</artifactId>
  4. <version>4.0.15</version>
  5. </dependency>

Continuous Integration

https://github.com/mlieshoff/jcrapi2/actions

Repository

https://packagecloud.io/mlieshoff/jcrapi2

Logging

We are using SLF4j.

Usage of RoyaleApi proxy

This wrapper can be easyly connected to the proxy of our friends on RoyaleAPI. Please proceed first the steps described here:

https://docs.royaleapi.com/#/proxy

Then initialize an instance of class Api like that:

  1. JCrApi jCrApi = new JCrApi("https://crproxy.royaleapi.dev/v1", API_KEY, CONNECTOR);

That’s all, enjoy :)

Library updates

Minor versions

  1. mvn versions:update-parent versions:use-latest-releases versions:update-properties versions:commit -DallowMajorUpdates=false

Major versions

  1. mvn versions:update-parent versions:use-latest-releases versions:update-properties versions:commit -DallowMajorUpdates=true

Update plugins

  1. mvn versions:display-plugin-updates -U

Contributing

  1. Feel free to open Pull Requests with your ideas :)