/// <summary>
        /// Updates friend list of authenticated user.
        /// </summary>
        /// <remarks> Swagger method name:<c>Update Friends</c>.</remarks>
        /// <see cref="https://developers.xsolla.com/user-account-api/user-friends/postusersmerelationships"/>.
        /// <param name="token">JWT from Xsolla Login.</param>
        /// <param name="action">Type of the action.</param>
        /// <param name="user">The Xsolla Login user ID to change relationship with.</param>
        /// <param name="onSuccess">Successful operation callback.</param>
        /// <param name="onError">Failed operation callback.</param>
        public void UpdateUserFriends(string token, FriendAction action, string user, Action onSuccess, Action <Error> onError)
        {
            var request = new UserFriendUpdate
            {
                action = action.GetParameter(),
                user   = user
            };

            WebRequestHelper.Instance.PostRequest(SdkType.Login, URL_USER_UPDATE_FRIENDS, request, WebRequestHeader.AuthHeader(token), onSuccess, onError);
        }
예제 #2
0
        public static bool ManageFriend(FriendAction action, string zuneTag)
        {
            bool   flag       = !string.IsNullOrEmpty(zuneTag);
            string strPostUrl = null;

            if (flag)
            {
                strPostUrl = CreateOperationUri("friends");
                flag       = strPostUrl != null;
            }
            if (flag)
            {
                flag = MessagingService.Instance.ManageFriend(action, strPostUrl, zuneTag);
            }
            return(flag);
        }
예제 #3
0
        public static string GetParameter(this FriendAction provider)
        {
            switch (provider)
            {
            case FriendAction.SendInviteRequest: return("friend_request_add");

            case FriendAction.CancelRequest: return("friend_request_cancel");

            case FriendAction.AcceptInvite: return("friend_request_approve");

            case FriendAction.DenyInvite: return("friend_request_deny");

            case FriendAction.RemoveFriend: return("friend_remove");

            case FriendAction.BlockFriend: return("block");

            case FriendAction.UnblockFriend: return("unblock");

            default: return(string.Empty);
            }
        }
예제 #4
0
        /// <summary>
        /// </summary>
        /// <param name="action"></param>
        /// <param name="username"></param>
        /// <param name="authToken"></param>
        /// <param name="friend"></param>
        /// <param name="postDataEntries"></param>
        public static async Task <FriendAction> Friend(string friend, string action, string username, string authToken,
                                                       Dictionary <string, string> postDataEntries = null)
        {
            long timestamp = Timestamps.GenerateRetardedTimestamp();
            var  postData  = new Dictionary <string, string>
            {
                { "friend", friend },
                { "action", action },
                { "username", username },
                { "timestamp", timestamp.ToString(CultureInfo.InvariantCulture) }
            };

            if (postDataEntries != null)
            {
                foreach (var postDataEntry in postDataEntries)
                {
                    postData.Add(postDataEntry.Key, postDataEntry.Value);
                }
            }

            HttpResponseMessage response =
                await WebRequests.Post("friend", postData, authToken, timestamp.ToString(CultureInfo.InvariantCulture));

            switch (response.StatusCode)
            {
            case HttpStatusCode.OK:
            {
                string data = await response.Content.ReadAsStringAsync();

                FriendAction parsedData = await JsonConvert.DeserializeObjectAsync <FriendAction>(data);

                // Yup, save the data and return true
                return(parsedData);
            }

            default:
                // Well, f**k
                return(null);
            }
        }
예제 #5
0
        private async void ButtonDelete_Click(object sender, EventArgs e)
        {
            StartPendingState(string.Format("Deleting {0} from your snapchat...", _friend.Name));

            string username  = App.IsolatedStorage.UserAccount.UserName;
            string authToken = App.IsolatedStorage.UserAccount.AuthToken;

            FriendAction response = await Functions.Friend(_friend.Name, "delete", username, authToken);

            if (response == null)
            {
                // TODO: tell user shit failed
            }
            else if (!response.Logged)
            {
                // Logged Out
                // TODO: Sign Out
            }
            else
            {
                // le worked
                try
                {
                    App.IsolatedStorage.UserAccount.Friends.Remove(
                        App.IsolatedStorage.UserAccount.Friends.Find(f => f.Name == _friend.Name));

                    MessageBox.Show(string.Format("The user {0} has been deleted from your friends list. :(", _friend.Name),
                                    string.Format("{0} Deleted", _friend.Name),
                                    MessageBoxButton.OK);

                    NavigationService.GoBack();
                }
                catch (Exception ex)
                {
                    // TODO: tell user something bad happened
                }
            }

            EndPendingStage();
        }
