Exemplo n.º 1
0
        /// <summary>
        /// Logs a user into the registered application. Email and password fields of
        /// user is used for this operation.
        /// </summary>
        /// <param name="email">Email of the user</param>
        /// <param name="password">Password of the user</param>
        /// <returns>The logged user</returns>
        public static NetmeraUser login(String email, String password)
        {
            NetmeraUser user = new NetmeraUser();

            try
            {
                RequestItem loginUserReqItem = new RequestItem();
                loginUserReqItem.setEmail(email);
                loginUserReqItem.setPassword(password);

                JObject jLogin = login(loginUserReqItem);
                if (jLogin != null)
                {
                    user = setCurrentUser(jLogin);
                }
                else
                {
                    throw new NetmeraException(NetmeraException.ErrorCode.EC_NULL_EXCEPTION, "Response of user login method is null");
                }
            }
            catch (WebException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Web exception occurred in user login method");
            }
            catch (IOException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred in user login method");
            }
            catch (JsonException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of user login method is invalid");
            }

            return(user);
        }
Exemplo n.º 2
0
        /// <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");
            }
        }
Exemplo n.º 3
0
        public static JObject accountUpdate(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(",")
                                                .Append("\"" + NetmeraConstants.Netmera_UserName + "\" : \"" + item.getName() + "\"").Append(",")
                                                .Append("\"" + NetmeraConstants.Netmera_UserSurname + "\" : \"" + item.getSurname() + "\"")
                                                .Append(" },\"" + NetmeraConstants.Method_Params + "\":\"" + NetmeraConstants.Netmera_PeopleAccountUpdate_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).");
            }
        }
Exemplo n.º 4
0
        private void deactivateUser(String email, Action <Exception> callback)
        {
            try
            {
                RequestItem deactivateUserReqItem = new RequestItem();
                deactivateUserReqItem.setEmail(email);

                deactivateUser(deactivateUserReqItem, ex =>
                {
                    if (callback != null)
                    {
                        callback(ex);
                    }
                });
            }
            catch (WebException)
            {
                if (callback != null)
                {
                    callback(new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred while activating user"));
                }
            }
            catch (IOException)
            {
                if (callback != null)
                {
                    callback(new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while activating user"));
                }
            }
        }
Exemplo n.º 5
0
        public static JObject locationSearch(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_LocationSearchContent_Url)
                                         .Append(NetmeraConstants.SecurityToken_Params).Append("=").Append(securityToken).Append("&")
                                         .Append(NetmeraConstants.Path_Params).Append("=").Append(NetmeraConstants.Default_ParentPath).Append("&")
                                         .Append(NetmeraConstants.ContentType_Params).Append("=").Append(NetmeraConstants.Default_ContentType).Append("&")
                                         .Append(NetmeraConstants.CustomCondition_Params).Append("=").Append(item.customCondition).Append("&")
                                         .Append(NetmeraConstants.SearchText_Params).Append("=").Append(item.searchText).Append("&")
                                         .Append(NetmeraConstants.Max_Params).Append("=").Append(item.max).Append("&")
                                         .Append(NetmeraConstants.Page_Params).Append("=").Append(item.page).Append("&")
                                         .Append(NetmeraConstants.SortBy_Params).Append("=").Append(item.sortBy).Append("&")
                                         .Append(NetmeraConstants.SortOrder_Params).Append("=").Append(item.sortOrder).Append("&")
                                         .Append(NetmeraConstants.LocationSearchType_Params).Append("=").Append(item.locationSearchType).Append("&")
                                         .Append(NetmeraConstants.LocationSearchField_Params).Append("=").Append(item.locationSearchField + NetmeraConstants.LocationField_Suffix).Append("&")
                                         .Append(NetmeraConstants.LocationLatitude_Params).Append("=").Append(item.latitudes).Append("&")
                                         .Append(NetmeraConstants.LocationLongitude_Params).Append("=").Append(item.longitudes).Append("&")
                                         .Append(NetmeraConstants.LocationDistance_Params).Append("=").Append(item.distance).Append("&");

                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).");
            }
        }
