BytesToJava
BytesToJava is the most advanced wrapper for the BytesToBits API. It is developed in Java and Kotlin, and provides easy access to all of the functions that the BytesToBits API has available.
What is BytesToBits?
BytesToBits or BTB for short is an active community that revolves around software development. It is based on a Discord Server with over 2,000 members that you can join here.
Getting Started
> Retrieving Your API Token
- Visit the BytesToBits API Login.
- Sign up using the "Register" button after inserting your details, or "Login" if you already have an account.
- You will be redirected to the main page. Click "Account" on the top right corner of the website.
- Copy the
API Token
. You will need this later to access the API.
Setting Up Your Build Environment
> BytesToJava for Maven
- Make sure your Java Project uses Maven. Not sure how to do this? Find out here.
- Add this repository to your
pom.xml
:
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
- Add this dependency to your
pom.xml
:
<dependency>
<groupId>com.github.OpenSrcerer</groupId>
<artifactId>BytesToJava</artifactId>
<version>0.0.1-beta1</version>
</dependency>
- Refresh your changes. Well done, you can now start using BytesToJava.
> BytesToJava for Gradle
- Make sure your Java Project uses Gradle. Not sure how to do this? Find out here.
- Add this repository to your
build.gradle
:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add this dependency to your
build.gradle
:
dependencies {
implementation 'com.github.OpenSrcerer:BytesToJava:0.0.1-beta1'
}
- Refresh your changes. Well done, you can now start using BytesToJava.
How to use BytesToJava?
Using BytesToJava is straightforward and simple. Firstly, create a BTJ
instance as such:
BTJ btj = BTJ.getBTJ("YOUR-TOKEN-HERE");
Please refrain from making multiple of these instances. You are supposed to work with one BTJ object per application.
You can make requests to the BytesToBits API using the following methods:
getInfo()
- To Retrieve info about your current tokengetWord()
- Retrieve a random word from the APIgetText()
- Retrieve a random piece of textgetMadLib()
- Get a random MadLibgetMeme()
- Get a meme from RedditgetLyrics()
- Get the lyrics of a songgetRedditPosts()
- Get Reddit Posts
All of the above methods return a BTJRequest instance. BTJRequests are BytesToJava's way of handling requests made towards the BytesToBits API. When using the methods above, you are not executing the request, but merely creating the Request object. BytesToJava offers three handy ways of executing your requests:
.queue()
- Execute a BTJRequest asynchronously using callbacks..submit()
- Execute a BTJRequest asynchronously. This method returns a CompletableFuture that represents the request..complete()
- Execute a BTJRequest synchronously, meaning that your thread will be blocked if you choose this method of completing the request. This method is not managed by BytesToJava's ratelimit protection and as such you are exposed to possible ratelimits if you spam API calls!
Examples
Here's an example of making a request using callbacks:
// initialize your BTJ instance here
...
btj.getText().queue(randomText -> /* do stuff with your random text */);
...
Or, if you want to handle exceptions yourself:
// initialize your BTJ instance here
...
btj.getText().queue(randomText -> /* do stuff with your random text */, throwable -> /* do stuff with your throwable */);
...
Here's an example of making a request using Futures:
CompletableFuture<RedditMeme> memeFuture = btj.getMeme().submit();
... // Wait for future to complete
if (memefuture.isDone()) {
...
Here's an example of making a request using a synchronous call:
Madlib madlib = btj.getMadlib().complete(); // Blocks the thread