예제 #6
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="friendUsername"></param>
		/// <param name="action"></param>
		/// <returns></returns>
		public Response SendFriendAction(string friendUsername, FriendAction action)
		{
			return SendFriendActionAsync(friendUsername, action).Result;
		}
예제 #7
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="friendUsername"></param>
		/// <param name="action"></param>
		/// <returns></returns>
		public async Task<Response> SendFriendActionAsync(string friendUsername, FriendAction action)
		{
			var timestamp = Timestamps.GenerateRetardedTimestamp();
			var postData = new Dictionary<string, string>
			{
				{"username", GetAuthedUsername()},
				{"timestamp", timestamp.ToString(CultureInfo.InvariantCulture)},
				{"action", action.ToString().ToLower()},
				{"friend", friendUsername},
			};

			var response =
				await
					_webConnect.PostToGenericAsync<Response>(FriendEndpointUrl, postData, _snapchatManager.AuthToken,
						timestamp.ToString(CultureInfo.InvariantCulture));

			return response;
		}
예제 #8
0
        private void ButtonAddFriend_Click(object sender, EventArgs e)
        {
            string username  = App.IsolatedStorage.UserAccount.UserName;
            string authToken = App.IsolatedStorage.UserAccount.AuthToken;

            var messageBox = new CustomMessageBox
            {
                Caption = "Add a Friend",
                Message = "Enter the Snapchat Username of the friend you want to add.",
                Content = new PhoneTextBox {
                    Text = "", Hint = "Snapchat Username", Margin = new Thickness(0, 10, 20, 0)
                },
                LeftButtonContent  = "cancel",
                RightButtonContent = "done",
                IsFullScreen       = false
            };

            messageBox.Dismissed += async(s1, e1) =>
            {
                switch (e1.Result)
                {
                case CustomMessageBoxResult.RightButton:
                    // rename
                    var mb = ((CustomMessageBox)s1);
                    if (mb == null)
                    {
                        return;
                    }

                    var textbox = ((PhoneTextBox)mb.Content);
                    if (textbox == null)
                    {
                        return;
                    }
                    SetProgress("Sending Snapchat Friend Request...", true);
                    FriendAction response = await Functions.Friend(textbox.Text, "add", username, authToken);

                    HideProgress(true);

                    Dispatcher.BeginInvoke(delegate
                    {
                        if (response == null)
                        {
                            // TODO: tell user shit failed
                        }
                        else if (!response.Logged)
                        {
                            // Logged Out
                            // TODO: Sign Out
                        }
                        else if (response.Object != null)
                        {
                            // le worked
                            try
                            {
                                App.IsolatedStorage.UserAccount.Friends.Add(response.Object);
                                RefreshBindings();

                                MessageBox.Show("", "Success", MessageBoxButton.OK);
                            }
                            catch (Exception ex)
                            {
                                // TODO: tell user something bad happened
                            }
                        }

                        // TODO: tell user shit failed
                    });
                    break;

                case CustomMessageBoxResult.LeftButton:
                case CustomMessageBoxResult.None:
                default:
                    break;
                }
            };
            messageBox.Show();
        }
