Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
Added JavaDocs to RJA and modified the README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshiCodes committed Jun 11, 2023
1 parent f3866d5 commit 29cf1f1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
27 changes: 1 addition & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- [Maven](#maven)
<br><br>
- [Usage](#usage)
- [RestActions](#restactions)
- [RestActions](https://github.com/JoshiCodes/RJA/wiki/Usage#restactions)
- [Sending Messages](#sending-messages)
- [EventListeners](#eventlisteners)
- [Caching](#caching)
Expand Down Expand Up @@ -74,31 +74,6 @@ Message message = rja.retrieveMessage("channelId", "messageId").complete(); // R

```

### RestActions
These methods usually make use of the `RestAction` class. RestActions are used to fetch and handle data async.
To get the data, you can use the `complete()` method, which *can* block the current thread until the data is fetched.
If you want to handle the data async, you can use the `queue()` method, which takes a `Consumer<T>` as parameter.
The queue() method can also be called without any parameters or with two parameters, which are a `Consumer<T>` and a `Consumer<Throwable>`.

```java
RJA rja = builder.build();

// One Consumer, only for the user
rja.retrieveUser("userId").queue(user -> {
// do stuff with the user
});

// Two Consumers, one for the user and one for the exception
rja.retrieveUser("userId").queue(user -> {
// do stuff with the user
}, throwable -> {
// handle the exception
});

// Get the user sync
User user = rja.retrieveUser("userId").complete();
```

### Sending Messages
You can send Messages to every `GenericChannel` using `GenericChannel#sendMessage` or `GenericChannel#sendEmbeds`.
Both of this Methods return a `MessageAction` which can be used to modify the message before sending it.
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/de/joshicodes/rja/RJA.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,28 @@ public RestAction<User> retrieveUser(String id) {
});
}

/**
* Retrieves a member from the cache or the API.
* @param server The server the member is in.
* @param user The user of the member.
* @return The RestAction containing the member. Use {@link RestAction#complete()} or {@link RestAction#queue} to get the member.
*/
public RestAction<Member> retrieveMember(final Server server, final User user) {
return retrieveMember(server, user.getId());
}

/**
* Retrieves a member from the cache or the API.
* @param server The server the member is in.
* @param id The id of the member.
* @return The RestAction containing the member. Use {@link RestAction#complete()} or {@link RestAction#queue} to get the member.
*/
public RestAction<Member> retrieveMember(final Server server, final String id) {
return new RestAction<>(this, () -> new FetchMemberRequest(server.getId(), id));
final RJA rja = this;
return new SimpleRestAction<>(this, () -> {
if(memberCache.containsKey(id)) return memberCache.get(id);
else return new RestAction<>(rja, () -> new FetchMemberRequest(server.getId(), id)).complete();
});
}

/**
Expand Down

0 comments on commit 29cf1f1

Please sign in to comment.