Exemplo n.º 6
0
        public static JObject searchUser(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_PeopleSearch_Url)
                                         .Append(NetmeraConstants.SecurityToken_Params).Append("=").Append(securityToken).Append("&")
                                         .Append(NetmeraConstants.Path_Params).Append("=").Append(item.path).Append("&")
                                         .Append(NetmeraConstants.SearchText_Params).Append("=").Append(item.searchText).Append("&")
                                         .Append(NetmeraConstants.CustomCondition_Params).Append("=").Append(item.customCondition).Append("&")
                                         .Append(NetmeraConstants.Max_Params).Append("=").Append(item.max).Append("&")
                                         .Append(NetmeraConstants.Page_Params).Append("=").Append(item.page).Append("&")
                                         .Append(NetmeraConstants.SortBy_Params).Append("=").Append(item.sortBy).Append("&")
                                         .Append(NetmeraConstants.SortOrder_Params).Append("=").Append(item.sortOrder).Append("&")
                                         .Append(NetmeraConstants.Filter_Params).Append("=").Append(item.filterBy).Append("&")
                                         .Append(NetmeraConstants.FilterValue_Params).Append("=").Append(item.filterValue).Append("&")
                                         .Append(NetmeraConstants.FilterOperation_Params).Append("=").Append(item.filterOperation).Append("&");

                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).");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Searches the content by taking given location as a base and retrieves the contents that located given distance far away.
        /// </summary>
        /// <param name="startLocation">Base location to search near it.</param>
        /// <param name="distance">Distance used to create circle by taking the startLocation as a center.</param>
        /// <param name="locationSearchField">Name of the field that holds location data.</param>
        /// <returns>The list of <see cref="NetmeraContent"/>  object.</returns>
        public List <NetmeraContent> circleSearch(NetmeraGeoLocation startLocation, double distance, String locationSearchField)
        {
            RequestItem item = new RequestItem();

            item.path            = NetmeraConstants.Default_ParentPath;
            item.contentType     = NetmeraConstants.Default_ContentType;
            item.max             = max;
            item.page            = page;
            item.sortBy          = sortBy;
            item.sortOrder       = sortOrder.ToString();
            item.customCondition = getCustomCondition();

            if (searchText != null)
            {
                item.searchText = searchText;
            }

            item.locationSearchType  = NetmeraConstants.LocationSearchType_Circle;
            item.distance            = distance;
            item.latitudes           = startLocation.getLatitude().ToString();
            item.longitudes          = startLocation.getLongitude().ToString();
            item.locationSearchField = locationSearchField;

            JArray jsonArray = new JArray(NetmeraHttpUtils.locationSearch(item));

            return(convertJsonArrayToNetmeraContent(jsonArray));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Retrieves the list of <see cref="NetmeraUser"/> objects that matches with the
        /// query.
        /// </summary>
        /// <param name="callback">Method called when user search operation finishes</param>
        public void searchUser(Action <List <NetmeraUser>, Exception> callback)
        {
            RequestItem item      = new RequestItem();
            JArray      jsonArray = new JArray();

            if (searchText != null)
            {
                item.searchText = searchText;
            }

            item.path            = NetmeraConstants.Netmera_People_Url;
            item.max             = max;
            item.page            = page;
            item.sortBy          = sortBy;
            item.sortOrder       = sortOrder.ToString();
            item.customCondition = getUserCustomCondition();

            searchUser(item, (users, ex) =>
            {
                if (callback != null)
                {
                    callback(users, ex);
                }
            });
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets the NetmeraContent from the network, not the cache.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private NetmeraContent getFromNetwork(String path)
        {
            RequestItem item = new RequestItem();

            if (path == null || path.Length == 0)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_NULL_EXCEPTION, "Path cannot be null or empty");
            }

            item.path            = path;
            item.page            = page;
            item.contentType     = NetmeraConstants.Default_ContentType;
            item.customCondition = getCustomCondition();

            JArray jsonArray = new JArray(NetmeraHttpUtils.get(item));

            List <NetmeraContent> contentList = convertJsonArrayToNetmeraContent(jsonArray);

            if (contentList != null && contentList.Count != 0)
            {
                return(contentList.First());
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 10
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"));
             }
         }
     });
 }
