Esempio n. 1
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).");
            }
        }
Esempio n. 2
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).");
            }
        }
Esempio n. 3
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).");
            }
        }
Esempio n. 4
0
        public static JObject updateContent(JObject paramsObject, String path)
        {
            //the same as in the createContent method
            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_UpdateContent_Url)
                                         .Append(NetmeraConstants.SecurityToken_Params).Append("=").Append(securityToken).Append("&")
                                         .Append(NetmeraConstants.ContentType_Params).Append("=").Append(NetmeraConstants.Default_ContentType).Append("&")
                                         .Append(NetmeraConstants.Path_Params).Append("=").Append(path).Append("&")
                                         .Append(NetmeraConstants.ContentPrivacy_Params).Append("=").Append(paramsObject[NetmeraConstants.ContentPrivacy_Params]).Append("&")
                                         .Append(NetmeraConstants.Service_Params).Append("=").Append(NetmeraConstants.Default_Service).Append("&")
                                         .Append(NetmeraConstants.Action_Params).Append("=").Append(NetmeraConstants.Update_Action).Append("&")
                                         .Append(NetmeraConstants.Content_Params).Append("=").Append(JsonConvert.SerializeObject(paramsObject));

                JObject responseHttp = sendHttp(strBuild.ToString(), NetmeraConstants.Http_Method_Post);
                return((JObject)responseHttp[NetmeraConstants.Entry_Params]);
            }
            else
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_API_KEY_NOT_FOUND, "You didn't set your api key. Please use NetmeraClient.init(apiKey).");
            }
        }
Esempio n. 5
0
        public static JObject createBulkContent(JObject paramsObject)
        {
            //security token is stored in a temporary variable because createActionToken resets the security token
            //inside NetmeraClien due to the method sendHttp which contains NetmeraClient.finish();
            String securityToken = NetmeraClient.getSecurityToken();

            if (securityToken != null && securityToken.Trim() != "")
            {
                long contentNameRnd = currentTimeMillis();

                StringBuilder strBuild = new StringBuilder()
                                         .Append(NetmeraConstants.Netmera_Domain_Url)
                                         .Append(NetmeraConstants.Netmera_Domain_Rpc_Url)
                                         //.Append(NetmeraConstants.Netmera_CreateBulkContent_Url)
                                         .Append(NetmeraConstants.SecurityToken_Params).Append("=").Append(securityToken);
                //.Append("&")
                //.Append(NetmeraConstants.ContentType_Params).Append("=").Append(NetmeraConstants.Default_ContentType).Append("&")
                //.Append(NetmeraConstants.ContentName_Params).Append("=").Append(contentNameRnd).Append("&")
                //.Append(NetmeraConstants.ContentPrivacy_Params).Append("=").Append(paramsObject[NetmeraConstants.ContentPrivacy_Params]).Append("&")
                //.Append(NetmeraConstants.Path_Params).Append("=").Append(NetmeraConstants.Default_ParentPath).Append("&")
                //.Append(NetmeraConstants.Service_Params).Append("=").Append(NetmeraConstants.Default_Service).Append("&")
                //.Append(NetmeraConstants.Action_Params).Append("=").Append(NetmeraConstants.Create_Action).Append("&")
                //.Append(NetmeraConstants.Content_Params);
                //.Append("=").Append(JsonConvert.SerializeObject(paramsObject));
                String strBody = JsonConvert.SerializeObject(paramsObject);

                JObject responseHttp = sendHttpWithJson(strBuild.ToString(), strBody, NetmeraConstants.Http_Method_Post);
                return(responseHttp);
            }
            else
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_API_KEY_NOT_FOUND, "You didn't set your api key. Please use NetmeraClient.init(apiKey).");
            }
        }
