Class PostAction
- java.lang.Object
-
- org.botblock.javabotblockapi.requests.PostAction
-
public class PostAction extends Object
Class used to perform POST requests towards the /api/count endpoint of BotBlock.The class offers options to post either
manually
orautomatically
.
-
-
Constructor Summary
Constructors Constructor Description PostAction(String id)
Constructor to get an instance of PostAction.PostAction(String userAgent, String id)
Constructor to get an instance of PostAction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
disableAutoPost()
Disables the automatic posting of Stats.void
disableAutoPost(long time, TimeUnit timeUnit)
Disables the automatic posting of Stats.void
disableAutoPost(BotBlockAPI botBlockAPI)
Disables the automatic posting of Stats.void
enableAutoPost(Long botId, int guilds, BotBlockAPI botBlockAPI)
Starts ascheduleAtFixedRate
task, which will post the provided guild count to the provided bot lists every n minutes.void
enableAutoPost(String botId, int guilds, BotBlockAPI botBlockAPI)
Starts ascheduleAtFixedRate
task, which will post the provided guild count to the provided bot lists every n minutes.void
postGuilds(Long botId, int guilds, BotBlockAPI botBlockAPI)
Posts the guild count with the provided bot id.void
postGuilds(String botId, int guilds, BotBlockAPI botBlockAPI)
Posts the guild count with the provided bot id.
-
-
-
Constructor Detail
-
PostAction
public PostAction(@Nonnull String id)
Constructor to get an instance of PostAction.Using this constructor will set the following default values:
- User-Agent:
"JavaBotBlockAPI-0000/API_VERSION (Unknown; +https://jbba.dev) DBots/{id}"
Following Exceptions can be thrown from the CheckUtil:
NullPointerException
- When the provided ID is empty.
- Parameters:
id
- The id of the bot. This is required for the internal User-Agent.
- User-Agent:
-
PostAction
public PostAction(@Nonnull String userAgent, @Nonnull String id)
Constructor to get an instance of PostAction.
This constructor allows you to set a own User-Agent by providing any String as the first argument.Note that you can provide
{id}
inside the userAgent to get it replaced with the provided id.Following Exceptions can be thrown from the CheckUtil:
NullPointerException
- When the provided ID or User Agent are empty.
- Parameters:
userAgent
- The Name to use as User-Agent.id
- The id of the bot. This is required for the internal User-Agent.
-
-
Method Detail
-
disableAutoPost
public void disableAutoPost()
Disables the automatic posting of Stats.
This essentially just performs aScheduledExecutorService.shutdown()
by calling thedisableAutoPost(null)
method.Note that using this method will NOT make the scheduler wait for previously scheduled tasks to complete.
If you want to wait for the tasks to complete usedisableAutoPost(BotBlockAPI)
ordisableAutoPost(long, TimeUnit)
instead.- See Also:
ExecutorService.shutdown()
-
disableAutoPost
public void disableAutoPost(@Nullable BotBlockAPI botBlockAPI)
Disables the automatic posting of Stats.
UnlikedisableAutoPost()
can you make the scheduler wait for all scheduled tasks to finish, or to time out after n minutes by providing theBotBlock instance
.Passing null as argument will just perform a
ScheduledExecutorService.shutdown()
similar to what the disableAutoPost() method does.If you want to use a different delay than what you've set in the BotBlockAPI instance, can you use
disableAutoPost(long, TimeUnit)
instead.This method may throw a
InterruptedException
in the terminal.- Parameters:
botBlockAPI
- TheBotBlockAPI instance
or null to just perform a shutdown.- Since:
- 6.0.0
-
disableAutoPost
public void disableAutoPost(long time, @Nonnull TimeUnit timeUnit)
Disables the automatic posting of Stats.
UnlikedisableAutoPost()
can you make the scheduler wait for all scheduled tasks to finish, or to time out after a specified time frame.This method may throw a
InterruptedException
in the terminal.Following Exceptions can be thrown from the CheckUtil:
IllegalStateException
- When the provided time param is 0 or lower.
- Parameters:
time
- The amount of time to wait for scheduled executions to finish before the Scheduler would time out.timeUnit
- TheTimeUnit
to use.- Since:
- 6.0.0
-
enableAutoPost
public void enableAutoPost(@Nonnull Long botId, int guilds, @Nonnull BotBlockAPI botBlockAPI)
Starts ascheduleAtFixedRate
task, which will post the provided guild count to the provided bot lists every n minutes.If the post can't be performed - either by getting a
RatelimitedException
or by getting anIOException
- will the exception be catched and the stacktrace printed.
The scheduler may be canceled by this.The scheduler will wait an initial delay of 1 minute and then performs a task every n minutes, where n is the time set in
BotBlockAPI.Builder.setUpdateDelay(Integer)
(default is 30 minutes).- Parameters:
botId
- The ID of the bot as Long.guilds
- The guild count.botBlockAPI
- TheBotBlockAPI instance
to use.
-
enableAutoPost
public void enableAutoPost(@Nonnull String botId, int guilds, @Nonnull BotBlockAPI botBlockAPI)
Starts ascheduleAtFixedRate
task, which will post the provided guild count to the provided bot lists every n minutes.If the post can't be performed - either by getting a
RatelimitedException
or by getting anIOException
- will the exception be catched and the stacktrace printed.
The scheduler may be canceled by this.The scheduler will wait an initial delay of 1 minute and then performs a task every n minutes, where n is the time set in
BotBlockAPI.Builder.setUpdateDelay(Integer)
(default is 30 minutes).- Parameters:
botId
- The ID of the bot as String.guilds
- The guild count.botBlockAPI
- TheBotBlockAPI instance
to use.
-
postGuilds
public void postGuilds(@Nonnull Long botId, int guilds, @Nonnull BotBlockAPI botBlockAPI) throws IOException, RateLimitedException
Posts the guild count with the provided bot id.- Parameters:
botId
- The ID of the bot.guilds
- The guild count.botBlockAPI
- TheBotBlockAPI instance
.- Throws:
IOException
- When the post request couldn't be performed.RateLimitedException
- When we exceed the rate-limit of the BotBlock API.
-
postGuilds
public void postGuilds(@Nonnull String botId, int guilds, @Nonnull BotBlockAPI botBlockAPI) throws IOException, RateLimitedException
Posts the guild count with the provided bot id.Following Exceptions can be thrown from the CheckUtil:
NullPointerException
- When the provided id is empty.
- Parameters:
botId
- The ID of the bot.guilds
- The guild count.botBlockAPI
- TheBotBlockAPI instance
.- Throws:
IOException
- When the post request couldn't be performed.RateLimitedException
- When we exceed the rate-limit of the BotBlock API.
-
-