Exemplo n.º 11
0
 private void deactivateUser(RequestItem item)
 {
     if (String.IsNullOrEmpty(item.getEmail()))
     {
         throw new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserEmail + " is required");
     }
     NetmeraHttpUtils.deactivateUser(item);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Creates box using the given two location (latitude,longitude) data and searches inside that box.
        /// </summary>
        /// <param name="firstPoint"><see cref="NetmeraGeoLocation"/>  object</param>
        /// <param name="secondPoint"><see cref="NetmeraGeoLocation"/>  object</param>
        /// <param name="locationSearchField">Name of the field that holds location data.</param>
        /// <returns>The list of <see cref="NetmeraContent"/>  object.</returns>
        public List <NetmeraContent> boxSearch(NetmeraGeoLocation firstPoint, NetmeraGeoLocation secondPoint, String locationSearchField)
        {
            RequestItem item = new RequestItem();

            item.path            = NetmeraConstants.Default_ParentPath;
            item.contentType     = NetmeraConstants.Default_ContentType;
            item.max             = max;
            item.page            = page;
            item.sortBy          = sortBy;
            item.sortOrder       = sortOrder.ToString();
            item.customCondition = getCustomCondition();

            if (searchText != null)
            {
                item.searchText = searchText;
            }

            item.locationSearchType = NetmeraConstants.LocationSearchType_Box;

            StringBuilder latitudes  = new StringBuilder();
            StringBuilder longitudes = new StringBuilder();

            if (firstPoint.getLatitude() < secondPoint.getLatitude())
            {
                latitudes.Append(firstPoint.getLatitude().ToString()).Append(",").Append(secondPoint.getLatitude().ToString());
            }
            else
            {
                latitudes.Append(secondPoint.getLatitude().ToString()).Append(",").Append(firstPoint.getLatitude().ToString());
            }

            if (firstPoint.getLongitude() < secondPoint.getLongitude())
            {
                longitudes.Append(firstPoint.getLongitude().ToString()).Append(",").Append(secondPoint.getLongitude().ToString());
            }
            else
            {
                longitudes.Append(secondPoint.getLongitude().ToString()).Append(",").Append(firstPoint.getLongitude().ToString());
            }

            item.latitudes           = latitudes.ToString();
            item.longitudes          = longitudes.ToString();
            item.locationSearchField = locationSearchField;

            JArray jsonArray = new JArray(NetmeraHttpUtils.locationSearch(item));

            return(convertJsonArrayToNetmeraContent(jsonArray));
        }
Exemplo n.º 13
0
 private void deactivateUser(RequestItem item, Action <Exception> callback)
 {
     if (String.IsNullOrEmpty(item.getEmail()))
     {
         if (callback != null)
         {
             callback(new NetmeraException(NetmeraException.ErrorCode.EC_REQUIRED_FIELD, NetmeraConstants.Netmera_UserEmail + " is required"));
         }
     }
     NetmeraHttpUtils.deactivateUser(item, ex =>
     {
         if (callback != null)
         {
             callback(new NetmeraException(NetmeraException.ErrorCode.EC_USER_LOGIN_ERROR, "Error occurred while deactivating user"));
         }
     });
 }
Exemplo n.º 14
0
 private void searchUser(RequestItem item, Action <List <NetmeraUser>, Exception> callback)
 {
     NetmeraHttpUtils.searchUser(item, (lno, ex) =>
     {
         if (ex != null)
         {
             if (callback != null)
             {
                 callback(null, ex);
             }
         }
         else if (lno != null)
         {
             try
             {
                 List <NetmeraUser> userList = convertJsonArrayToNetmeraUser(new JArray(lno));
                 if (callback != null)
                 {
                     callback(userList, null);
                 }
             }
             catch (JsonException e)
             {
                 if (callback != null)
                 {
                     callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of search method is invalid.", e.Message));
                 }
             }
             catch (IOException e)
             {
                 if (callback != null)
                 {
                     callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred in search method.", e.Message));
                 }
             }
             catch (Exception e)
             {
                 if (callback != null)
                 {
                     callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred in search method.", e.Message));
                 }
             }
         }
     });
 }
Exemplo n.º 15
0
        /// <summary>
        /// Deactivates the registered User.
        /// </summary>
        /// <param name="email">Email of the user</param>
        public void deactivateUser(String email)
        {
            try
            {
                RequestItem deactivateUserReqItem = new RequestItem();
                deactivateUserReqItem.setEmail(email);

                deactivateUser(deactivateUserReqItem);
            }
            catch (WebException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred while activating user");
            }
            catch (IOException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while activating user");
            }
        }
