Skip to content

Commit

Permalink
Add with_counts query param to GET guild (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
p4czyk committed Jan 2, 2021
1 parent 6b9fe05 commit 45a2cda
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
16 changes: 15 additions & 1 deletion rest/src/main/java/discord4j/rest/entity/RestGuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,28 @@ static RestGuild create(RestClient restClient, long id) {
return new RestGuild(restClient, id);
}

/**
* Retrieve this guild's data upon subscription.
*
* @param withCounts when true, will return approximate member and presence counts for the guild too.
* otherwise approximate member and presence counts will be null in {@link GuildUpdateData}.
* @return a {@link Mono} where, upon successful completion, emits the {@link GuildUpdateData} belonging to this
* entity. If an error is received, it is emitted through the {@code Mono}.
*/
public Mono<GuildUpdateData> getData(@Nullable Boolean withCounts) {
Map<String, Object> queryParams = new HashMap<>();
Optional.ofNullable(withCounts).ifPresent(value -> queryParams.put("with_counts", value));
return restClient.getGuildService().getGuild(id, queryParams);
}

/**
* Retrieve this guild's data upon subscription.
*
* @return a {@link Mono} where, upon successful completion, emits the {@link GuildUpdateData} belonging to this
* entity. If an error is received, it is emitted through the {@code Mono}.
*/
public Mono<GuildUpdateData> getData() {
return restClient.getGuildService().getGuild(id);
return getData(null);
}

/**
Expand Down
11 changes: 9 additions & 2 deletions rest/src/main/java/discord4j/rest/service/GuildService.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@ public Mono<GuildUpdateData> createGuild(GuildCreateRequest request) {
.bodyToMono(GuildUpdateData.class);
}

public Mono<GuildUpdateData> getGuild(long guildId, Map<String, Object> queryParams) {
return Routes.GUILD_GET.newRequest(guildId)
.query(queryParams)
.exchange(getRouter())
.bodyToMono(GuildUpdateData.class);
}

public Mono<GuildUpdateData> getGuild(long guildId) {
return Routes.GUILD_GET.newRequest(guildId)
.exchange(getRouter())
.bodyToMono(GuildUpdateData.class);
.exchange(getRouter())
.bodyToMono(GuildUpdateData.class);
}

public Mono<GuildUpdateData> modifyGuild(long guildId, GuildModifyRequest request, @Nullable String reason) {
Expand Down
16 changes: 16 additions & 0 deletions rest/src/test/java/discord4j/rest/entity/RestGuildTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package discord4j.rest.entity;

import discord4j.common.util.Snowflake;
import discord4j.discordjson.json.GuildUpdateData;
import discord4j.rest.RestClient;
import reactor.core.publisher.Mono;

public class RestGuildTest {
public static void main(String[] args) {
RestClient restClient = RestClient.create(System.getenv("token"));
System.out.println(restClient.getRestResources().getJacksonResources().toString());
RestGuild restGuild = restClient.getGuildById(Snowflake.of(System.getenv("guildId")));
Mono<GuildUpdateData> updateDataMono = restGuild.getData(true);
GuildUpdateData updateData = updateDataMono.block();
}
}

0 comments on commit 45a2cda

Please sign in to comment.