@Test public void currentUser_v1_From_v2() throws Exception { JSONObject localFileData = new JSONObject(); localFileData.put("sessionToken", "dummySessionToken"); localFileData.put("phone", "000-000-0000"); localFileData.put("objectId", "dummyUserId"); localFileData.put("mailAddress", "email@example.com"); localFileData.put("classname", "user"); localFileData.put("userName", "dummyUser"); localFileData.put("password", "dummyPassword"); localFileData.put("createDate", "2015-09-10T02:24:03.597Z"); localFileData.put("updateDate", "2015-09-11T02:24:03.597Z"); File localFile = new File(NCMB.getCurrentContext().context.getDir("NCMB", Context.MODE_PRIVATE), "currentUser"); try { FileOutputStream out = new FileOutputStream(localFile); out.write(localFileData.toString().getBytes("UTF-8")); out.close(); } catch (IOException e) { throw new RuntimeException(e); } NCMBUser currentUser = NCMBUser.getCurrentUser(); Assert.assertEquals("dummySessionToken", currentUser.getString("sessionToken")); Assert.assertEquals("dummySessionToken", NCMB.getCurrentContext().sessionToken); Assert.assertEquals("000-000-0000", currentUser.getString("phone")); Assert.assertEquals("dummyUserId", currentUser.getObjectId()); Assert.assertEquals("email@example.com", currentUser.getMailAddress()); Assert.assertEquals("dummyUser", currentUser.getUserName()); DateFormat format = NCMBDateFormat.getIso8601(); Date resultCreateDate = format.parse("2015-09-10T02:24:03.597Z"); Assert.assertEquals(resultCreateDate, currentUser.getCreateDate()); Date resultUpdateDate = format.parse("2015-09-11T02:24:03.597Z"); Assert.assertEquals(resultUpdateDate, currentUser.getUpdateDate()); NCMBUserService userService = (NCMBUserService) NCMB.factory(NCMB.ServiceType.USER); try { JSONObject update = new JSONObject("{key:value}"); userService.updateUser(currentUser.getObjectId(), update); } catch (NCMBException error) { Assert.fail(error.getMessage()); } }
public JSONObject updateUser(String userId, JSONObject params) throws NCMBException { RequestParams reqParams = updateUserParams(userId, params); NCMBResponse response = sendRequest(reqParams); try { params.put("objectId", userId); } catch (JSONException e) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, e.getMessage()); } updateUserCheckResponse(response); writeCurrentUser(params, response.responseData); return response.responseData; }
NCMBUserService extends NCMBService { public JSONObject updateUser(String userId, JSONObject params) throws NCMBException { RequestParams reqParams = updateUserParams(userId, params); NCMBResponse response = sendRequest(reqParams); try { params.put("objectId", userId); } catch (JSONException e) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, e.getMessage()); } updateUserCheckResponse(response); writeCurrentUser(params, response.responseData); return response.responseData; } }
NCMBUserService extends NCMBService { public JSONObject updateUser(String userId, JSONObject params) throws NCMBException { RequestParams reqParams = updateUserParams(userId, params); NCMBResponse response = sendRequest(reqParams); try { params.put("objectId", userId); } catch (JSONException e) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, e.getMessage()); } updateUserCheckResponse(response); writeCurrentUser(params, response.responseData); return response.responseData; } NCMBUserService(NCMBContext context); }
NCMBUserService extends NCMBService { public JSONObject updateUser(String userId, JSONObject params) throws NCMBException { RequestParams reqParams = updateUserParams(userId, params); NCMBResponse response = sendRequest(reqParams); try { params.put("objectId", userId); } catch (JSONException e) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, e.getMessage()); } updateUserCheckResponse(response); writeCurrentUser(params, response.responseData); return response.responseData; } NCMBUserService(NCMBContext context); NCMBUser registerByName(String userName, String password); NCMBUser registerByName(String userName, String password,JSONObject otherFields); void saveByName(String userName, String password); void saveByName(String userName, String password,JSONObject otherFields); void registerByNameInBackground(String userName, String password, LoginCallback callback); void registerByNameInBackground(String userName, String password, JSONObject otherFields, LoginCallback callback); NCMBUser registerByOauth(JSONObject oauthOptions); void registerByOauthInBackground(JSONObject oauthOptions, LoginCallback callback); void inviteByMail(String mailAddress); void inviteByMailInBackground(String mailAddress, DoneCallback callback); void requestPasswordReset(String mailAddress); void requestPasswordResetInBackground(String mailAddress, DoneCallback callback); NCMBUser fetchUser(String userId); void fetchUserInBackground(String userId, final FetchCallback callback); JSONObject updateUser(String userId, JSONObject params); void updateUserInBackground(final String userId, final JSONObject params, final ExecuteServiceCallback callback); NCMBUser loginByName(String userName, String password); void loginByNameInBackground(String userName, String password,
                                        LoginCallback callback); NCMBUser loginByMail(String mailAddress, String password); void loginByMailInBackground(String mailAddress, String password,
                                        LoginCallback callback); void deleteUser(String userId); void deleteUserInBackground(final String userId, ExecuteServiceCallback callback); void logout(); void logoutInBackground(DoneCallback callback); ArrayList<NCMBUser> searchUser(JSONObject conditions); void searchUserInBackground(JSONObject conditions, final SearchUserCallback callback); }
NCMBUserService extends NCMBService { public JSONObject updateUser(String userId, JSONObject params) throws NCMBException { RequestParams reqParams = updateUserParams(userId, params); NCMBResponse response = sendRequest(reqParams); try { params.put("objectId", userId); } catch (JSONException e) { throw new NCMBException(NCMBException.NOT_EFFICIENT_VALUE, e.getMessage()); } updateUserCheckResponse(response); writeCurrentUser(params, response.responseData); return response.responseData; } NCMBUserService(NCMBContext context); NCMBUser registerByName(String userName, String password); NCMBUser registerByName(String userName, String password,JSONObject otherFields); void saveByName(String userName, String password); void saveByName(String userName, String password,JSONObject otherFields); void registerByNameInBackground(String userName, String password, LoginCallback callback); void registerByNameInBackground(String userName, String password, JSONObject otherFields, LoginCallback callback); NCMBUser registerByOauth(JSONObject oauthOptions); void registerByOauthInBackground(JSONObject oauthOptions, LoginCallback callback); void inviteByMail(String mailAddress); void inviteByMailInBackground(String mailAddress, DoneCallback callback); void requestPasswordReset(String mailAddress); void requestPasswordResetInBackground(String mailAddress, DoneCallback callback); NCMBUser fetchUser(String userId); void fetchUserInBackground(String userId, final FetchCallback callback); JSONObject updateUser(String userId, JSONObject params); void updateUserInBackground(final String userId, final JSONObject params, final ExecuteServiceCallback callback); NCMBUser loginByName(String userName, String password); void loginByNameInBackground(String userName, String password,
                                        LoginCallback callback); NCMBUser loginByMail(String mailAddress, String password); void loginByMailInBackground(String mailAddress, String password,
                                        LoginCallback callback); void deleteUser(String userId); void deleteUserInBackground(final String userId, ExecuteServiceCallback callback); void logout(); void logoutInBackground(DoneCallback callback); ArrayList<NCMBUser> searchUser(JSONObject conditions); void searchUserInBackground(JSONObject conditions, final SearchUserCallback callback); static final String SERVICE_PATH; static final int HTTP_STATUS_REGISTERED; static final int HTTP_STATUS_AUTHORIZED; static final int HTTP_STATUS_REQUEST_ACCEPTED; }