Exemplo n.º 16
0
        /// <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");
            }
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
        public static JObject get(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_GetContent_Url)
                                         .Append(NetmeraConstants.SecurityToken_Params).Append("=").Append(securityToken).Append("&")
                                         .Append(NetmeraConstants.Path_Params).Append("=").Append(item.path);

                return(sendHttp(strBuild.ToString(), NetmeraConstants.Http_Method_Get));
            }
            else
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_API_KEY_NOT_FOUND, "You didn't set your api key. Please use NetmeraClient.init(apiKey).");
            }
        }
Exemplo n.º 19
0
        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);
                        }
                    }
                }
            });
        }
Exemplo n.º 20
0
        /// <summary>
        /// Retrieves the list of <see cref="NetmeraUser"/> objects that matches with the
        /// query.
        /// </summary>
        /// <returns>The list of <see cref="NetmeraUser"/> object</returns>
        public List <NetmeraUser> searchUser()
        {
            RequestItem item      = new RequestItem();
            JArray      jsonArray = new JArray();

            if (searchText != null)
            {
                item.searchText = searchText;
            }

            item.path            = NetmeraConstants.Netmera_People_Url;
            item.max             = max;
            item.page            = page;
            item.sortBy          = sortBy;
            item.sortOrder       = sortOrder.ToString();
            item.customCondition = getUserCustomCondition();

            jsonArray = searchUser(item);

            return(convertJsonArrayToNetmeraUser(jsonArray));
        }
Exemplo n.º 21
0
        private List <NetmeraContent> searchFromNetwork()
        {
            RequestItem item = new RequestItem();

            item.path            = NetmeraConstants.Default_ParentPath;
            item.contentType     = NetmeraConstants.Default_ContentType;
            item.max             = max;
            item.page            = page;
            item.sortBy          = sortBy;
            item.sortOrder       = sortOrder.ToString();
            item.customCondition = getCustomCondition();

            if (searchText != null)
            {
                item.searchText = searchText;
            }

            JArray jsonArray = new JArray(NetmeraHttpUtils.search(item));

            return(convertJsonArrayToNetmeraContent(jsonArray));
        }
Exemplo n.º 22
0
        /// <summary>
        /// Finds the number of <seealso cref="NetmeraContent"/> objects that matches with the query.
        /// </summary>
        /// <returns>Content count</returns>
        public long count()
        {
            RequestItem item = new RequestItem();

            if (searchText != null)
            {
                item.searchText = searchText;
            }

            item.path            = NetmeraConstants.Default_ParentPath;
            item.contentType     = NetmeraConstants.Default_ContentType;
            item.max             = max;
            item.page            = page;
            item.sortBy          = sortBy;
            item.sortOrder       = sortOrder.ToString();
            item.customCondition = getCustomCondition();

            JArray jsonArray = new JArray(NetmeraHttpUtils.search(item));

            return(getNumberOfTotalResults(jsonArray));
        }
Exemplo n.º 23
0
        public static void activateUser(RequestItem item)
        {
            String securityToken = NetmeraClient.getSecurityToken();

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

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

                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).");
            }
        }
Exemplo n.º 24
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).");
            }
        }
Exemplo n.º 25
0
 private JArray searchUser(RequestItem item)
 {
     return(new JArray(NetmeraHttpUtils.searchUser(item)));
 }
Exemplo n.º 26
0
        /// <summary>
        /// Gets the <see cref="NetmeraContent"/> from the network, not the cache.
        /// </summary>
        /// <param name="path">Content path to get</param>
        /// <param name="callback">Method finding the content as the result of get operation and exception if exists.</param>
        public void getFromNetwork(String path, Action <NetmeraContent, Exception> callback)
        {
            RequestItem item = new RequestItem();

            if (path == null || path.Length == 0)
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_NULL_EXCEPTION, "Path cannot be null or empty"));
                }
            }

            item.path            = path;
            item.contentType     = NetmeraConstants.Default_ContentType;
            item.customCondition = getCustomCondition();

            NetmeraHttpUtils.get(item, (lno, ex) =>
            {
                if (ex != null)
                {
                    if (callback != null)
                    {
                        callback(null, ex);
                    }
                }
                else if (lno != null)
                {
                    try
                    {
                        List <NetmeraContent> contentList = convertJsonArrayToNetmeraContent(new JArray(lno));
                        if (callback != null)
                        {
                            if (contentList != null && contentList.Count != 0)
                            {
                                callback(contentList.ToArray()[0], null);
                            }
                        }
                    }
                    catch (JsonException e)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of search method is invalid.", e.Message));
                        }
                    }
                    catch (IOException e)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred in search method.", e.Message));
                        }
                    }
                    catch (Exception e)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred in search method.", e.Message));
                        }
                    }

                    NetmeraClient.finish();
                }
            });
        }
