Пример #1
0
 private void register(RequestItem item, Action <JObject, Exception> callback)
 {
     if (String.IsNullOrEmpty(item.getEmail()))
     {
         if (callback != null)
         {
             callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserEmail + " is required"));
         }
     }
     if (String.IsNullOrEmpty(item.getNickname()))
     {
         if (callback != null)
         {
             callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserNickname + " is required"));
         }
     }
     if (String.IsNullOrEmpty(item.getPassword()))
     {
         if (callback != null)
         {
             callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserPassword + " is required"));
         }
     }
     NetmeraHttpUtils.registerUser(item, (json, e) =>
     {
         if (json != null)
         {
             if (json["entry"] != null && json["entry"].First != null)
             {
                 if (callback != null)
                 {
                     callback((JObject)json.First.First, e);
                 }
             }
             else if (json["error"] != null)
             {
                 String error = json["error"]["message"].ToString();
                 if (callback != null)
                 {
                     callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, error));
                 }
             }
             else
             {
                 if (callback != null)
                 {
                     callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, "Error occurred while registering user"));
                 }
             }
         }
         else
         {
             if (callback != null)
             {
                 callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_USER_UPDATE_ERROR, "Error occurred while registering user"));
             }
         }
     });
 }
Пример #2
0
        private JObject register(RequestItem item)
        {
            JObject json = null;

            if (String.IsNullOrEmpty(item.getEmail()))
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserEmail + " is required");
            }
            if (String.IsNullOrEmpty(item.getNickname()))
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserNickname + " is required");
            }
            if (String.IsNullOrEmpty(item.getPassword()))
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserPassword + " is required");
            }
            try
            {
                json = NetmeraHttpUtils.registerUser(item);
            }
            catch (NetmeraException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_REGISTER_ERROR, "Error occurred while registering user");
            }

            if (json != null)
            {
                if (json["entry"] != null && json["entry"].Count() != 0)
                {
                    return((JObject)json.First.First);
                }
                else if (json["error"] != null)
                {
                    String error = json["error"]["message"].ToString();
                    throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_REGISTER_ERROR, error);
                }
                else
                {
                    throw new NetmeraException(NetmeraException.ErrorCode.EC_USER_REGISTER_ERROR, "Error occurred while registering user");
                }
            }
            return(null);
        }
Пример #3
0
        public static JObject login(RequestItem item)
        {
            String securityToken = NetmeraClient.getSecurityToken();

            if (securityToken != null && securityToken.Trim() != "")
            {
                StringBuilder strBuildForJson = new StringBuilder()
                                                .Append("{\"" + NetmeraConstants.Params_Params + "\":{")
                                                .Append("\"" + NetmeraConstants.Netmera_UserEmail + "\" : \"" + item.getEmail() + "\"").Append(",")
                                                .Append("\"" + NetmeraConstants.Netmera_UserPassword + "\" : \"" + item.getPassword() + "\"")
                                                .Append(" },\"" + NetmeraConstants.Method_Params + "\":\"" + NetmeraConstants.Netmera_LoginUser_Method + "\"}");

                StringBuilder strBuildForUrl = new StringBuilder()
                                               .Append(NetmeraConstants.Netmera_Domain_Url)
                                               .Append(NetmeraConstants.Netmera_Domain_Rpc_Url)
                                               .Append(NetmeraConstants.SecurityToken_Params).Append("=").Append(securityToken);

                return(sendHttpWithJson(strBuildForUrl.ToString(), strBuildForJson.ToString(), NetmeraConstants.Http_Method_Post));
            }
            else
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_API_KEY_NOT_FOUND, "You didn't set your api key. Please use NetmeraClient.init(apiKey).");
            }
        }
Пример #4
0
        public static JObject registerUser(RequestItem item)
        {
            String securityToken = NetmeraClient.getSecurityToken();

            if (securityToken != null && securityToken.Trim() != "")
            {
                StringBuilder strBuild = new StringBuilder()
                                         .Append(NetmeraConstants.Netmera_Domain_Url)
                                         .Append(NetmeraConstants.Netmera_Domain_Rest_Url)
                                         .Append(NetmeraConstants.Netmera_RegisterUser_Url)
                                         .Append(NetmeraConstants.SecurityToken_Params).Append("=").Append(securityToken).Append("&")
                                         .Append(NetmeraConstants.Netmera_UserEmail).Append("=").Append(item.getEmail()).Append("&")
                                         .Append(NetmeraConstants.Netmera_UserPassword).Append("=").Append(item.getPassword()).Append("&")
                                         .Append(NetmeraConstants.Netmera_UserNickname).Append("=").Append(item.getNickname()).Append("&")
                                         .Append(NetmeraConstants.Netmera_UserName).Append("=").Append(item.getName()).Append("&")
                                         .Append(NetmeraConstants.Netmera_UserSurname).Append("=").Append(item.getSurname());

                return(sendHttp(strBuild.ToString(), NetmeraConstants.Http_Method_Post));
            }
            else
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_API_KEY_NOT_FOUND, "You didn't set your api key. Please use NetmeraClient.init(apiKey).");
            }
        }