Esempio n. 6
0
        private JObject createMedia(NetmeraContent content)
        {
            JObject json = null;

            try
            {
                JObject mediaObject      = new JObject();
                bool    isMediaFileAdded = false;

                IEnumerable <JProperty> jlist = mediaData.Properties();

                foreach (JProperty token in jlist)
                {
                    String key = token.Name;
                    String tmpMediaDataJson = mediaData.Value <String>(key);

                    byte[] tmpMediaData = JsonConvert.DeserializeObject <byte[]>(tmpMediaDataJson);

                    NetmeraMedia file = new NetmeraMedia(tmpMediaData);

                    isMediaFileAdded = true;

                    String appId       = content.getContent().Value <string>(NetmeraConstants.Site);
                    String apiKey      = NetmeraClient.getSecurityToken();
                    String contentPath = content.getPath();
                    String viewerId    = content.getOwner().Value <String>(NetmeraConstants.Netmera_Owner_Node_Name);
                    String mediaUrl    = file.save(appId, apiKey, contentPath, viewerId);

                    mediaObject.Add(key, mediaUrl);
                }
                if (isMediaFileAdded)
                {
                    json = NetmeraHttpUtils.updateContent(mediaObject, content.getPath());
                }
            }
            catch (JsonException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_JSON, "Json in the response of creating media file is invalid");
            }
            catch (WebException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_INVALID_REQUEST, "Request exception occurred while saving media data");
            }
            catch (IOException)
            {
                throw new NetmeraException(NetmeraException.ErrorCode.EC_IO_EXCEPTION, "IO Exception occurred while saving media data");
            }
            return(json);
        }
Esempio n. 7
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).");
            }
        }
Esempio n. 8
0
        public static JObject loginAsGuest()
        {
            String securityToken = NetmeraClient.getSecurityToken();

            if (securityToken != null && securityToken.Trim() != "")
            {
                StringBuilder strBuildForJson = new StringBuilder()
                                                .Append("{\"" + NetmeraConstants.Params_Params + "\":{")
                                                .Append(" },\"" + NetmeraConstants.Method_Params + "\":\"" + NetmeraConstants.Netmera_LoginGuestUser_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).");
            }
        }
Esempio n. 9
0
        public static bool deleteContent(String path)
        {
            bool   flag          = false;
            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_RemoveContent_Url)
                                         .Append(NetmeraConstants.SecurityToken_Params).Append("=").Append(securityToken).Append("&")
                                         .Append(NetmeraConstants.Path_Params).Append("=").Append(path);

                flag = sendHttpwithReturn(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).");
            }
            return(flag);
        }
Esempio n. 10
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).");
            }
        }