Exemplo n.º 27
0
        /// <summary>
        /// Logs a user into the registered application. Email and password fields of
        /// user is used for this operation.
        /// </summary>
        /// <param name="email">Email of the user</param>
        /// <param name="password">Password of the user</param>
        /// <param name="callback">Method called when user login operation finishes</param>
        public static void login(String email, String password, Action <NetmeraUser, Exception> callback)
        {
            clearSocialSessions((cleared, exception) =>
            {
                if (exception != null)
                {
                    if (callback != null)
                    {
                        callback(null, exception);
                    }
                }
                else if (cleared)
                {
                    NetmeraUser user = new NetmeraUser();
                    try
                    {
                        RequestItem loginUserReqItem = new RequestItem();
                        loginUserReqItem.setEmail(email);
                        loginUserReqItem.setPassword(password);

                        login(loginUserReqItem, (json, ex) =>
                        {
                            if (json == null || ex != null)
                            {
                                if (callback != null)
                                {
                                    callback(null, ex);
                                }
                            }
                            else
                            {
                                try
                                {
                                    user = setCurrentUser(json);
                                    if (callback != null)
                                    {
                                        callback(user, 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 in user login method"));
                        }
                    }
                    catch (IOException)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred in user login method"));
                        }
                    }
                    catch (JsonException)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of user login method is invalid"));
                        }
                    }
                }
                else
                {
                    if (callback != null)
                    {
                        callback(null, exception);
                    }
                }
            });
        }
Exemplo n.º 28
0
        /// <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"));
                }
            }
        }
Exemplo n.º 29
0
        /// <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"));
                }
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Searches the content by taking given location as a base and retrieves the contents that located given distance far away.
        /// </summary>
        /// <param name="startLocation">Base location to search near it.</param>
        /// <param name="distance">Distance used to create circle by taking the startLocation as a center.</param>
        /// <param name="locationSearchField">Name of the field that holds location data.</param>
        /// <param name="callback">Method called when circle search operation finishes</param>
        public void circleSearch(NetmeraGeoLocation startLocation, double distance, String locationSearchField, Action <List <NetmeraContent>, Exception> callback)
        {
            RequestItem item = new RequestItem();

            item.path            = NetmeraConstants.Default_ParentPath;
            item.contentType     = NetmeraConstants.Default_ContentType;
            item.max             = max;
            item.page            = page;
            item.sortBy          = sortBy;
            item.sortOrder       = sortOrder.ToString();
            item.customCondition = getCustomCondition();

            if (searchText != null)
            {
                item.searchText = searchText;
            }

            item.locationSearchType  = NetmeraConstants.LocationSearchType_Circle;
            item.distance            = distance;
            item.latitudes           = startLocation.getLatitude().ToString();
            item.longitudes          = startLocation.getLongitude().ToString();
            item.locationSearchField = locationSearchField;

            NetmeraHttpUtils.locationSearch(item, (lno, ex) =>
            {
                if (ex != null)
                {
                    if (callback != null)
                    {
                        callback(null, ex);
                    }
                }
                else if (lno != null)
                {
                    try
                    {
                        List <NetmeraContent> contentList = convertJsonArrayToNetmeraContent(new JArray(lno));
                        if (callback != null)
                        {
                            callback(contentList, null);
                        }
                    }
                    catch (JsonException e)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of search method is invalid.", e.Message));
                        }
                    }
                    catch (IOException e)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred in search method.", e.Message));
                        }
                    }
                    catch (Exception e)
                    {
                        if (callback != null)
                        {
                            callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred in search method.", e.Message));
                        }
                    }

                    NetmeraClient.finish();
                }
            });
        }