/// <summary> /// Registers new user. Before calling this method email,password and /// nickname fields of the <see cref="NetmeraUser"/> should be set. Those are /// the compulsory fields. There are also optional name and surname fields. /// </summary> public void register() { try { RequestItem registerUserReqItem = new RequestItem(); registerUserReqItem.setEmail(email); registerUserReqItem.setPassword(password); registerUserReqItem.setNickname(nickname); registerUserReqItem.setName(name); registerUserReqItem.setSurname(surname); JObject jUser = register(registerUserReqItem); setUser(jUser); } catch (WebException) { throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred while registering user"); } catch (IOException) { throw new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while registering user"); } catch (JsonException) { throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of register user method is invalid"); } }
/// <summary> /// Updates user info. Before calling this method email,password and nickname /// fields of the <see cref="NetmeraUser"/> should be set. Those are the /// compulsory fields. /// </summary> public void update() { JObject jProfile = null; JObject jAccount = null; try { RequestItem updateUserReqItem = new RequestItem(); updateUserReqItem.setEmail(email); updateUserReqItem.setPassword(password); updateUserReqItem.setNickname(nickname); updateUserReqItem.setName(name); updateUserReqItem.setSurname(surname); if (nickname != null) { jProfile = profileUpdate(updateUserReqItem); setUser(jProfile); if (password != null) { jAccount = accountUpdate(updateUserReqItem); } } else if (password != null) { jAccount = accountUpdate(updateUserReqItem); setUser(jAccount); } } catch (WebException) { throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Web exception occurred while updating user"); } catch (IOException) { throw new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while updating user"); } catch (JsonException) { throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of update user method is invalid"); } }
private static void registerAndLogin(String fbId, String nickname, String name, String surname, String email, Action <NetmeraUser, Exception> callback) { NetmeraUser user = new NetmeraUser(); RequestItem loginFbUserUserReqItem = new RequestItem(); loginFbUserUserReqItem.setFbId(fbId); loginFbUserUserReqItem.setNickname(nickname); loginFbUserUserReqItem.setName(name); loginFbUserUserReqItem.setSurname(surname); loginFbUserUserReqItem.setEmail(email); NetmeraUser.facebookRegister(loginFbUserUserReqItem, (json, ex) => { if (json == null || ex != null) { if (callback != null) { callback(null, ex); } } else { try { user = NetmeraUser.setCurrentUser(json); if (callback != null) { callback(user, ex); } } catch (NetmeraException e) { if (callback != null) { callback(null, e); } } } }); }
/// <summary> /// Updates user info. Before calling this method email,password and nickname /// fields of the <see cref="NetmeraUser"/> should be set. Those are the /// compulsory fields. /// </summary> /// <param name="callback">Method called when user update operation finishes</param> public void update(Action <NetmeraUser, Exception> callback) { try { RequestItem updateUserReqItem = new RequestItem(); updateUserReqItem.setEmail(email); updateUserReqItem.setPassword(password); updateUserReqItem.setNickname(nickname); updateUserReqItem.setName(name); updateUserReqItem.setSurname(surname); if (nickname != null) { profileUpdate(updateUserReqItem, (jsonp, ex) => { if (jsonp == null || ex != null) { if (callback != null) { callback(null, ex); } } else { try { setUser(jsonp); if (callback != null) { callback(this, ex); } if (password != null) { accountUpdate(updateUserReqItem, (jsona, e) => { if (callback != null) { callback(this, e); } }); } if (callback != null) { callback(this, ex); } } catch (NetmeraException e) { if (callback != null) { callback(null, e); } } } }); } else if (password != null) { accountUpdate(updateUserReqItem, (jsona, ex) => { if (jsona == null || ex != null) { if (callback != null) { callback(null, ex); } } else { try { setUser(jsona); if (callback != null) { callback(this, ex); } } catch (NetmeraException e) { if (callback != null) { callback(null, e); } } } }); } } catch (WebException) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Web exception occurred while updating user")); } } catch (IOException) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while updating user")); } } catch (JsonException) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of update user method is invalid")); } } }
/// <summary> /// Registers new user. Before calling this method email,password and /// nickname fields of the <see cref="NetmeraUser"/> should be set. Those are /// the compulsory fields. There are also optional name and surname fields. /// </summary> /// <param name="callback">method called when user register operation finishes</param> public void register(Action <NetmeraUser, Exception> callback) { try { RequestItem registerUserReqItem = new RequestItem(); registerUserReqItem.setEmail(email); registerUserReqItem.setPassword(password); registerUserReqItem.setNickname(nickname); registerUserReqItem.setName(name); registerUserReqItem.setSurname(surname); register(registerUserReqItem, (json, ex) => { if (json == null || ex != null) { if (callback != null) { callback(null, ex); } } else { try { setUser(json); if (callback != null) { callback(this, ex); } } catch (NetmeraException e) { if (callback != null) { callback(null, e); } } } }); } catch (WebException) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred while registering user")); } } catch (IOException) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while registering user")); } } catch (JsonException) { if (callback != null) { callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of register user method is invalid")); } } }