Super simples and efficient library implementing all the options provided by the PasteBin api.
With this library you can easily:
- Create pastes for users and as a Guest
- Delete pastes
- List users pastes
- Fetch user information
- Create User Session Key (Actually you doesn't need to do that, the library will handle it, but if you want you can create too)
- Get pastes contents (All pastes PUBLIC, UNLISTED and PRIVATE)
The build status may show as failed even if there are no errors, because the currently PasteBin API has a limit for free accounts, and since the tests use an free account to run, the limits can be already used in the day and the tests will fail, so, if the build is showing failed, doesn't mean it has any problem, can be just the free account limits.
More information on tests in the Running tests section.
Read the docs here!
- Build Status Note
- Installation
- Requirements
- Examples
- Running tests
- JavaDocs
- Contribution
- Problems & Suggestions
- License
- Donations
You can add the following dependency to your maven or gradle based project:
<properties>
<pastebin4j.version>1.1.0<pastebin4j.version>
<properties>
<dependency>
<groupId>com.github.kennedyoliveira</groupId>
<artifactId>pastebin4j</artifactId>
<version>${pastebin4j.version}</version>
</dependency
You can get the last version looking at the top in the "maven-central" badge and replace in your pom.xml
or build.gradle
You can build the project with gradle using the following command to install to you local repository:
git clone https://github.com/kennedyoliveira/pastebin4j.git
cd pastebin4j
./gradlew clean build install -x test
Exclude the tests because for testing you need to provide a devkey
, username
and password
.
This command will build and install the project into your local maven repository and the artifacts generated will be in the build/libs
directory inside your project folder.
To use the APi you'll need to have a developer key, that you can get from the PasteBin site, you go to this link: Developer Key.
All the interaction is provided by the PasteBin
class, you need to create one passing your credentials and that is it!
// Configuration for the Credentials
final String devKey = "dev-key";
final String userName = "user-name";
final String password = "password";
// Create a PasteBin object with the credentials
final PasteBin pasteBin = new PasteBin(new AccountCredentials(devKey, userName, password));
// List all the pastes from the user!
// Pretty easy, isn't?
final List<Paste> pastes = pasteBin.listUserPastes();
// The method never returns null, so you can check if the list is empty to see if you have pastes or not
if (pastes.isEmpty()) {
System.out.println("You don't have any pastes :(");
return;
}
// Getting a paste
final Paste paste = pastes.get(0);
// Current info on pastes
System.out.println("Title: " + paste.getTitle());
System.out.println("Visibility: " + paste.getVisibility().name());
System.out.println("Unique Key: " + paste.getKey());
System.out.println("Syntax Highlight: " + paste.getHighLight().name());
System.out.println("Paste Date: " + paste.getLocalPasteDate());
System.out.println("Paste Expiration: " + paste.getExpiration());
System.out.println("Paste Expiration Date: " + paste.getLocalExpirationDate());
System.out.println("Hits: " + paste.getHits());
System.out.println("URL: " + paste.getUrl());
System.out.println("Size: " + paste.getSize());
// Prints all information of all pastes
pastes.forEach(System.out::println);
final String devKey = "dev-key";
final String userName = "user-name";
final String password = "password";
final PasteBin pasteBin = new PasteBin(new AccountCredentials(devKey, userName, password));
// Basic creation
final Paste paste = new Paste();
paste.setTitle("Testing API");
paste.setExpiration(PasteExpiration.ONE_HOUR);
paste.setHighLight(PasteHighLight.Java);
paste.setVisibility(PasteVisibility.UNLISTED);
paste.setContent("public class Teste { }");
final String url = pasteBin.createPaste(paste);
System.out.println("Paste created at url: " + url);
The api gives you enums with all the information so you can just select it easy, doesn't need to remember, the class PasteHighLight
has all the SyntaxHighLight currently implemented in the PasteBin, the class PasteExpiration
has all the possible values for Expiration in a Paste and the PasteVisibility
has the visibility status of a paste.
You can create a guest Paste by using a GuestPaste
instead of a paste.
Paste p = new GuestPaste();
Even if you specify your username
and password
using this class your paste will be created as guest.
There are builder for creating the pastes that you can access by Paste.newBuilder()
.
Check the src/examples
for more examples, there you can see how to list trends pastes, get user information and more!
To run the tests you need to specify an devkey, username and password.
Use it in command line like the following:
.\gradlew -Dpastebin4j.devkey=your-dev-key -Dpastebin4j.username=your-user-name -Dpastebin4j.password=your-password test
Important Note: The tests will create some pastes, so expect it :D
Check the JavaDocs here: JavaDocs. The JavaDocs are for the latest release.
If you want to contribute you can fork the project and send pull requests, you can even provide your own implementation of the API just by creating a class that implements the PasteBinApi
interface and pass it to the PasteBin
constructor.
If you encounter any problem, please report at Issues i'm work on it the fast as i can.
This project is licensed with MIT License, so you can freely use, modify and distribute.
If this projects helped you and you feels like helping me back, consider a donation, it'll help me a lot! Anyway, if this helped you i'm glad i could help you!