@Test public void testParsing() throws Exception { String val = "{\"UserIdentities\":[{\"Type\":1,\"Identity\":\"123\"},{\"Type\":7,\"Identity\":\"test@gmail.com\"}]}"; IdentityApiRequest request = getIdentityApiRequest(new JSONObject(val)); request.getUserIdentities().toString(); }
protected IdentityApiRequest getIdentityApiRequest(JSONObject jsonObject) { JSONArray identitiesArray = jsonObject.optJSONArray(USER_IDENTITIES); Map<MParticle.IdentityType, String> identities = new HashMap<MParticle.IdentityType, String>(); if (identitiesArray != null) { for (int i = 0; i < identitiesArray.length(); i++) { try { JSONObject object = identitiesArray.getJSONObject(i); identities.put(getIdentityType(object), object.getString(IDENTITY)); } catch (JSONException jse){ Logger.warning(String.format(errorMsg, jse.getMessage())); } } } IdentityApiRequest.Builder builder = IdentityApiRequest.withEmptyUser() .userIdentities(identities); if (jsonObject.has(TYPE) && jsonObject.has(IDENTITY)) { MParticle.IdentityType type = getIdentityType(jsonObject); String value = jsonObject.optString(IDENTITY); if (type != null && !MPUtility.isEmpty(value)) { builder.userIdentity(type, value); } } return builder.build(); }
MParticleJSInterface { protected IdentityApiRequest getIdentityApiRequest(JSONObject jsonObject) { JSONArray identitiesArray = jsonObject.optJSONArray(USER_IDENTITIES); Map<MParticle.IdentityType, String> identities = new HashMap<MParticle.IdentityType, String>(); if (identitiesArray != null) { for (int i = 0; i < identitiesArray.length(); i++) { try { JSONObject object = identitiesArray.getJSONObject(i); identities.put(getIdentityType(object), object.getString(IDENTITY)); } catch (JSONException jse){ Logger.warning(String.format(errorMsg, jse.getMessage())); } } } IdentityApiRequest.Builder builder = IdentityApiRequest.withEmptyUser() .userIdentities(identities); if (jsonObject.has(TYPE) && jsonObject.has(IDENTITY)) { MParticle.IdentityType type = getIdentityType(jsonObject); String value = jsonObject.optString(IDENTITY); if (type != null && !MPUtility.isEmpty(value)) { builder.userIdentity(type, value); } } return builder.build(); } }
MParticleJSInterface { protected IdentityApiRequest getIdentityApiRequest(JSONObject jsonObject) { JSONArray identitiesArray = jsonObject.optJSONArray(USER_IDENTITIES); Map<MParticle.IdentityType, String> identities = new HashMap<MParticle.IdentityType, String>(); if (identitiesArray != null) { for (int i = 0; i < identitiesArray.length(); i++) { try { JSONObject object = identitiesArray.getJSONObject(i); identities.put(getIdentityType(object), object.getString(IDENTITY)); } catch (JSONException jse){ Logger.warning(String.format(errorMsg, jse.getMessage())); } } } IdentityApiRequest.Builder builder = IdentityApiRequest.withEmptyUser() .userIdentities(identities); if (jsonObject.has(TYPE) && jsonObject.has(IDENTITY)) { MParticle.IdentityType type = getIdentityType(jsonObject); String value = jsonObject.optString(IDENTITY); if (type != null && !MPUtility.isEmpty(value)) { builder.userIdentity(type, value); } } return builder.build(); } MParticleJSInterface(); }
MParticleJSInterface { protected IdentityApiRequest getIdentityApiRequest(JSONObject jsonObject) { JSONArray identitiesArray = jsonObject.optJSONArray(USER_IDENTITIES); Map<MParticle.IdentityType, String> identities = new HashMap<MParticle.IdentityType, String>(); if (identitiesArray != null) { for (int i = 0; i < identitiesArray.length(); i++) { try { JSONObject object = identitiesArray.getJSONObject(i); identities.put(getIdentityType(object), object.getString(IDENTITY)); } catch (JSONException jse){ Logger.warning(String.format(errorMsg, jse.getMessage())); } } } IdentityApiRequest.Builder builder = IdentityApiRequest.withEmptyUser() .userIdentities(identities); if (jsonObject.has(TYPE) && jsonObject.has(IDENTITY)) { MParticle.IdentityType type = getIdentityType(jsonObject); String value = jsonObject.optString(IDENTITY); if (type != null && !MPUtility.isEmpty(value)) { builder.userIdentity(type, value); } } return builder.build(); } MParticleJSInterface(); @JavascriptInterface String getCurrentMpId(); @JavascriptInterface void login(); @JavascriptInterface void login(String json); @JavascriptInterface void logout(); @JavascriptInterface void logout(String json); @JavascriptInterface void modify(String json); @JavascriptInterface void logEvent(String json); @JavascriptInterface void setUserTag(String json); @JavascriptInterface void removeUserTag(String json); @JavascriptInterface void setUserAttribute(String json); @JavascriptInterface void removeUserAttribute(String json); @JavascriptInterface void setSessionAttribute(String json); @JavascriptInterface void setUserIdentity(String json); @JavascriptInterface void removeUserIdentity(String json); @JavascriptInterface void addToCart(String json); @JavascriptInterface void removeFromCart(String json); @JavascriptInterface void clearCart(); @JavascriptInterface void setUserAttributeList(String json); @JavascriptInterface void removeAllUserAttributes(); @JavascriptInterface String getUserAttributesLists(); @JavascriptInterface String getAllUserAttributes(); static void registerWebView(WebView webView, String workspaceToken); }
MParticleJSInterface { protected IdentityApiRequest getIdentityApiRequest(JSONObject jsonObject) { JSONArray identitiesArray = jsonObject.optJSONArray(USER_IDENTITIES); Map<MParticle.IdentityType, String> identities = new HashMap<MParticle.IdentityType, String>(); if (identitiesArray != null) { for (int i = 0; i < identitiesArray.length(); i++) { try { JSONObject object = identitiesArray.getJSONObject(i); identities.put(getIdentityType(object), object.getString(IDENTITY)); } catch (JSONException jse){ Logger.warning(String.format(errorMsg, jse.getMessage())); } } } IdentityApiRequest.Builder builder = IdentityApiRequest.withEmptyUser() .userIdentities(identities); if (jsonObject.has(TYPE) && jsonObject.has(IDENTITY)) { MParticle.IdentityType type = getIdentityType(jsonObject); String value = jsonObject.optString(IDENTITY); if (type != null && !MPUtility.isEmpty(value)) { builder.userIdentity(type, value); } } return builder.build(); } MParticleJSInterface(); @JavascriptInterface String getCurrentMpId(); @JavascriptInterface void login(); @JavascriptInterface void login(String json); @JavascriptInterface void logout(); @JavascriptInterface void logout(String json); @JavascriptInterface void modify(String json); @JavascriptInterface void logEvent(String json); @JavascriptInterface void setUserTag(String json); @JavascriptInterface void removeUserTag(String json); @JavascriptInterface void setUserAttribute(String json); @JavascriptInterface void removeUserAttribute(String json); @JavascriptInterface void setSessionAttribute(String json); @JavascriptInterface void setUserIdentity(String json); @JavascriptInterface void removeUserIdentity(String json); @JavascriptInterface void addToCart(String json); @JavascriptInterface void removeFromCart(String json); @JavascriptInterface void clearCart(); @JavascriptInterface void setUserAttributeList(String json); @JavascriptInterface void removeAllUserAttributes(); @JavascriptInterface String getUserAttributesLists(); @JavascriptInterface String getAllUserAttributes(); static void registerWebView(WebView webView, String workspaceToken); static final String INTERFACE_BASE_NAME; }