public async Task <TrophyEntity> GetTrophyList(string user, int offset, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); var userAccount = userAccountEntity.GetUserEntity(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } string url = string.Format("https://{0}-tpy.np.community.playstation.net/trophy/v1/trophyTitles?fields=%40default&npLanguage={1}&iconSize=s&platform=PS3%2CPSVITA%2CPS4&offset={2}&limit=64&comparedUser={3}&fromUser={4}", userAccount.Region, userAccount.Language, offset, user, userAccountEntity.GetUserEntity().OnlineId); // TODO: Fix this cheap hack to get around caching issue. For some reason, no-cache is not working... url += "&r=" + Guid.NewGuid(); var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(null); } var trophy = JsonConvert.DeserializeObject <TrophyEntity>(responseContent); return(trophy); } catch (Exception) { return(null); } }
public async Task <FriendTokenEntity> GetFriendLink(UserAccountEntity userAccountEntity) { try { var user = userAccountEntity.GetUserEntity(); var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var theAuthClient = new HttpClient(); var param = new Dictionary <String, String> { { "type", "ONE" } }; var jsonObject = JsonConvert.SerializeObject(param); var stringContent = new StringContent(jsonObject, Encoding.UTF8, "application/json"); var request = new HttpRequestMessage(HttpMethod.Post, UrlConstants.FriendMeUrl) { Content = stringContent }; request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); var response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <FriendTokenEntity>(responseContent));; } catch (Exception) { return(null); } }
public static async Task <bool> ClearNotification(NotificationEntity.Notification notification, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); var user = userAccountEntity.GetUserEntity(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } string url = string.Format("https://{0}-ntl.np.community.playstation.net/notificationList/v1/users/{1}/notifications/{2}/{3}", user.Region, user.OnlineId, notification.NotificationGroup, notification.NotificationId); var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Put, url) { Content = new StringContent("{\"seenFlag\":true}", Encoding.UTF8, "application/json") }; request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; HttpResponseMessage response = await theAuthClient.SendAsync(request); return(response.IsSuccessStatusCode); } catch (Exception) { return(false); } }
public async Task <Stream> GetMessageContent(string id, MessageEntity.Message message, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); var user = userAccountEntity.GetUserEntity(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var content = "image-data-0"; string url = string.Format("https://{0}-gmsg.np.community.playstation.net/groupMessaging/v1/messageGroups/{1}/messages/{2}?contentKey={3}&npLanguage={4}", user.Region, id, message.messageUid, content, user.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", userAccountEntity.GetAccessToken()); var response = await theAuthClient.SendAsync(request); var responseContent = await response.Content.ReadAsStreamAsync(); return(responseContent); } catch (Exception) { return(null); } }
public async Task <UserAccountEntity.User> GetUserEntity(UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, UrlConstants.VerifyUser); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(null); } UserAccountEntity.User user = UserAccountEntity.ParseUser(responseContent); return(user); } catch (Exception) { return(null); } }
public async Task <NotificationEntity> GetNotifications(string username, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); var user = userAccountEntity.GetUserEntity(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } string url = string.Format("https://{0}-ntl.np.community.playstation.net/notificationList/v1/users/{1}/notifications?fields=@default%2Cmessage%2CactionUrl&npLanguage={2}", user.Region, username, user.Language); var theAuthClient = new HttpClient(); // TODO: Fix this cheap hack to get around caching issue. For some reason, no-cache is not working... url += "&r=" + Guid.NewGuid(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(null); } var notification = JsonConvert.DeserializeObject <NotificationEntity>(responseContent); return(notification); } catch (Exception) { return(null); } }
public async void ClearMessages(MessageEntity messageEntity, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); var user = userAccountEntity.GetUserEntity(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var messageUids = new List <int>(); messageUids.AddRange(messageEntity.messages.Where(o => o.seenFlag == false).Select(message => message.messageUid)); if (messageUids.Count == 0) { return; } string url = string.Format("https://{0}-gmsg.np.community.playstation.net/groupMessaging/v1/messageGroups/{1}/messages?messageUid={2}", user.Region, messageEntity.messageGroup.messageGroupId, string.Join(",", messageUids)); var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Put, url); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; request.Headers.Add("Origin", "http://psapp.dl.playstation.net"); request.Headers.Add("Referer", "http://psapp.dl.playstation.net/psapp/6228351b09c436f44f1c53955c0a51ca/index.html"); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); request.Content = new StringContent("{\"seenFlag\":true}", Encoding.UTF8, "application/json"); await theAuthClient.SendAsync(request); } catch (Exception) { Debug.WriteLine("Failed to clear messages"); } }
public async Task <SessionInviteDetailEntity> GetInviteInformation(string inviteId, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); var user = userAccountEntity.GetUserEntity(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } string url = string.Format("https://{0}-ivt.np.community.playstation.net/sessionInvitation/v1/users/{1}/invitations/{2}?fields=@default,npTitleDetail,session,members&npLanguage={3}", user.Region, user.OnlineId, inviteId, user.Language); // TODO: Fix this cheap hack to get around caching issue. For some reason, no-cache is not working... url += "&r=" + Guid.NewGuid(); var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; var response = await theAuthClient.SendAsync(request); var responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(null); } var sessionInvite = JsonConvert.DeserializeObject <SessionInviteDetailEntity>(responseContent); return(sessionInvite); } catch (Exception) { return(null); } }
public async Task <UserAccountEntity.User> GetUserEntity(UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } string url = "https://vl.api.np.km.playstation.net/vl/api/v1/mobile/users/me/info"; var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(null); } UserAccountEntity.User user = UserAccountEntity.ParseUser(responseContent); return(user); } catch (Exception) { return(null); } }
public async Task <Result> DeleteData(Uri uri, StringContent json, UserAccountEntity userAccountEntity) { var httpClient = new HttpClient(); try { var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var user = userAccountEntity.GetUserEntity(); if (user != null) { var language = userAccountEntity.GetUserEntity().Language; httpClient.DefaultRequestHeaders.Add("Accept-Language", language); } httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); var response = await httpClient.DeleteAsync(uri); var responseContent = await response.Content.ReadAsStringAsync(); return(response.IsSuccessStatusCode ? new Result(true, string.Empty) : new Result(false, responseContent)); } catch (Exception) { return(new Result(false, string.Empty)); } }
public async Task <Result> GetData(Uri uri, UserAccountEntity userAccountEntity) { var httpClient = new HttpClient(); try { var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var user = userAccountEntity.GetUserEntity(); if (user != null) { var language = userAccountEntity.GetUserEntity().Language; httpClient.DefaultRequestHeaders.Add("Accept-Language", language); } httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); var response = await httpClient.GetAsync(uri); if (response.StatusCode == HttpStatusCode.NotFound) { throw new WebException("PSN API Error: Service not found."); } var responseContent = await response.Content.ReadAsStringAsync(); return(string.IsNullOrEmpty(responseContent) ? new Result(false, string.Empty) : new Result(true, responseContent)); } catch { throw new WebException("PSN API Error: Service not found."); } }
public async Task <bool> SendNameRequest(string username, UserAccountEntity userAccountEntity) { try { var user = userAccountEntity.GetUserEntity(); var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var theAuthClient = new HttpClient(); var param = new Dictionary <String, String>(); var url = string.Format("https://{0}-prof.np.community.playstation.net/userProfile/v1/users/{1}/friendList/{2}/personalDetailSharing", user.Region, user.OnlineId, username); var request = new HttpRequestMessage(HttpMethod.Post, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); //string requestContent = await request.Content.ReadAsStringAsync(); var response = await theAuthClient.SendAsync(request); return(response.IsSuccessStatusCode); } catch (Exception) { return(false); } }
public async static Task <UserEntity> GetUserAvatar(string userName, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); var user = userAccountEntity.GetUserEntity(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } string url = string.Format("https://{0}-prof.np.community.playstation.net/userProfile/v1/users/{1}/profile?fields=avatarUrl", user.Region, userName); // TODO: Fix this cheap hack to get around caching issue. For some reason, no-cache is not working... url += "&r=" + Guid.NewGuid(); var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(null); } var friend = JsonConvert.DeserializeObject <UserEntity>(responseContent); return(friend); } catch (Exception) { return(null); } }
public async Task <string> GetRequestMessage(string username, UserAccountEntity userAccountEntity) { try { var user = userAccountEntity.GetUserEntity(); var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var theAuthClient = new HttpClient(); var url = string.Format("https://{0}-prof.np.community.playstation.net/userProfile/v1/users/{1}/friendList/{2}/requestMessage", user.Region, user.OnlineId, username); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); var response = await theAuthClient.SendAsync(request); var responseContent = await response.Content.ReadAsStringAsync(); var o = JObject.Parse(responseContent); return(o["requestMessage"] != null ? (string)o["requestMessage"] : string.Empty); } catch (Exception) { return(null); } }
public async Task <MessageEntity> GetGroupConversation(string messageGroupId, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); var user = userAccountEntity.GetUserEntity(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var url = string.Format("https://{0}-gmsg.np.community.playstation.net/groupMessaging/v1/messageGroups/{1}/messages?fields=@default%2CmessageGroup%2Cbody&npLanguage={2}", user.Region, messageGroupId, user.Language); var theAuthClient = new HttpClient(); // TODO: Fix this cheap hack to get around caching issue. For some reason, no-cache is not working... url += "&r=" + Guid.NewGuid(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; var response = await theAuthClient.SendAsync(request); var responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(null); } var messageGroup = JsonConvert.DeserializeObject <MessageEntity>(responseContent); return(messageGroup.messages == null ? null : messageGroup); } catch (Exception) { return(null); } }
public async Task <UstreamEntity> GetUstreamFeed(int pageNumber, int pageSize, string detailLevel, Dictionary <string, string> filterList, string sortBy, string query, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var url = UrlConstants.UstreamBaseUrl; url += string.Format("p={0}&", pageNumber); url += string.Format("pagesize={0}&", pageSize); url += string.Format("detail_level={0}&", detailLevel); foreach (var item in filterList) { if (item.Key.Equals(UstreamUrlConstants.Interactive)) { url += string.Format(UstreamUrlConstants.FilterBase, UstreamUrlConstants.PlatformPs4) + "[interactive]=" + item.Value + "&"; } else { url += string.Concat(string.Format(UstreamUrlConstants.FilterBase, item.Key), "=", item.Value + "&"); } } url += string.Format("sort={0}", sortBy); var theAuthClient = new HttpClient(); // TODO: Fix this cheap hack to get around caching issue. For some reason, no-cache is not working... url += "&r=" + Guid.NewGuid(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(null); } // Instead of parsing the object manually, let JSON.net do it for us. var ustreamEntity = JsonConvert.DeserializeObject <UstreamEntity>(responseContent); return(ustreamEntity); } catch (Exception) { return(null); } }
public async Task <TwitchEntity> GetTwitchFeed(int offset, int limit, string platform, string titlePreset, string query, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var url = UrlConstants.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 += string.Format("offset={0}&", offset); url += string.Format("limit={0}&", limit); //url += string.Format("sce_platform={0}&", platform); // "sce_title_preset" represents the "Interactive" filter. //url += string.Format("sce_title_preset={0}&", titlePreset); url += string.Format("query={0}&", query); string language = userAccountEntity.GetUserEntity().Language; var theAuthClient = new HttpClient(); theAuthClient.DefaultRequestHeaders.Add("Accept-Language", language); // TODO: Fix this cheap hack to get around caching issue. For some reason, no-cache is not working... url += "&r=" + Guid.NewGuid(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); // Twitch requires a "Platform" header to be added in order for the request to go through. // In this case, we can use Sony's key to let us in. request.Headers.Add("platform", "54bd6377db3b48cba9ecc44bff5a410b"); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(null); } // Instead of parsing the object manually, let JSON.net do it for us. var twitchEntity = JsonConvert.DeserializeObject <TwitchEntity>(responseContent); return(twitchEntity); } catch (Exception) { return(null); } }
public async Task <bool> CreatePostWithAudio(string messageUserId, string post, byte[] fileStream, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); const string boundary = "abcdefghijklmnopqrstuvwxyz"; var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, string.Format("https://jp-gmsg.np.community.playstation.net/groupMessaging/v1/messageGroups/{0}/messages", messageUserId)); var form = new MultipartContent("mixed", boundary); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); var messageJson = new SendMessage { message = new Message() { body = post, fakeMessageUid = 1384958573288, messageKind = 1011 } }; string json = JsonConvert.SerializeObject(messageJson); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); stringContent.Headers.Add("Content-Description", "message"); form.Add(stringContent); Stream stream = new MemoryStream(fileStream); var t = new StreamContent(stream); t.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); t.Headers.Add("Content-Description", "voice-data-0"); t.Headers.Add("Content-Type", "audio/3gpp"); t.Headers.Add("Content-Transfer-Encoding", "binary"); t.Headers.Add("Content-Voice-Data-Playback-Time", "14"); t.Headers.ContentLength = stream.Length; form.Add(t); request.Content = form; HttpResponseMessage response = await theAuthClient.SendAsync(request); await response.Content.ReadAsStringAsync(); return(response.IsSuccessStatusCode); } catch (Exception) { { return(false); } } }
public async Task <NicoNicoEntity> GetNicoFeed(string status, string platform, int offset, int limit, string sort, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var url = UrlConstants.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. url += string.Format("offset={0}&", offset); url += string.Format("limit={0}&", limit); url += string.Format("status={0}&", status); url += string.Format("sce_platform={0}&", platform); url += string.Format("sort={0}", sort); // TODO: Fix this cheap hack to get around caching issue. For some reason, no-cache is not working... url += "&r=" + Guid.NewGuid(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; string language = userAccountEntity.GetUserEntity().Language; var theAuthClient = new HttpClient(); theAuthClient.DefaultRequestHeaders.Add("Accept-Language", language); HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(null); } // Instead of parsing the object manually, let JSON.net do it for us. var niconicoEntity = JsonConvert.DeserializeObject <NicoNicoEntity>(responseContent); return(niconicoEntity); } catch (Exception) { // If something breaks, take the error. // We can just reload and try again. return(null); } }
public async Task <bool> CreatePost(string messageUserId, string post, UserAccountEntity userAccountEntity) { try { var user = userAccountEntity.GetUserEntity(); var authenticationManager = new AuthenticationManager(); const string boundary = "abcdefghijklmnopqrstuvwxyz"; var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, string.Format("https://{0}-gmsg.np.community.playstation.net/groupMessaging/v1/messageGroups/{1}/messages", user.Region, messageUserId)); var form = new MultipartContent("mixed", boundary); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); 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"); form.Add(stringContent); request.Content = form; HttpResponseMessage response = await theAuthClient.SendAsync(request); await response.Content.ReadAsStringAsync(); return(response.IsSuccessStatusCode); } catch (Exception) { { return(false); } } }
public async Task <RecentActivityEntity> GetActivityFeed(string userName, int?pageNumber, bool storePromo, bool isNews, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); var feedNews = isNews ? "news" : "feed"; if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } string url = string.Format("https://activity.api.np.km.playstation.net/activity/api/v1/users/{0}/{1}/{2}?filters=PURCHASED&filters=RATED&filters=VIDEO_UPLOAD&filters=SCREENSHOT_UPLOAD&filters=PLAYED_GAME&filters=WATCHED_VIDEO&filters=TROPHY&filters=BROADCASTING&filters=LIKED&filters=PROFILE_PIC&filters=FRIENDED&filters=CONTENT_SHARE", userName, feedNews, pageNumber); // TODO: Fix this cheap hack to get around caching issue. For some reason, no-cache is not working... if (storePromo) { url += "&filters=STORE_PROMO"; } url += "&r=" + Guid.NewGuid(); string language = userAccountEntity.GetUserEntity().Language; var theAuthClient = new HttpClient(); theAuthClient.DefaultRequestHeaders.Add("Accept-Language", language); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; var response = await theAuthClient.SendAsync(request); var responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(null); } var recentActivityEntity = JsonConvert.DeserializeObject <RecentActivityEntity>(responseContent); return(recentActivityEntity); } catch (Exception) { return(null); } }
public async Task <TrophyDetailEntity> GetTrophyDetailList(string gameId, string comparedUser, bool includeHidden, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); var user = userAccountEntity.GetUserEntity(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } string url = string.Format("https://{0}-tpy.np.community.playstation.net/trophy/v1/trophyTitles/{1}/trophyGroups/all/trophies?fields=@default,trophyRare,trophyEarnedRate&npLanguage={2}&iconSize=m&comparedUser={3}&fromUser={4}", user.Region, gameId, user.Language, comparedUser, user.OnlineId); var theAuthClient = new HttpClient(); // TODO: Fix this cheap hack to get around caching issue. For some reason, no-cache is not working... url += "&r=" + Guid.NewGuid(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseContent)) { return(null); } var trophy = JsonConvert.DeserializeObject <TrophyDetailEntity>(responseContent); if (!includeHidden) { trophy.Trophies = trophy.Trophies.Where(trophyDetail => trophyDetail.TrophyHidden != true).ToList(); } return(trophy); } catch (Exception) { return(null); } }
public async Task <Result> PostData(Uri uri, MultipartContent header, StringContent content, UserAccountEntity userAccountEntity) { var httpClient = new HttpClient(); try { var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var user = userAccountEntity.GetUserEntity(); if (user != null) { var language = userAccountEntity.GetUserEntity().Language; httpClient.DefaultRequestHeaders.Add("Accept-Language", language); } httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); HttpResponseMessage response; if (header == null) { response = await httpClient.PostAsync(uri, content); } else { response = await httpClient.PostAsync(uri, header); } var responseContent = await response.Content.ReadAsStringAsync(); return(new Result(true, responseContent)); } catch { // TODO: Add detail error result to json object. return(new Result(false, string.Empty)); } }
public async Task <bool> LikeDislikeFeedItem(bool isLiked, string feedId, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); var liked = isLiked ? "like" : "dislike"; if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } string url = string.Format("https://activity.api.np.km.playstation.net/activity/api/v1/users/{0}/set/{1}/story/{2}", userAccountEntity.GetUserEntity().OnlineId, liked, feedId); var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); var response = await theAuthClient.SendAsync(request); return(response.IsSuccessStatusCode); } catch (Exception) { return(false); } }
public async Task <bool> SendFriendRequest(string username, string requestMessage, UserAccountEntity userAccountEntity) { try { var user = userAccountEntity.GetUserEntity(); var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var theAuthClient = new HttpClient(); var param = new Dictionary <String, String>(); var url = string.Format("https://{0}-prof.np.community.playstation.net/userProfile/v1/users/{1}/friendList/{2}?requestMessage={3}", user.Region, user.OnlineId, username, requestMessage); if (!string.IsNullOrEmpty(requestMessage)) { param.Add("requestMessage", requestMessage); } var jsonObject = JsonConvert.SerializeObject(param); var stringContent = new StringContent(jsonObject, Encoding.UTF8, "application/json"); var request = new HttpRequestMessage(HttpMethod.Post, url) { Content = stringContent }; request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); string requestContent = await request.Content.ReadAsStringAsync(); var response = await theAuthClient.SendAsync(request); return(response.IsSuccessStatusCode); } catch (Exception) { return(false); } }
public async Task <bool> DenyAddFriend(bool isRemove, string username, UserAccountEntity userAccountEntity) { try { var user = userAccountEntity.GetUserEntity(); var authenticationManager = new AuthenticationManager(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } var theAuthClient = new HttpClient(); var url = string.Format("https://{0}-prof.np.community.playstation.net/userProfile/v1/users/{1}/friendList/{2}", user.Region, user.OnlineId, username); var httpMethod = isRemove ? HttpMethod.Delete : HttpMethod.Put; var request = new HttpRequestMessage(httpMethod, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); var response = await theAuthClient.SendAsync(request); return(response.IsSuccessStatusCode); } catch (Exception) { return(false); } }
public async Task <Stream> GetImageMessageContent(string id, MessageEntity.Message message, UserAccountEntity userAccountEntity) { try { var user = userAccountEntity.GetUserEntity(); const string content = "image-data-0"; var url = string.Format(EndPoints.MessageContent, user.Region, id, message.messageUid, content, user.Language); url += "&r=" + Guid.NewGuid(); var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true }; request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); var response = await theAuthClient.SendAsync(request); var responseContent = await response.Content.ReadAsStreamAsync(); return(responseContent); } catch (Exception ex) { throw new Exception("Failed to get image message content", ex); } }
public async Task <bool> CreatePostWithMedia(string messageUserId, string post, String path, byte[] fileStream, UserAccountEntity userAccountEntity) { try { var user = userAccountEntity.GetUserEntity(); var authenticationManager = new AuthenticationManager(); const string boundary = "abcdefghijklmnopqrstuvwxyz"; var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, string.Format("https://{0}-gmsg.np.community.playstation.net/groupMessaging/v1/messageGroups/{1}/messages", user.Region, messageUserId)); var form = new MultipartContent("mixed", boundary); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); var messageJson = new SendMessage { message = new Message() { body = post, fakeMessageUid = 1384958573288, messageKind = 3 } }; string json = JsonConvert.SerializeObject(messageJson); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); stringContent.Headers.Add("Content-Description", "message"); form.Add(stringContent); Stream stream = new MemoryStream(fileStream); var t = new StreamContent(stream); string fileName = "testtesttesttest.jpg"; var s = Path.GetExtension(path); if (s != null && s.Equals(".png")) { t.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/png"); } else { var extension = Path.GetExtension(path); if (extension != null && (extension.Equals(".jpg") || extension.Equals(".jpeg"))) { t.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpeg"); } else { t.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/gif"); } } t.Headers.ContentType = new System.Net.Http.Headers.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); request.Content = form; HttpResponseMessage response = await theAuthClient.SendAsync(request); string test = await response.Content.ReadAsStringAsync(); return(response.IsSuccessStatusCode); } catch (Exception) { { return(false); } } }
public async Task <FriendsEntity> GetFriendsList(string username, int?offset, bool blockedPlayer, bool playedRecently, bool personalDetailSharing, bool friendStatus, bool requesting, bool requested, bool onlineFilter, UserAccountEntity userAccountEntity) { try { var authenticationManager = new AuthenticationManager(); var user = userAccountEntity.GetUserEntity(); if (userAccountEntity.GetAccessToken().Equals("refresh")) { await authenticationManager.RefreshAccessToken(userAccountEntity); } string url = string.Format("https://{0}-prof.np.community.playstation.net/userProfile/v1/users/{1}/friendList?fields=@default,relation,onlineId%2CavatarUrl%2Cplus%2CpersonalDetail%2CtrophySummary&sort=onlineId&avatarSize=m&offset={2}&limit=32", user.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( "https://activity.api.np.km.playstation.net/activity/api/v1/users/{0}/recentlyplayed?", username); } if (blockedPlayer) { url = string.Format("https://{0}-prof.np.community.playstation.net/userProfile/v1/users/{1}/blockList?fields=%40default%2C%40profile&offset={2}", user.Region, username, offset); } // TODO: Fix this cheap hack to get around caching issue. For some reason, no-cache is not working... url += "&r=" + Guid.NewGuid(); var theAuthClient = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Get, url); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken()); request.Headers.CacheControl = new CacheControlHeaderValue { NoCache = true, MustRevalidate = true }; HttpResponseMessage response = await theAuthClient.SendAsync(request); string responseContent = await response.Content.ReadAsStringAsync(); var friend = JsonConvert.DeserializeObject <FriendsEntity>(responseContent); return(friend); } catch (Exception) { return(null); } }