Esempio n. 11
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).");
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Login with Twitter account
        /// </summary>
        /// <param name="callback">Method to be called when login operation finishes</param>
        public static void login(Action <NetmeraUser, Exception> callback)
        {
            String securityToken = NetmeraClient.getSecurityToken();

            if (securityToken != null && securityToken.Trim() != "")
            {
                Popup            popup   = new Popup();
                LoginUserControl control = new LoginUserControl();
                control.webBrowser.Source = null;
                control.btnCancel.Click  += new RoutedEventHandler((s, e) =>
                {
                    if (callback != null)
                    {
                        callback(null, null);
                    }
                });
                try
                {
                    NetmeraUser.clearSocialSessions((logout, ex) =>
                    {
                        if (logout && ex == null)
                        {
                            control.webBrowser.Loaded += new RoutedEventHandler((s, e) =>
                            {
                                twitter.getTwitterLoginUri((loginUri, ex1) =>
                                {
                                    if (loginUri != null && ex1 == null)
                                    {
                                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                                        {
                                            control.webBrowser.Navigate(loginUri);
                                        });
                                    }
                                    else
                                    {
                                        if (callback != null)
                                        {
                                            callback(null, ex1);
                                        }
                                    }
                                });
                            });

                            control.webBrowser.LoadCompleted += new LoadCompletedEventHandler((s, e) =>
                            {
                                if (e.Uri.AbsoluteUri == Twitter.AuthorizeUrl)
                                {
                                    String pinHtml = control.webBrowser.SaveToString();

                                    twitter.getTwitterPin(pinHtml, (pin, ex1) =>
                                    {
                                        if (!String.IsNullOrEmpty(pin))
                                        {
                                            twitter.getTwitterAccessToken(e.Uri, (accessToken, ex2) =>
                                            {
                                                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                {
                                                    popup.IsOpen = false;
                                                    if (ex2 != null)
                                                    {
                                                        if (callback != null)
                                                        {
                                                            callback(null, ex2);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (!String.IsNullOrEmpty(accessToken))
                                                        {
                                                            getTwitterUser((user, exc) =>
                                                            {
                                                                if (user != null && exc == null)
                                                                {
                                                                    TwitterSession.save(twitter);
                                                                }
                                                                callback(user, exc);
                                                            });
                                                        }
                                                        else
                                                        {
                                                            login(callback);
                                                        }
                                                    }
                                                });
                                            });
                                        }
                                    });
                                }
                            });
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                popup.Child  = control;
                                popup.IsOpen = true;
                            });
                        }
                        else
                        {
                            if (callback != null)
                            {
                                callback(null, ex);
                            }
                        }
                    });
                }
                catch (Exception e)
                {
                    if (callback != null)
                    {
                        callback(null, e);
                    }
                }
            }
            else
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_API_KEY_NOT_FOUND, "You didn't set your api key. Please use NetmeraClient.init(apiKey)."));
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Logs a user into the registered application with Facebook account with Facebook permissions.
        /// </summary>
        /// <param name="permissionArray">Permission array</param>
        /// <param name="callback">Method to be called when login operation finishes</param>
        public static void login(String[] permissionArray, Action <NetmeraUser, Exception> callback)
        {
            String securityToken = NetmeraClient.getSecurityToken();

            if (securityToken != null && securityToken.Trim() != "")
            {
                Popup            popup   = new Popup();
                LoginUserControl control = new LoginUserControl();
                control.btnCancel.Click += new RoutedEventHandler((s, e) =>
                {
                    NetmeraUser user = null;
                    user             = NetmeraUser.getCurrentUser();
                    if (callback != null)
                    {
                        callback(user, null);
                    }
                });
                try
                {
                    NetmeraUser.clearSocialSessions((logout, ex) =>
                    {
                        if (logout && ex == null)
                        {
                            control.webBrowser.Loaded += new RoutedEventHandler((s, e) =>
                            {
                                facebook.getFacebookLoginUri(permissionArray, (loginUri, ex1) =>
                                {
                                    if (loginUri != null && ex1 == null)
                                    {
                                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                                        {
                                            control.webBrowser.Navigate(loginUri);
                                        });
                                    }
                                    else
                                    {
                                        if (callback != null)
                                        {
                                            callback(null, ex1);
                                        }
                                    }
                                });
                            });

                            control.webBrowser.LoadCompleted += new LoadCompletedEventHandler((s, e) =>
                            {
                                String ss = control.webBrowser.SaveToString();
                                facebook.getFacebookAccessToken(e.Uri, (accessToken, ex2) =>
                                {
                                    if (!String.IsNullOrEmpty(accessToken))
                                    {
                                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                                        {
                                            popup.IsOpen = false;
                                            getFacebookUser((user, ex3) =>
                                            {
                                                if (user != null && ex3 == null)
                                                {
                                                    FacebookSession.save(facebook);
                                                }
                                                callback(user, ex3);
                                            });
                                        });
                                    }
                                    else if (ex2 != null)
                                    {
                                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                                        {
                                            popup.IsOpen = false;
                                            if (callback != null)
                                            {
                                                callback(null, ex2);
                                            }
                                        });
                                    }
                                });
                            });
                            Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                popup.Child  = control;
                                popup.IsOpen = true;
                            });
                        }
                        else
                        {
                            if (callback != null)
                            {
                                callback(null, ex);
                            }
                        }
                    });
                }
                catch (Exception)
                {
                    if (callback != null)
                    {
                        callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_FB_ERROR, "Error occured while logging in facebook."));
                    }
                }
            }
            else
            {
                if (callback != null)
                {
                    callback(null, new NetmeraException(NetmeraException.ErrorCode.EC_API_KEY_NOT_FOUND, "You didn't set your api key. Please use NetmeraClient.init(apiKey)."));
                }
            }
        }