KPaste allows you to access Paste.ee services, "pasting" for example, from your program's code with little hassle. In other words, it is an interface to Paste.ee services.
Said services are accessed through an implementation of the PasteService class generated by Retrofit, while both response and request bodies are converted to/from domain objects with Moshi.
As a client, you work with the PasteService implementation and the domain classes.
While the domain classes are very similar in structure to the responses from Paste.ee, they decouple your code from the schema used by Paste.ee. Further, you can write your own domain classes to suit your needs. Just be sure to modify the adapters. The adapters convert instances of classes with a structure matching a server response to a domain object.
A basic understanding of both Retrofit and Moshi is advised, although not strictly necessary, to use KPaste as-is. You do need to read Paste.ee API documentation, however, in order to understand the services Paste.ee offers.
To use in your project, download the jar file (available in Releases), add it to your lib folder, and manually add the dependencies of the library (see build.gradle) to your own. KPaste depends on kotlinx-coroutines-core, kotlin-reflect, converter-moshi, moshi-kotlin. We may consider publishing to a central repository in future releases.
Usage.
// Retrieve the service
val service = PasteServiceProvider.pasteService
// Submit a paste using your developer key
// first, create a paste draft
val pasteDraft = PasteDraft(
false,
"Greetings paste.",
listOf(Section(1, "autodetect", "Greetings", "Hello, world."))
)
// then, submit the draft
try {
val pasteLink = service.postPasteDraft(developerKey, pasteDraft)
// print link and id of created paste
println("$pasteLink")
} catch (e: Exception) {
// handle exception
}
// Posting a paste using an application key follows the same procedure - if you
// do not know about the different keys available, read paste.ees documentation.
// Finding out about a key
try {
val info = service.getKeyInfo(someKey)
println("$info")
} catch (e: Exception) {
// handle exception
}
// You can also get and delete a paste, get a list of the syntax available,
// get the details of a specific syntax, and more.
This project is provided AS-IS.
This project is MIT licensed.