Exemplo n.º 1
0
 public async Task <bool> AddBookmarks(List <long> threadIdList)
 {
     foreach (long threadId in threadIdList)
     {
         await _webManager.PostData(
             Constants.BOOKMARK, string.Format(
                 Constants.ADD_BOOKMARK, threadId
                 ));
     }
     return(true);
 }
        public async Task <bool> GetTokenEmail(string email)
        {
            var uri    = new Uri(string.Format(EndPoints.CreateUserEmail, email));
            var result = await _webManager.PostData(uri, null, null);

            if (!result.IsSuccess)
            {
                throw new LoginFailedException("Failed to send token email");
            }
            return(result.IsSuccess);
        }
Exemplo n.º 3
0
        public async Task <UserFlag> FlagUser(int id, int flagid)
        {
            var uri    = new Uri(string.Format(EndPoints.FlagUser, id, flagid));
            var result = await _webManager.PostData(uri, null, null);

            if (!result.IsSuccess)
            {
                throw new Exception("Failed to set user flag: " + result.ResultJson);
            }
            return(JsonConvert.DeserializeObject <UserFlag>(result.ResultJson));
        }
        public async Task <Result> SendFriendRequest(string username, string requestMessage, string currentUserOnlineId, UserAuthenticationEntity userAuthenticationEntity, string region = "jp")
        {
            var param = new Dictionary <String, String>();

            if (!string.IsNullOrEmpty(requestMessage))
            {
                param.Add("requestMessage", requestMessage);
            }
            var jsonObject    = JsonConvert.SerializeObject(param);
            var stringContent = new StringContent(jsonObject, Encoding.UTF8, "application/json");
            var url           = string.Format(EndPoints.SendFriendRequest, region, currentUserOnlineId, username, requestMessage);

            return(await _webManager.PostData(new Uri(url), stringContent, userAuthenticationEntity));
        }
Exemplo n.º 5
0
        private async Task <bool> SendLoginData(string username, string password)
        {
            CookieContainer cookies = await _webManager.PostData(
                Constants.LOGIN_URL, string.Format(
                    "action=login&username={0}&password={1}",
                    username.Replace(" ", "+"),
                    WebUtility.UrlEncode(password)));

            if (cookies.Count < 2)
            {
                return(false);
            }

            var fixedCookieContainer = new CookieContainer();

            // TODO: HUGE HACK. For some reason Windows Phone does not use the Domain Key on a cookie, but only the domain when making requests.
            // Windows 8 won't break on it, but Windows Phone will, since the Domain Key and Domain are different on SA.
            // We need to move this code to a more common place.

            foreach (Cookie cookie in cookies.GetCookies(new Uri(Constants.COOKIE_DOMAIN_URL)))
            {
                var fixedCookie = new Cookie(cookie.Name, cookie.Value, "/", ".somethingawful.com");
                fixedCookieContainer.Add(new Uri(Constants.COOKIE_DOMAIN_URL), fixedCookie);
            }

            await _localStorageManager.SaveCookie(Constants.COOKIE_FILE, cookies, new Uri(Constants.COOKIE_DOMAIN_URL));

            return(true);
        }
Exemplo n.º 6
0
        public async Task <bool> SendPushNotification(string toDeviceId, string fromUserId, string fromUserName, string message, string iconUrl)
        {
            var uri    = new Uri(string.Format(EndPoints.PushMessage, toDeviceId, fromUserId, fromUserName, message, iconUrl));
            var result = await _webManager.PostData(uri, null, null);

            if (!result.IsSuccess)
            {
                throw new Exception("Failed to send push message");
            }
            return(result.IsSuccess);
        }
        public async Task <Result> CreateStickerPost(string messageUserId, string manifestFileUrl, string number,
                                                     string imageUrl, string packageId, string type, UserAuthenticationEntity userAuthenticationEntity,
                                                     string region = "jp")
        {
            var          url         = string.Format(EndPoints.CreatePost, region, messageUserId);
            const string boundary    = "gc0p4Jq0M2Yt08jU534c0p";
            var          messageJson = new SendMessage
            {
                message = new Message()
                {
                    body           = string.Empty,
                    fakeMessageUid = 1234,
                    messageKind    = 1013,
                    stickerDetail  = new StickerDetail()
                    {
                        imageUrl        = imageUrl,
                        manifestFileUrl = manifestFileUrl,
                        number          = number,
                        packageId       = packageId,
                        type            = type
                    }
                }
            };

            var json          = JsonConvert.SerializeObject(messageJson);
            var stringContent = new StringContent(json, Encoding.UTF8, "application/json");

            stringContent.Headers.Add("Content-Description", "message");
            var form = new MultipartContent("mixed", boundary)
            {
                stringContent
            };

            return(await _webManager.PostData(new Uri(url), form, userAuthenticationEntity));
        }
