Search in sources :

Example 6 with RtmMessage

use of com.fitpay.android.webview.events.RtmMessage in project fitpay-android-sdk by fitpay.

the class RtmParserTest method testWebAppVersionSame.

@Test
public void testWebAppVersionSame() {
    String rtmMsgStr = "{\"callbackId\":\"0\",\"data\":\"{\\\"version\\\":3}\",\"type\":\"version\"}";
    RtmMessage msg = Constants.getGson().fromJson(rtmMsgStr, RtmMessage.class);
    int webAppRtmVersion = RtmType.RTM_VERSION;
    String errorMsg = null;
    try {
        RtmParserImpl.parse(wvci, webAppRtmVersion, msg);
    } catch (IllegalStateException e) {
        errorMsg = e.getMessage();
    }
    Assert.assertNull(errorMsg);
}
Also used : RtmMessage(com.fitpay.android.webview.events.RtmMessage) Test(org.junit.Test)

Example 7 with RtmMessage

use of com.fitpay.android.webview.events.RtmMessage in project fitpay-android-sdk by fitpay.

the class WebViewCommunicatorImpl method dispatchMessage.

@Override
@JavascriptInterface
public void dispatchMessage(String message) throws JSONException {
    if (message == null) {
        FPLog.w(WV_DATA, "\\Received\\: invalid message");
        throw new IllegalArgumentException("invalid message");
    }
    JSONObject obj = new JSONObject(message);
    String callBackId = obj.getString("callBackId");
    if (callBackId == null) {
        FPLog.w(WV_DATA, "\\Received\\: callBackId is missing in the message");
        throw new IllegalArgumentException("callBackId is missing in the message");
    }
    String type = obj.getString("type");
    if (type == null) {
        FPLog.w(WV_DATA, "\\Received\\: type is missing in the message");
        throw new IllegalArgumentException("type is missing in the message");
    }
    FPLog.i(WV_DATA, String.format(Locale.getDefault(), "\\Received\\: callbackId:%s type:%s", callBackId, type));
    String dataStr = obj.has("data") ? obj.getString("data") : null;
    RxBus.getInstance().post(new RtmMessage(callBackId, dataStr, type));
}
Also used : RtmMessage(com.fitpay.android.webview.events.RtmMessage) JSONObject(org.json.JSONObject) JavascriptInterface(android.webkit.JavascriptInterface)

Aggregations

RtmMessage (com.fitpay.android.webview.events.RtmMessage)7 Test (org.junit.Test)6 JavascriptInterface (android.webkit.JavascriptInterface)1 BearerTokenTest (com.fitpay.android.BearerTokenTest)1 JSONObject (org.json.JSONObject)1 Ignore (org.junit.Ignore)1