예제 #9
0
        private void ButtonAcceptFriend_Click(object sender, RoutedEventArgs e)
        {
            // Accept the friend request
            var button = ((Button)sender);

            if (button == null)
            {
                return;
            }

            object tag = button.Tag;

            if (tag == null)
            {
                return;
            }

            string friend = (button.Tag is Snap)
                                ? (button.Tag as Snap).ScreenName
                                : null;

            if (friend == null)
            {
                return;
            }

            var messageBox = new CustomMessageBox
            {
                Title              = string.Format("Are you sure you want to add {0}?", friend),
                Message            = "You shall be able to send and recieve snapchats from/to each other.",
                LeftButtonContent  = "Yes",
                RightButtonContent = "No"
            };

            messageBox.Dismissed += async(s1, e1) =>
            {
                switch (e1.Result)
                {
                case CustomMessageBoxResult.LeftButton:
                    string username  = App.IsolatedStorage.UserAccount.UserName;
                    string authToken = App.IsolatedStorage.UserAccount.AuthToken;

                    // Add User
                    SetProgress("Syncing with Snapchat securely...", true);
                    FriendAction response = await Functions.Friend(friend, "add", username, authToken);

                    HideProgress(true);

                    if (response == null)
                    {
                        MessageBox.Show("Uh Oh", "Unable to connect to the Snapchat Servers. Check your connection and try again.",
                                        MessageBoxButton.OK);
                    }
                    else if (!response.Logged)
                    {
                        // TODO: Logout
                    }
                    else if (response.Object != null)
                    {
                        // Add user to friends
                        App.IsolatedStorage.UserAccount.Friends.Add(response.Object);

                        RefreshBindings();

                        MessageBox.Show("Successfull", string.Format("You have added {0} as a friend on snapchat!", friend),
                                        MessageBoxButton.OK);
                    }
                    else
                    {
                        MessageBox.Show("Uh Oh", string.Format("There was an error adding {0} as a friend on snapchat.", friend),
                                        MessageBoxButton.OK);
                    }
                    break;

                case CustomMessageBoxResult.RightButton:
                case CustomMessageBoxResult.None:
                default:
                    break;
                }
            };
            messageBox.Show();
        }
예제 #10
0
        private void ButtonRename_Click(object sender, EventArgs e)
        {
            StartPendingState("Creating a Display Name for user...");

            string username  = App.IsolatedStorage.UserAccount.UserName;
            string authToken = App.IsolatedStorage.UserAccount.AuthToken;

            var messageBox = new CustomMessageBox
            {
                Caption = string.Format("Do you want to add a display name for {0}", _friend.Name),
                Message =
                    "This display name will appear under their name on the friends list. and is just for you, nobody else will see it.",
                Content =
                    new PhoneTextBox
                {
                    Text   = _friend.Display,
                    Hint   = string.Format("Pick a Custom Name for {0}", _friend.Name),
                    Margin = new Thickness(0, 10, 20, 0)
                },
                LeftButtonContent  = "cancel",
                RightButtonContent = "done",
                IsFullScreen       = false
            };

            messageBox.Dismissed += async(s1, e1) =>
            {
                switch (e1.Result)
                {
                case CustomMessageBoxResult.RightButton:
                    // rename
                    var mb = ((CustomMessageBox)s1);
                    if (mb == null)
                    {
                        return;
                    }

                    var textbox = ((PhoneTextBox)mb.Content);
                    if (textbox == null)
                    {
                        return;
                    }

                    FriendAction response =
                        await
                        Functions.Friend(_friend.Name, "display", username, authToken,
                                         new Dictionary <string, string> {
                        { "display", textbox.Text }
                    });

                    Dispatcher.BeginInvoke(delegate
                    {
                        if (response == null)
                        {
                            // TODO: tell user shit failed
                        }
                        else if (!response.Logged)
                        {
                            // Logged Out
                            // TODO: Sign Out
                        }
                        else if (response.Object != null)
                        {
                            // le worked
                            try
                            {
                                _friend = response.Object;
                                App.IsolatedStorage.UserAccount.Friends.Find(f => f.Name == _friend.Name).Display = response.Object.Display;
                            }
                            catch (Exception ex)
                            {
                                // TODO: tell user something bad happened
                            }
                        }

                        // TODO: tell user shit failed
                    });
                    break;

                case CustomMessageBoxResult.LeftButton:
                case CustomMessageBoxResult.None:
                default:
                    break;
                }
                Dispatcher.BeginInvoke(EndPendingStage);
            };

            messageBox.Show();
        }