Wordpress-SDK | Android
Minimal Wordpress SDK for Android.
Installation
In build.gradle
add the following dependencies
repositories {
maven {
url 'http://dl.bintray.com/venomvendor/maven'
}
}
dependencies {
compile 'com.venomvendor:Wordpress-SDK:1.0.0-beta'
}
Initialization
WordpressSDK.initialize("VenomVendor.com/wp", false);
Available APIs
/* Request for posts */
PostRequests postReq = (PostRequests) NetworkHandler.getInstance(PostRequests.IDENTIFIER);
/* Request for comments */
CommentRequests commentReq = (CommentRequests) NetworkHandler.getInstance(CommentRequests.IDENTIFIER);
/* Request for categories */
CategoryRequests CategoryReq = (CategoryRequests) NetworkHandler.getInstance(CategoryRequests.IDENTIFIER);
Get Recent Posts
PostRequests postReq = (PostRequests) NetworkHandler.getInstance(PostRequests.IDENTIFIER);
postReq.getRecentPosts(new ResponseHandler<GetPost[]>() {
@Override
public void onResponse(@Nullable Response<GetPost[]> response,
@Nullable WordpressException ex) {
if (response != null) {
GetPost[] allPosts = response.body();
for (GetPost post : allPosts) {
Log.d(TAG, post.getTitle().getRendered());
}
} else if (ex != null) {
Log.d(TAG, ex.getMessage());
} else {
Log.d(TAG, "Unknown Error");
}
}
});
Get Posts
PostRequests postReq = (PostRequests) NetworkHandler.getInstance(PostRequests.IDENTIFIER);
PostsParams.Builder params = new PostsParams.Builder();
params.setPage(1);
params.setOffset(10);
params.setResultSize(20);
params.setSearch("Mario");
params.setCategory("Mobile");
params.setSlug("some-slug");
params.setPublishedBefore("2017-03-18T13:18:35");
params.setPublishedAfter("2016-01-01T13:18:35");
postReq.getPosts(postParams.build(), new ResponseHandler<GetPost[]>() {
@Override
public void onResponse(@Nullable Response<GetPost[]> response,
@Nullable WordpressException ex) {
if (response != null) {
GetPost[] allPosts = response.body();
for (GetPost post : allPosts) {
Log.d(TAG, post.getTitle().getRendered());
}
} else if (ex != null) {
Log.d(TAG, ex.getMessage());
} else {
Log.d(TAG, "Unknown Error");
}
}
});
Setup
Refer Sample Factory.json with comments
{
"dateError": "GMT+05:30",
"perReq": 20,
"perReqNew": 100,
"secure": true,
"domain": "VenomVendor.com",
"protocolDefault": "http://",
"protocolSecure": "https://",
"path": {
"root": "/wp-json/wp/v2/",
"token": "token/",
"posts": "posts/",
"comments": "comments/",
"category": "categories/"
},
"filter": {
"fetchPost": {
"id": "include",
"publishedAfter": "after",
"publishedBefore": "before",
"page": "page",
"search": "search",
"offset": "offset",
"resultSize": "per_page",
"slug": "slug",
"category": "categories"
},
"fetchComment": {
"id": "include",
"publishedAfter": "after",
"publishedBefore": "before",
"page": "page",
"search": "search",
"offset": "offset",
"resultSize": "per_page",
"postId": "post",
"userId": "author",
"inReplyTo": "parent"
}
},
"create": {
"newComment": {
"postId": "post",
"userId": "author",
"email": "author_email",
"name": "author_name",
"comment": "content",
"userAgent": "author_user_agent",
"replyTo": "parent"
}
},
"update": {
"updateParams": {
"postId": "post",
"userId": "author",
"email": "author_email",
"name": "author_name",
"comment": "content"
}
},
"delete": {
"oldComment": {
"force": "force",
"password": "password"
}
}
}