Search in sources :

Example 1 with SystemDataReport

use of org.infobip.mobile.messaging.api.data.SystemDataReport in project mobile-messaging-sdk-android by infobip.

the class SystemDataReporter method synchronize.

public void synchronize() {
    SystemData systemData = mobileMessagingCore.getUnreportedSystemData();
    if (systemData == null) {
        return;
    }
    new MRetryableTask<SystemData, SystemData>() {

        @Override
        public SystemData run(SystemData[] systemDatas) {
            if (systemDatas.length < 1 || systemDatas[0] == null) {
                MobileMessagingLogger.e(InternalSdkError.ERROR_EMPTY_SYSTEM_DATA.get());
                throw InternalSdkError.ERROR_EMPTY_SYSTEM_DATA.getException();
            }
            if (StringUtils.isBlank(mobileMessagingCore.getPushRegistrationId())) {
                MobileMessagingLogger.w("Can't report system data without valid registration");
                throw InternalSdkError.NO_VALID_REGISTRATION.getException();
            }
            SystemData data = systemDatas[0];
            SystemDataReport report = from(data);
            MobileMessagingLogger.v("SYSTEM DATA >>>", report);
            mobileApiData.reportSystemData(report);
            MobileMessagingLogger.v("SYSTEM DATA <<<");
            return data;
        }

        @Override
        public void after(SystemData systemData) {
            mobileMessagingCore.setSystemDataReported();
            broadcaster.systemDataReported(systemData);
        }

        @Override
        public void error(Throwable error) {
            MobileMessagingLogger.w("Error reporting system data: " + error);
            mobileMessagingCore.setLastHttpException(error);
            stats.reportError(MobileMessagingStatsError.SYSTEM_DATA_REPORT_ERROR);
            if (!(error instanceof InternalSdkError.InternalSdkException)) {
                broadcaster.error(MobileMessagingError.createFrom(error));
            }
        }
    }.retryWith(policy).execute(executor, systemData);
}
Also used : SystemDataReport(org.infobip.mobile.messaging.api.data.SystemDataReport) MRetryableTask(org.infobip.mobile.messaging.mobile.common.MRetryableTask) SystemData(org.infobip.mobile.messaging.SystemData)

Example 2 with SystemDataReport

use of org.infobip.mobile.messaging.api.data.SystemDataReport in project mobile-messaging-sdk-android by infobip.

the class MobileApiDataTest method create_systemData_success_examineRequest.

@Test
public void create_systemData_success_examineRequest() throws Exception {
    // prepare request data
    SystemDataReport systemDataReport = new SystemDataReport();
    systemDataReport.setSdkVersion("1.2.3.TEST");
    systemDataReport.setOsVersion("0.1.2.TEST");
    systemDataReport.setDeviceManufacturer("INFOBIP");
    systemDataReport.setDeviceModel("TEST");
    systemDataReport.setApplicationVersion("3.4.5.TEST");
    systemDataReport.setGeofencing(false);
    systemDataReport.setNotificationsEnabled(true);
    systemDataReport.setDeviceSecure(true);
    // prepare server
    debugServer.respondWith(NanoHTTPD.Response.Status.OK, null);
    // send request
    mobileApiData.reportSystemData(systemDataReport);
    // inspect http context
    assertEquals("/mobile/2/data/system", debugServer.getUri());
    assertEquals(1, debugServer.getRequestCount());
    assertEquals(NanoHTTPD.Method.POST, debugServer.getRequestMethod());
    assertEquals(0, debugServer.getQueryParametersCount());
    assertEquals("App my_API_key", debugServer.getHeader("Authorization"));
    assertNotNull(debugServer.getBody());
    // inspect request
    JSONAssert.assertEquals("{" + "'sdkVersion':'1.2.3.TEST'," + "'osVersion':'0.1.2.TEST'," + "'deviceManufacturer':'INFOBIP'," + "'deviceModel':'TEST'," + "'applicationVersion':'3.4.5.TEST'," + "'geofencing':false," + "'notificationsEnabled':true," + "'deviceSecure':true" + "}", debugServer.getBody(), true);
}
Also used : SystemDataReport(org.infobip.mobile.messaging.api.data.SystemDataReport) Test(org.junit.Test)

Aggregations

SystemDataReport (org.infobip.mobile.messaging.api.data.SystemDataReport)2 SystemData (org.infobip.mobile.messaging.SystemData)1 MRetryableTask (org.infobip.mobile.messaging.mobile.common.MRetryableTask)1 Test (org.junit.Test)1