Exemplo n.º 8
0
        public async Task <bool> SendFriendRequest(string username, string requestMessage,
                                                   UserAccountEntity userAccountEntity)
        {
            try
            {
                var user  = userAccountEntity.GetUserEntity();
                var param = new Dictionary <String, String>();
                if (!string.IsNullOrEmpty(requestMessage))
                {
                    param.Add("requestMessage", requestMessage);
                }
                var jsonObject    = JsonConvert.SerializeObject(param);
                var stringContent = new StringContent(jsonObject, Encoding.UTF8, "application/json");
                var url           = string.Format(EndPoints.SendFriendRequest, user.Region, user.OnlineId, username, requestMessage);
                var result        = await _webManager.PostData(new Uri(url), null, stringContent, userAccountEntity);

                return(result.IsSuccess);
            }
            catch (Exception ex)
            {
                throw new Exception("Error sending friend request", ex);
            }
        }
Exemplo n.º 9
0
        public async Task <UserLoginSession> LoginUserThroughV1ApiAsync(string email, string password)
        {
            var body   = new StringContent(string.Format(Constants.LoginForm, email, password), Encoding.UTF8, "application/x-www-form-urlencoded");
            var result = await _webManager.PostData(new Uri(EndPoints.VitaLogin), null, body);

            if (!result.IsSuccess)
            {
                throw new Exception("Failed to Login: "******"Failed to Login: "******"Failed to Login: " + result.ResultXml, ex);
            }
        }
Exemplo n.º 10
0
        public async Task <bool> ClearNotification(NotificationEntity.Notification notification,
                                                   UserAccountEntity userAccountEntity)
        {
            try
            {
                var user   = userAccountEntity.GetUserEntity();
                var url    = string.Format(EndPoints.ClearNotification, user.Region, user.OnlineId, notification.NotificationGroup, notification.NotificationId);
                var json   = new StringContent("{\"seenFlag\":true}", Encoding.UTF8, "application/json");
                var result = await _webManager.PostData(new Uri(url), null, json, userAccountEntity);

                return(result.IsSuccess);
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to clear notification", ex);
            }
        }
Exemplo n.º 11
0
        public async Task <FlagResponse> FlagByteAsync(string postId, string reason = "")
        {
            var result = await _webManager.PostData(new Uri(string.Format(Endpoints.AddRemoveFlag, postId)), null, null);

            return(JsonConvert.DeserializeObject <FlagResponse>(result.ResultJson));
        }
Exemplo n.º 12
0
        public async Task <StarResponse> StarByteAsync(string postId)
        {
            var result = await _webManager.PostData(new Uri(string.Format(Endpoints.AddRemoveStar, postId)), null, null);

            return(JsonConvert.DeserializeObject <StarResponse>(result.ResultJson));
        }
Exemplo n.º 13
0
        public async Task <CommentResponse> MakeCommentAsync(string postId, NewComment comment)
        {
            var result = await _webManager.PostData(new Uri(string.Format(Endpoints.PostComment, postId)), null, new StringContent(JsonConvert.SerializeObject(comment)));

            return(JsonConvert.DeserializeObject <CommentResponse>(result.ResultJson));
        }