📖 English Documentation | 📖 中文文档
WP-SDK library built in Kotlin, only supported Application Passwords authentication.
Maven
:
<dependency>
<groupId>com.xzakota.wordpress</groupId>
<artifactId>sdk-kt</artifactId>
<version>${version}</version>
</dependency>
Gradle
:
dependencies {
implementation 'com.xzakota.wordpress:sdk-kt:${version}'
}
Java
:
WPClient client = new WPClient(server, new Authentication(username, appPwd));
// connect
client.connect();
// connect and test, failure to pass the test will throw an exception
// client.connectTest();
// Send request
// ...
// 断开连接
client.disconnect();
Kotlin
:
val client = WPClient(server, Authentication(username, appPwd))
// connect
client.connect()
// connect and test, failure to pass the test will throw an exception
// client.connectTest()
// send request
// ...
// disconnect
client.disconnect()
Java
:
client.request().pages(router -> {
List<Page> pages = router.list();
println("List of Page: ");
println(pages);
Page page = new Page();
page.setTitle(new RenderedField("New page title"));
page.setContent(new RenderedField("New page content"));
Page createdPage = router.create(page);
if (createdPage != null) {
println("Created page id: " + createdPage.getId());
}
});
Kotlin
:
client.request().pages { router ->
val pages = router.list()
println("List of Page: ")
println(pages)
router.create(Page().apply {
title = RenderedField("New page title")
content = RenderedField("New page content")
})?.let { createdPage ->
println("Created page id: " + createdPage.id)
}
}
Java
:
client.request().posts(router -> {
Post post = router.retrieveById(1L);
if (post != null) {
println("Post with ID 1: $post");
post.setPassword("123456");
if (post.getId() != null) {
router.updateById(post.getId(), post);
}
} else {
println("No post with ID 1.");
}
});
Kotlin
:
client.request().posts { router ->
val post = router.retrieveById(1L)
if (post != null) {
println("Post with ID 1: $post")
post.password = "123456"
if (post.id != null) {
router.updateById(post.id!!, post)
}
} else {
println("No post with ID 1.")
}
}
For other uses, please check out the test unit or browse the source code: