public async Task<Result> GetTrophyDetailList(string gameId, string comparedUser, bool includeHidden,
     UserAuthenticationEntity userAuthenticationEntity, string fromUser, string region = "jp", string language = "ja")
 {
     var url = string.Format(EndPoints.TrophyDetailList, region, gameId, language, comparedUser, fromUser);
     url += "&r=" + Guid.NewGuid();
     return await _webManager.GetData(new Uri(url), userAuthenticationEntity, language);
 }
        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);
        }
 public async Task<Result> GetUstreamFeed(int pageNumber, int pageSize, string detailLevel,
     Dictionary<string, string> filterList, string sortBy, string query, UserAuthenticationEntity userAuthenticationEntity)
 {
     var url = EndPoints.UstreamBaseUrl;
     url += $"p={pageNumber}&";
     url += $"pagesize={pageSize}&";
     url += $"detail_level={detailLevel}&";
     foreach (var item in filterList)
     {
         if (item.Key.Equals(EndPoints.UstreamUrlConstants.Interactive))
         {
             url += string.Format(EndPoints.UstreamUrlConstants.FilterBase, EndPoints.UstreamUrlConstants.PlatformPs4) +
                              "[interactive]=" + item.Value + "&";
         }
         else
         {
             url += string.Concat(string.Format(EndPoints.UstreamUrlConstants.FilterBase, item.Key), "=", item.Value + "&");
         }
     }
     url += $"sort={sortBy}";
     if (!string.IsNullOrEmpty(query))
     {
         url += $"&q={query}";
     }
     url += "&r=" + Guid.NewGuid();
     return await _webManager.GetData(new Uri(url), userAuthenticationEntity);
 }
 public async  Task<Result> PostData(Uri uri, StringContent content, UserAuthenticationEntity userAuthenticationEntity, string language = "ja")
 {
     using (var httpClient = new HttpClient())
     {
         try
         {
             var authenticationManager = new AuthenticationManager();
             Result result = new Result(false, "");
             if (RefreshTime(userAuthenticationEntity.ExpiresInDate))
             {
                 var tokens = await authenticationManager.RefreshAccessToken(userAuthenticationEntity.RefreshToken);
                 result.Tokens = tokens.Tokens;
             }
             httpClient.DefaultRequestHeaders.Add("Accept-Language", language);
             httpClient.DefaultRequestHeaders.Add("Origin", "http://psapp.dl.playstation.net");
             httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userAuthenticationEntity.AccessToken);
             var response = await httpClient.PostAsync(uri, content);
             var responseContent = await response.Content.ReadAsStringAsync();
             result.IsSuccess = response.IsSuccessStatusCode;
             result.ResultJson = responseContent;
             return result;
         }
         catch (Exception)
         {
             return new Result(false, string.Empty);
         }
     }
 }
 public async Task<Result> DeleteMessageThread(string messageGroupId, string onlineId,
    UserAuthenticationEntity userAuthenticationEntity, string region = "jp")
 {
     var url = string.Format(EndPoints.DeleteThread, region, messageGroupId, onlineId);
     url += "&r=" + Guid.NewGuid();
     return await _webManager.DeleteData(new Uri(url), null, userAuthenticationEntity);
 }
 public async Task<Result> GetTrophyList(string comparedUser, string fromUser, int offset, UserAuthenticationEntity userAuthenticationEntity,
     string region = "jp", string language = "ja")
 {
     var url = string.Format(EndPoints.TrophyList, region, language, offset, comparedUser, fromUser);
     url += "&r=" + Guid.NewGuid();
     return await _webManager.GetData(new Uri(url), userAuthenticationEntity, language);
 }
        public async Task<Result> GetTwitchFeed(int offset, int limit, string platform,
            bool titlePreset, string query, UserAuthenticationEntity userAuthenticationEntity, string language = "ja")
        {
            var url = EndPoints.TwitchBaseUrl;
            // Sony's app hardcodes this value to 0. 
            // This app could, in theory, allow for more polling of data, so these options are left open to new values and limits.
            url += $"sce_platform=PS4&offset={offset}&";
            url += $"limit={limit}&";
            if (!string.IsNullOrEmpty(query))
            {
                url += $"q={query}&";
            }
            if (titlePreset)
            {
                url += "sce_title_preset=true";
            }

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.twitchtv.v1+json"));
                httpClient.DefaultRequestHeaders.Add("Platform", "54bd6377db3b48cba9ecc44bff5a410b");
                httpClient.DefaultRequestHeaders.Add("Accept-Language", language);

                var response = await httpClient.GetAsync(new Uri(url));
                var responseContent = await response.Content.ReadAsStringAsync();
                return new Result(response.IsSuccessStatusCode, responseContent);
            }
        }
 public async Task<Result> GetGroupConversation(string messageGroupId,
     UserAuthenticationEntity userAuthenticationEntity, string region = "jp", string language = "ja")
 {
     var url = string.Format(EndPoints.MessageGroup2, region, messageGroupId, language);
     url += "&r=" + Guid.NewGuid();
     return await _webManager.GetData(new Uri(url), userAuthenticationEntity, language);
 }
 public async Task<Result> SendNameRequest(string username, string currentUserOnlineId, UserAuthenticationEntity userAuthenticationEntity, string region = "jp")
 {
     var param = new Dictionary<String, String>();
     var jsonObject = JsonConvert.SerializeObject(param);
     var stringContent = new StringContent(jsonObject, Encoding.UTF8, "application/json");
     var url = string.Format(EndPoints.SendNameRequest, region, currentUserOnlineId, username);
     return await _webManager.PostData(new Uri(url), stringContent, userAuthenticationEntity);
 }
 public async Task<Result> GetActivityFeed(string userName, int? pageNumber, bool storePromo,
     bool isNews, UserAuthenticationEntity userAuthenticationEntity, string region = "jp", string language = "ja")
 {
     var feedNews = isNews ? "news" : "feed";
     var url = string.Format(EndPoints.RecentActivity, userName, feedNews, pageNumber);
     if (storePromo)
         url += "&filters=STORE_PROMO";
     url += "&r=" + Guid.NewGuid();
     return await _webManager.GetData(new Uri(url), userAuthenticationEntity, language);
 }
 public async Task<Result> GetUserAvatar(string userName, UserAuthenticationEntity userAuthenticationEntity,
     string region = "jp", string language = "ja")
 {
     try
     {
         var url = string.Format(EndPoints.UserAvatars, region, userName);
         return await _webManager.GetData(new Uri(url), userAuthenticationEntity, language);
     }
     catch (Exception exception)
     {
         throw new Exception("Error getting user avatars", exception);
     }
 }
 public async Task<Result> GetFriendsList(string username, int? offset, bool blockedPlayer,
     bool playedRecently, bool personalDetailSharing, bool friendStatus, bool requesting, bool requested,
     bool onlineFilter, UserAuthenticationEntity userAuthenticationEntity, string region = "jp", string language = "ja")
 {
     var url = string.Format(EndPoints.FriendList, region, username, offset);
     if (onlineFilter) url += "&filter=online";
     if (friendStatus && !requesting && !requested) url += "&friendStatus=friend&presenceType=primary";
     if (friendStatus && requesting && !requested) url += "&friendStatus=requesting";
     if (friendStatus && !requesting && requested) url += "&friendStatus=requested";
     if (personalDetailSharing && requested) url += "&friendStatus=friend&personalDetailSharing=requested&presenceType=primary";
     if (personalDetailSharing && requesting) url += "&friendStatus=friend&personalDetailSharing=requesting&presenceType=primary";
     if (playedRecently)
         url =
             string.Format(
                 EndPoints.RecentlyPlayed, username);
     if (blockedPlayer) url =
         $"https://{region}-prof.np.community.playstation.net/userProfile/v1/users/{username}/blockList?fields=@default,@profile&offset={offset}";
     url += "&r=" + Guid.NewGuid();
     return await _webManager.GetData(new Uri(url), userAuthenticationEntity, language);
 }
 public async Task<Stream> GetMessageContent(string id, string messageUid, UserAuthenticationEntity userAuthenticationEntity, string region = "jp", string language = "ja")
 {
     try
     {
         var content = "image-data-0";
         string url =
             $"https://{region}-gmsg.np.community.playstation.net/groupMessaging/v1/messageGroups/{id}/messages/{messageUid}?contentKey={content}&npLanguage={language}";
         var theAuthClient = new HttpClient();
         var request = new HttpRequestMessage(HttpMethod.Get, url);
         request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true };
         request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAuthenticationEntity.AccessToken);
         var response = await theAuthClient.SendAsync(request);
         var responseContent = await response.Content.ReadAsStreamAsync();
         return responseContent;
     }
     catch (Exception)
     {
         return null;
     }
 }
        public async Task<Result> CreatePost(string messageUserId, string post,
            UserAuthenticationEntity userAuthenticationEntity, string region = "jp")
        {
            var url = string.Format(EndPoints.CreatePost, region, messageUserId);
            const string boundary = "abcdefghijklmnopqrstuvwxyz";
            var messageJson = new SendMessage
            {
                message = new Message()
                {
                    body = post,
                    fakeMessageUid = 1384958573288,
                    messageKind = 1
                }
            };

            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);
        }
 public async Task<Result> GetNicoFeed(string status, string platform, bool titlePreset, int offset,
     int limit, string sort, string query,
     UserAuthenticationEntity userAuthenticationEntity)
 {
     var url = EndPoints.NicoNicoBaseUrl;
     // Sony's app hardcodes this value to 0. 
     // This app could, in theory, allow for more polling of data, so these options are left open to new values and limits.
     if (!string.IsNullOrEmpty(query))
     {
         url += $"keyword={query}&";
     }
     url += $"offset={offset}&";
     url += $"limit={limit}&";
     url += $"status={status}&";
     url += $"sce_platform={platform}&";
     if (titlePreset)
     {
         url += "sce_title_preset=true&";
     }
     url += $"sort={sort}";
     // TODO: Fix this cheap hack to get around caching issue. For some reason, no-cache is not working...
     url += "&r=" + Guid.NewGuid();
     return await _webManager.GetData(new Uri(url), userAuthenticationEntity);
 }
        public async Task<Result> CreateNewGroupMessage(string[] toArray, string message, UserAuthenticationEntity currentTokens, string region)
        {
            var url = string.Format(EndPoints.CreateNewGroupPost, region);
            const string boundary = "gc0p4Jq0M2Yt08jU534c0p";
            var messageJson = new SendMessage
            {
                to = toArray,
                message = new Message()
                {
                    body = message,
                    fakeMessageUid = 1234,
                    messageKind = 1
                }
            };

            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, currentTokens, "ja", true);
        }
        public async Task<Result> CreateNewGroupMessageWithMedia(string[] toArray, string message, string imagePath, Stream realImage, UserAuthenticationEntity currentTokens, string region)
        {
            var url = string.Format(EndPoints.CreateNewGroupPost, region);
            const string boundary = "gc0p4Jq0M2Yt08jU534c0p";
            var messageJson = new SendMessage
            {
                to = toArray,
                message = new Message()
                {
                    body = message,
                    fakeMessageUid = 1234,
                    messageKind = 3
                }
            };

            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 };
            var t = new StreamContent(realImage);
            t.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
            t.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
            t.Headers.Add("Content-Description", "image-data-0");
            t.Headers.Add("Content-Transfer-Encoding", "binary");
            t.Headers.ContentLength = realImage.Length;
            form.Add(t);

            return await _webManager.PostData(new Uri(url), form, currentTokens, "ja", true);
        }
        public async Task<Result> CreatePostWithMedia(string messageUserId, string post, string path, Stream stream,
            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 = post,
                    fakeMessageUid = 1234,
                    messageKind = 3
                }
            };

            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 };
            var t = new StreamContent(stream);
            t.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
            t.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
            t.Headers.Add("Content-Description", "image-data-0");
            t.Headers.Add("Content-Transfer-Encoding", "binary");
            t.Headers.ContentLength = stream.Length;
            form.Add(t);

            return await _webManager.PostData(new Uri(url), form, userAuthenticationEntity);
        }
 public async Task<Result> GetFriendLink(UserAuthenticationEntity userAuthenticationEntity)
 {
     var param = new Dictionary<string, string> { { "type", "ONE" } };
     var jsonObject = JsonConvert.SerializeObject(param);
     var stringContent = new StringContent(jsonObject, Encoding.UTF8, "application/json");
     return await _webManager.PostData(new Uri(EndPoints.FriendMeUrl), stringContent, userAuthenticationEntity);
 }
 public async Task<Result> GetEventLiveBroadcast(string id, UserAuthenticationEntity userAuthenticationEntity)
 {
     var url = string.Format(EndPoints.EventLiveBroadcast, id);
     return await _webManager.GetData(new Uri(url), userAuthenticationEntity);
 }
 public async Task<Result> GetFriendRequestMessage(string username, string currentUserOnlineId, UserAuthenticationEntity userAuthenticationEntity, string region = "jp")
 {
     var url = string.Format(EndPoints.RequestMessage, region, currentUserOnlineId, username);
     return await _webManager.GetData(new Uri(url), userAuthenticationEntity);
 }
 public async Task<Result> GetVideoFeedFromPsn(string serviceType, string sort, UserAuthenticationEntity userAuthenticationEntity, string language = "ja")
 {
     return await _webManager.GetData(new Uri(string.Format(EndPoints.LiveBroadcast, serviceType, sort, language)),
         userAuthenticationEntity);
 }
 public async Task<Result> GetUserEntity(UserAuthenticationEntity entity, string lang)
 {
     return await _webManager.GetData(new Uri(EndPoints.VerifyUser), entity, lang);
 }
 public async Task<Result> GetEventDetailFriends(string id, int offset, int limit, UserAuthenticationEntity userAuthenticationEntity,
     string region = "ja")
 {
     var url = string.Format(EndPoints.EventDetailFriends, region, id, offset, limit);
     return await _webManager.GetData(new Uri(url), userAuthenticationEntity);
 }
        public async Task<Result> CreatePostWithMedia(string messageUserId, string post, string path, byte[] fileStream,
            UserAuthenticationEntity userAuthenticationEntity, string region = "jp")
        {
            var url = string.Format(EndPoints.CreatePost, region, messageUserId);
            const string boundary = "abcdefghijklmnopqrstuvwxyz";
            var messageJson = new SendMessage
            {
                message = new Message()
                {
                    body = post,
                    fakeMessageUid = 1445225905274,
                    messageKind = 3
                }
            };

            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 };

            Stream stream = new MemoryStream(fileStream);
            var t = new StreamContent(stream);
            var s = Path.GetExtension(path);
            if (s != null && s.Equals(".png"))
            {
                t.Headers.ContentType = new MediaTypeHeaderValue("image/png");
            }
            else
            {
                var extension = Path.GetExtension(path);
                if (extension != null && (extension.Equals(".jpg") || extension.Equals(".jpeg")))
                {
                    t.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
                }
                else
                {
                    t.Headers.ContentType = new MediaTypeHeaderValue("image/gif");
                }
            }
            t.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
            t.Headers.Add("Content-Description", "image-data-0");
            t.Headers.Add("Content-Transfer-Encoding", "binary");
            t.Headers.ContentLength = stream.Length;
            form.Add(t);

            return await _webManager.PostData(new Uri(url), form, userAuthenticationEntity);
        }
 public async Task<Result> ClearMessages(string messageGroupId, List<float> messageUids, UserAuthenticationEntity userAuthenticationEntity, string region = "jp")
 {
     var url = string.Format(EndPoints.ClearMessages, region, messageGroupId, string.Join(",", messageUids));
     var json = new StringContent("{\"seenFlag\":true}", Encoding.UTF8, "application/json");
     return await _webManager.PutData(new Uri(url), json, userAuthenticationEntity);
 }
 public async Task<Result> AddEvent(string id, string username, UserAuthenticationEntity userAuthenticationEntity, string region = "ja")
 {
     var url = string.Format(EndPoints.AddRemoveEvent, region, id, username);
     var json = new StringContent("{\"autoBootPreference\":{\"autoBootFlag\":false,\"key\":\"\"}}", Encoding.UTF8, "application/json");
     return await _webManager.PutData(new Uri(url), json, userAuthenticationEntity);
 }
 public async Task<Result> DeleteFriend(string username, string currentUserOnlineId, UserAuthenticationEntity userAuthenticationEntity, string region = "jp", string language = "ja")
 {
     var url = string.Format(EndPoints.DenyAddFriend, region, currentUserOnlineId, username);
     var result = await _webManager.DeleteData(new Uri(url), null, userAuthenticationEntity, language);
     return new Result(result.IsSuccess, string.Empty);
 }
 public async Task<Result> SearchForFriends(string query, UserAuthenticationEntity userAuthenticationEntity,
     string region = "jp", string language = "ja")
 {
     var url = String.Format(EndPoints.FriendFinder, query);
     return await _webManager.GetData(new Uri(url), userAuthenticationEntity, language);
 }
 public async Task<Result> RemoveEvent(string id, string username, UserAuthenticationEntity userAuthenticationEntity, string region = "ja")
 {
     var url = string.Format(EndPoints.AddRemoveEvent, region, id, username);
     return await _webManager.DeleteData(new Uri(url), null, userAuthenticationEntity);
 }