use of org.wordpress.android.ui.stats.models.VisitsModel in project WordPress-Android by wordpress-mobile.
the class RemoteTests method testVisits.
public void testVisits() throws Exception {
StatsRestRequestAbstractListener listener = new StatsRestRequestAbstractListener() {
@Override
void parseResponse(JSONObject response) throws JSONException {
VisitsModel model = new VisitsModel(123456, response);
assertNotNull(model.getVisits());
assertNotNull(model.getUnit());
assertNotNull(model.getDate());
assertEquals(model.getVisits().size(), 30);
assertEquals(model.getUnit(), "day");
VisitModel visitModel = model.getVisits().get(0);
assertEquals(visitModel.getViews(), 7808);
assertEquals(visitModel.getVisitors(), 4331);
assertEquals(visitModel.getLikes(), 0);
assertEquals(visitModel.getComments(), 0);
assertEquals(visitModel.getPeriod(), "2014-10-08");
}
};
mRestClient.makeRequest(Request.Method.POST, "https://public-api.wordpress.com/rest/v1.1/sites/123456/stats/visits", null, listener, errListener);
}
use of org.wordpress.android.ui.stats.models.VisitsModel in project WordPress-Android by wordpress-mobile.
the class StatsService method updateWidgetsUI.
// Call an updates on the installed widgets if the blog is the primary, the endpoint is Visits
// the timeframe is DAY or INSIGHTS, and the date = TODAY
private void updateWidgetsUI(long siteId, final StatsEndpointsEnum endpointName, StatsTimeframe timeframe, String date, int pageRequested, Serializable responseObjectModel) {
if (pageRequested != -1) {
return;
}
if (endpointName != StatsEndpointsEnum.VISITS) {
return;
}
if (timeframe != StatsTimeframe.DAY && timeframe != StatsTimeframe.INSIGHTS) {
return;
}
SiteModel site = mSiteStore.getSiteBySiteId(siteId);
// make sure the data is for the current date
if (!date.equals(StatsUtils.getCurrentDateTZ(site))) {
return;
}
if (responseObjectModel == null) {
// TODO What we want to do here?
return;
}
if (!StatsWidgetProvider.isBlogDisplayedInWidget(siteId)) {
AppLog.d(AppLog.T.STATS, "The blog with remoteID " + siteId + " is NOT displayed in any widget. Stats Service doesn't call an update of the widget.");
return;
}
if (responseObjectModel instanceof VisitsModel) {
VisitsModel visitsModel = (VisitsModel) responseObjectModel;
if (visitsModel.getVisits() == null || visitsModel.getVisits().size() == 0) {
return;
}
List<VisitModel> visits = visitsModel.getVisits();
VisitModel data = visits.get(visits.size() - 1);
StatsWidgetProvider.updateWidgets(getApplicationContext(), site, data);
} else if (responseObjectModel instanceof VolleyError) {
VolleyError error = (VolleyError) responseObjectModel;
StatsWidgetProvider.updateWidgets(getApplicationContext(), site, mSiteStore, error);
} else if (responseObjectModel instanceof StatsError) {
StatsError statsError = (StatsError) responseObjectModel;
StatsWidgetProvider.updateWidgets(getApplicationContext(), site, mSiteStore, statsError);
}
}
Aggregations