use of org.michenux.drodrolib.wordpress.json.WPJsonResponse in project YourAppIdea by Michenux.
the class TutorialSyncAdapter method retrievePosts.
private WPJsonPost retrievePosts(long lastSync, ContentProviderClient provider) throws InterruptedException, ExecutionException, ParseException, RemoteException, OperationApplicationException {
if (BuildConfig.DEBUG) {
Log.d(YourApplication.LOG_TAG, "tutorialSyncAdapter.retrievePosts()");
}
WordpressService wordpressService = WordpressServiceFactory.create(getContext());
Observable<WPJsonResponse> observable = wordpressService.query("get_recent_posts", "android", "android_desc", "android", 9999);
WPJsonResponse response = observable.toBlocking().first();
WPJsonPost newPost = null;
if (response.getStatus().equals(WPJsonResponse.STATUS_OK) && response.getPosts() != null && !response.getPosts().isEmpty()) {
final WPJsonPost lastPost = response.getPosts().get(0);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.FRENCH);
sdf.setTimeZone(TimeZone.getTimeZone("Europe/Paris"));
Date lastPostDate = sdf.parse(lastPost.getDate());
Date lastSyncDate = new Date(lastSync);
if (BuildConfig.DEBUG) {
Log.d(YourApplication.LOG_TAG, "title:" + lastPost.getTitle());
Log.d(YourApplication.LOG_TAG, "date: " + lastPost.getDate());
Log.d(YourApplication.LOG_TAG, "lastSync: " + sdf.format(lastSync));
}
if (lastPostDate.after(lastSyncDate)) {
newPost = lastPost;
}
updateDatabase(response.getPosts(), provider);
//if (ConnectivityUtils.isConnectedWifi(TutorialSyncAdapter.this.getContext()) &&
// BatteryUtils.isChargingOrFull(TutorialSyncAdapter.this.getContext())) {
//load image
//}
} else if (BuildConfig.DEBUG) {
Log.d(YourApplication.LOG_TAG, "result is null or empty");
}
return newPost;
}
use of org.michenux.drodrolib.wordpress.json.WPJsonResponse in project YourAppIdea by Michenux.
the class WordpressServiceTest method testQuery.
@Test
public void testQuery() throws Exception {
WordpressService wordpressService = WordpressServiceFactory.create(mContext);
Observable<WPJsonResponse> observable = wordpressService.query("get_recent_posts", "android", "android_desc", "android", 9999);
TestSubscriber<WPJsonResponse> testSubscriber = new TestSubscriber<>();
observable.subscribe(testSubscriber);
testSubscriber.assertNoErrors();
List<WPJsonResponse> jsonPosts = testSubscriber.getOnNextEvents();
Assert.assertNotNull(jsonPosts);
Assert.assertFalse(jsonPosts.isEmpty());
WPJsonResponse response = jsonPosts.get(0);
Assert.assertEquals(response.getStatus(), "ok");
List<WPJsonPost> posts = response.getPosts();
Assert.assertNotNull(posts);
Assert.assertFalse(posts.isEmpty());
}
Aggregations