コード例 #1
6
ファイル: UserManager.cs プロジェクト: happy-ryo/CrouMetro
        public static async Task<bool> ChangeUserProfile(String name, String url, String description, String location,
            UserAccountEntity userAccountEntity)
        {
            if (userAccountEntity.GetAccessToken().Equals("refresh"))
            {
                await Auth.RefreshAccessToken(userAccountEntity);
            }
            var param = new Dictionary<String, String>();
            if (!string.IsNullOrEmpty(name)) param.Add("name", name);
            if (!string.IsNullOrEmpty(url)) param.Add("url", url);
            if (!string.IsNullOrEmpty(location)) param.Add("location", location);
            if (!string.IsNullOrEmpty(description)) param.Add("description", description);

            var theAuthClient = new HttpClient();
            HttpContent header = new FormUrlEncodedContent(param);
            var request = new HttpRequestMessage(HttpMethod.Post, EndPoints.ACCOUNT_UPDATE) {Content = header};
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken());
            try
            {
                HttpResponseMessage response = await theAuthClient.SendAsync(request);
                return response.IsSuccessStatusCode;
            }
            catch (Exception)
            {
                return false;
            }
        }
コード例 #2
0
        public static async Task<List<PostEntity>> GetMentions(bool? trim, long? sinceId, long? maxId, int? count,
            UserAccountEntity userAccountEntity)
        {
            if (userAccountEntity.GetAccessToken().Equals("refresh"))
            {
                await Auth.RefreshAccessToken(userAccountEntity);
            }

            string url = EndPoints.MENTIONS_TIMELINE + "?";
            //if (trim != null) url += "&trim_user="******"&since_id=" + sinceId;
            if (maxId != null) url += "&max_id=" + maxId;
            if (count != null) url += "&count=" + count;

            var theAuthClient = new HttpClient();
            var request = new HttpRequestMessage(HttpMethod.Get, url);
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken());
            try
            {
                HttpResponseMessage response = await theAuthClient.SendAsync(request);
                string responseContent = await response.Content.ReadAsStringAsync();
                return PostEntity.Parse(responseContent, userAccountEntity);
            }
            catch (Exception)
            {
                return null;
            }
        }
コード例 #3
0
ファイル: StatusManager.cs プロジェクト: happy-ryo/CrouMetro
        public static async Task<bool> UpdateStatus(String status, long? inReply, bool? inQuote, bool? trim,
            UserAccountEntity userAccountEntity)
        {
            var param = new Dictionary<String, String> {{"status", status}};
            if (inReply != null) param.Add("in_reply_to_status_id", inReply.ToString());
            if (inQuote == true) param.Add("in_reply_with_quote", true.ToString());
            if (trim == true) param.Add("trim_user", true.ToString());

            var theAuthClient = new HttpClient();
            var request = new HttpRequestMessage(HttpMethod.Post, EndPoints.STATUS_UPDATE);

            string accessToken = userAccountEntity.GetAccessToken();
            if (accessToken.Equals("refresh"))
            {
                await Auth.RefreshAccessToken(userAccountEntity);
                accessToken = userAccountEntity.GetAccessToken();
            }

            HttpContent header = new FormUrlEncodedContent(param);
            request.Content = header;
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            try
            {
                HttpResponseMessage response = await theAuthClient.SendAsync(request);
                return response.IsSuccessStatusCode;
            }
            catch (Exception)
            {
                return false;
            }
        }
コード例 #4
0
ファイル: SearchManager.cs プロジェクト: happy-ryo/CrouMetro
 public static async Task<List<UserEntity>> SearchUserList(string query, int? count, int? page, bool trim,
     UserAccountEntity userAccountEntity)
 {
     if (userAccountEntity.GetAccessToken().Equals("refresh"))
     {
         await Auth.RefreshAccessToken(userAccountEntity);
     }
     var paramer = "?q=" + query;
     if (count.HasValue)
     {
         paramer += "&count=" + count.Value;
     }
     if (page.HasValue)
     {
         paramer += "&page=" + page.Value;
     }
     if (trim)
     {
         paramer += "&trim_user="******"Bearer", userAccountEntity.GetAccessToken());
     try
     {
         HttpResponseMessage response = await theAuthClient.SendAsync(request);
         string responseContent = await response.Content.ReadAsStringAsync();
         return UserEntity.ParseUserList(responseContent, userAccountEntity);
     }
     catch (Exception)
     {
         return null;
     }
 }
コード例 #5
0
        public static async Task<bool> CreateMail(String text, long? userId, String screenName,
            UserAccountEntity userAccountEntity)
        {
            var param = new Dictionary<String, String> {{"text", text}, {"user_id", userId.ToString()}};
            var theAuthClient = new HttpClient();
            var request = new HttpRequestMessage(HttpMethod.Post, EndPoints.MESSAGE_NEW);

            string accessToken = userAccountEntity.GetAccessToken();
            if (accessToken.Equals("refresh"))
            {
                await Auth.RefreshAccessToken(userAccountEntity);
                accessToken = userAccountEntity.GetAccessToken();
            }

            HttpContent header = new FormUrlEncodedContent(param);
            request.Content = header;
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            try
            {
                HttpResponseMessage response = await theAuthClient.SendAsync(request);
                return response.IsSuccessStatusCode;
            }
            catch (Exception)
            {
                return false;
            }
        }
コード例 #6
0
ファイル: SpreadManager.cs プロジェクト: happy-ryo/CrouMetro
        public static async Task<HttpStatusCode> CreateSpread(long id, bool? trim, UserAccountEntity userAccountEntity)
        {
            var param = new Dictionary<String, String>();
            if (trim == true) param.Add("trim_user", trim.ToString());
            var theAuthClient = new HttpClient();
            var request = new HttpRequestMessage(HttpMethod.Post, (String.Format(EndPoints.SPREAD_CREATE, id)));

            string accessToken = userAccountEntity.GetAccessToken();
            if (accessToken.Equals("refresh"))
            {
                await Auth.RefreshAccessToken(userAccountEntity);
                accessToken = userAccountEntity.GetAccessToken();
            }

            HttpContent header = new FormUrlEncodedContent(param);
            request.Content = header;
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            try
            {
                HttpResponseMessage response = await theAuthClient.SendAsync(request);
                return response.StatusCode;
            }
            catch (Exception)
            {
                return HttpStatusCode.BadRequest;
            }
        }
コード例 #7
0
ファイル: SearchManager.cs プロジェクト: happy-ryo/CrouMetro
 public static async Task<SearchEntity> SearchStatusList(string query, long? MaxId, long? SinceId, int? count,
     bool trim, bool entities, UserAccountEntity userAccountEntity)
 {
     if (userAccountEntity.GetAccessToken().Equals("refresh"))
     {
         await Auth.RefreshAccessToken(userAccountEntity);
     }
     string paramer = "?q=" + query;
     if (MaxId.HasValue)
     {
         paramer += "&max_id=" + MaxId.Value;
     }
     if (SinceId.HasValue)
     {
         paramer += "&since_id=" + SinceId.Value;
     }
     if (count.HasValue)
     {
         paramer += "&count=" + count.Value;
     }
     if (trim)
     {
         paramer += "&trim_user="******"&include_entities=" + true;
     }
     var param = new Dictionary<String, String>();
     var theAuthClient = new HttpClient();
     var request = new HttpRequestMessage(HttpMethod.Get, EndPoints.SEARCH_VOICES + paramer);
     request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken());
     try
     {
         HttpResponseMessage response = await theAuthClient.SendAsync(request);
         string responseContent = await response.Content.ReadAsStringAsync();
         responseContent = "[" + responseContent + "]";
         JArray a = JArray.Parse(responseContent);
         var b = (JObject)a[0];
         if (b["statuses"] == null || b["search_metadata"] == null) return null;
         return SearchEntity.ParseStatuses(b["statuses"].ToString(), b["search_metadata"].ToString(),
             userAccountEntity);
     }
     catch (Exception)
     {
         return null;
     }
 }
コード例 #8
0
ファイル: TrendManager.cs プロジェクト: happy-ryo/CrouMetro
 public static async Task<TrendPlaceEntity> GetTrends(int woeId,
     UserAccountEntity userAccountEntity)
 {
     if (userAccountEntity.GetAccessToken().Equals("refresh"))
     {
         await Auth.RefreshAccessToken(userAccountEntity);
     }
     var theAuthClient = new HttpClient();
     var request = new HttpRequestMessage(HttpMethod.Get, string.Format(EndPoints.TrendsPlace, woeId));
     request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken());
     try
     {
         HttpResponseMessage response = await theAuthClient.SendAsync(request);
         string responseContent = await response.Content.ReadAsStringAsync();
         return TrendPlaceEntity.Parse(responseContent);
     }
     catch (Exception)
     {
         return null;
     }
 }
コード例 #9
0
ファイル: StatusManager.cs プロジェクト: happy-ryo/CrouMetro
        public static async Task<HttpStatusCode> DestroyStatus(long statusId, UserAccountEntity userAccountEntity)
        {
            var theAuthClient = new HttpClient();
            var request = new HttpRequestMessage(HttpMethod.Post, string.Format(EndPoints.STATUS_DESTROY, statusId));

            string accessToken = userAccountEntity.GetAccessToken();
            if (accessToken.Equals("refresh"))
            {
                await Auth.RefreshAccessToken(userAccountEntity);
                accessToken = userAccountEntity.GetAccessToken();
            }
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            try
            {
                HttpResponseMessage response = await theAuthClient.SendAsync(request);
                return response.StatusCode;
            }
            catch (Exception)
            {
                return HttpStatusCode.BadRequest;
            }
        }
コード例 #10
0
        public static async Task<bool> CreateFriendship(long? id, UserAccountEntity userAccountEntity)
        {
            var theAuthClient = new HttpClient();
            var request = new HttpRequestMessage(HttpMethod.Post, EndPoints.FRIEND_CREATE + "?user_id=" + id);

            string accessToken = userAccountEntity.GetAccessToken();
            if (accessToken.Equals("refresh"))
            {
                await Auth.RefreshAccessToken(userAccountEntity);
                accessToken = userAccountEntity.GetAccessToken();
            }
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            HttpResponseMessage response;
            try
            {
                response = await theAuthClient.SendAsync(request);
            }
            catch (WebException)
            {
                return false;
            }
            return response.IsSuccessStatusCode;
        }
コード例 #11
0
ファイル: StatusManager.cs プロジェクト: happy-ryo/CrouMetro
 public static async Task<PostEntity> GetPost(bool? trim, bool? entities, long postId,
     UserAccountEntity userAccountEntity)
 {
     string url = string.Format(EndPoints.STATUS_SHOW, postId);
     if (trim != null) url += "&trim_user="******"&include_entities=" + entities;
     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();
     JObject post = JObject.Parse(responseContent);
     return PostEntity.ParsePost(post, userAccountEntity);
 }
コード例 #12
0
ファイル: UserManager.cs プロジェクト: happy-ryo/CrouMetro
        public static async Task<UserEntity> ShowUser(String screenname, long? userId,
            UserAccountEntity userAccountEntity)
        {
            if (userAccountEntity.GetAccessToken().Equals("refresh"))
            {
                await Auth.RefreshAccessToken(userAccountEntity);
            }
            var paramer = string.Empty;

            if (screenname != null)
            {
                paramer += "?screen_name=" + screenname;
            }
            else if (userId != null)
            {
                paramer += "?user_id=" + userId;
            }
            else
            {
                return null;
            }

            var theAuthClient = new HttpClient();
            var request = new HttpRequestMessage(HttpMethod.Get, EndPoints.USERS_SHOW + paramer);
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken());
            try
            {
                HttpResponseMessage response = await theAuthClient.SendAsync(request);
                string responseContent = await response.Content.ReadAsStringAsync();
                return UserEntity.Parse(responseContent, userAccountEntity);
            }
            catch (Exception)
            {
                return null;
            }
        }
コード例 #13
0
ファイル: AlbumManager.cs プロジェクト: happy-ryo/CrouMetro
 public static async Task<List<MediaEntity>> GetAlbumList(int offSet, String screenName,
     UserAccountEntity userAccountEntity)
 {
     if (userAccountEntity.GetAccessToken().Equals("refresh"))
     {
         await Auth.RefreshAccessToken(userAccountEntity);
     }
     var doc = new HtmlDocument();
     var theAuthClient = new HttpClient();
     var requestMsg = new HttpRequestMessage(new HttpMethod("GET"),
         "https://croudia.com/voices/album/" + screenName + "?offset=" + offSet);
     HttpResponseMessage response = await theAuthClient.SendAsync(requestMsg);
     string responseContent = await response.Content.ReadAsStringAsync();
     responseContent = RemoveHtmlComments(responseContent);
     doc.LoadHtml(responseContent);
     var idList = doc.DocumentNode.Descendants("div").Where(node => node.GetAttributeValue("class", "").Contains("contents")).Select(link => ConvertToLong(link.GetAttributeValue("id", ""))).ToList();
     var imageList = doc.DocumentNode.Descendants("img").Where(node => node.GetAttributeValue("src", "").Contains("?large")).Select(link => ExtractId(link.GetAttributeValue("src", ""))).ToList();
     var postList = doc.DocumentNode.Descendants("p").Select(link => link.InnerText).ToList();
     return imageList.Select(t => "https://croudia.com/testimages/download/" + t).Select((url, i) => new MediaEntity(idList[i], url, postList[i], "", i)).ToList();
 }
コード例 #14
0
ファイル: UserManager.cs プロジェクト: happy-ryo/CrouMetro
        public static async Task<List<UserEntity>> LookupFollowerUsers(int cursor, long? userId,
            UserAccountEntity userAccountEntity)
        {
            if (userAccountEntity.GetAccessToken().Equals("refresh"))
            {
                await Auth.RefreshAccessToken(userAccountEntity);
            }
            string paramer = "?cursor=" + cursor + "&user_id=" + userId;
            var theAuthClient = new HttpClient();
            var request = new HttpRequestMessage(HttpMethod.Get, EndPoints.FOLLOWERS_LIST + paramer);
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken());
            try
            {
                HttpResponseMessage response = await theAuthClient.SendAsync(request);

                string responseContent = await response.Content.ReadAsStringAsync();

                responseContent = "[" + responseContent + "]";
                JArray a = JArray.Parse(responseContent);
                var b = (JObject)a[0];
                return UserEntity.ParseUserList(b["users"].ToString(), userAccountEntity);
            }
            catch (Exception)
            {
                return null;
            }
        }
コード例 #15
0
ファイル: StatusManager.cs プロジェクト: happy-ryo/CrouMetro
        public static async Task<bool> UpdateStatusWithMedia(String status, String path, byte[] fileStream,
            long? inReply, bool? isQuote, bool? trim, UserAccountEntity account)
        {
            try
            {
                Debug.WriteLine(EndPoints.STATUS_UPDATE_WITH_MEDIA);

                var theAuthClient = new HttpClient();
                var request = new HttpRequestMessage(HttpMethod.Post, EndPoints.STATUS_UPDATE_WITH_MEDIA);
                var form = new MultipartFormDataContent();
                if (account != null)
                {
                    if (account.GetAccessToken().Equals("refresh"))
                    {
                        await Auth.RefreshAccessToken(account);
                    }
                }
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", account.GetAccessToken());
                form.Add(new StringContent(status), @"""status""");
                Stream stream = new MemoryStream(fileStream);
                var t = new StreamContent(stream);
                const string fileName = "test.jpg";
                var extension = Path.GetExtension(path);
                if (extension != null && extension.Equals(".png"))
                {
                    t.Headers.ContentType = new MediaTypeHeaderValue("image/png");
                }
                else
                {
                    var s = Path.GetExtension(path);
                    if (s != null && (s.Equals(".jpg") || s.Equals(".jpeg")))
                    {
                        t.Headers.ContentType = new MediaTypeHeaderValue("image/jpg");
                    }
                    else
                    {
                        t.Headers.ContentType = new MediaTypeHeaderValue("image/gif");
                    }
                }
                t.Headers.ContentType = new MediaTypeHeaderValue("image/jpg");
                form.Add(t, @"""media""", fileName);
                request.Content = form;
                HttpResponseMessage response = await theAuthClient.SendAsync(request);
                return response.IsSuccessStatusCode;
            }
            catch (WebException e)
            {
                Debug.WriteLine(((HttpWebResponse) e.Response).StatusDescription);
                Debug.WriteLine(new StreamReader(e.Response.GetResponseStream()).ReadToEnd());
                return false;
            }
        }
コード例 #16
0
ファイル: AuthManager.cs プロジェクト: happy-ryo/CrouMetro
 public static void SaveUserCredentials(UserAccountEntity userAccountEntity)
 {
     AppSettings["refreshToken"] = userAccountEntity.GetRefreshToken();
     AppSettings["accessToken"] = userAccountEntity.GetAccessToken();
     AppSettings.Save();
 }
コード例 #17
0
ファイル: AuthManager.cs プロジェクト: happy-ryo/CrouMetro
 public static async Task<bool> VerifyAccount(UserAccountEntity userAccountEntity)
 {
     var theAuthClient = new HttpClient();
     var requestMsg = new HttpRequestMessage(new HttpMethod("GET"), EndPoints.ACCOUNT_VERIFY);
     requestMsg.Headers.Authorization = new AuthenticationHeaderValue("Bearer",
         userAccountEntity.GetAccessToken());
     HttpResponseMessage response;
     try
     {
         response = await theAuthClient.SendAsync(requestMsg);
     }
     catch (WebException)
     {
         return false;
     }
     if (response.StatusCode != HttpStatusCode.OK) return false;
     string responseContent = await response.Content.ReadAsStringAsync();
     userAccountEntity.SetUserEntity(UserEntity.Parse(responseContent, userAccountEntity));
     SaveUserCredentials(userAccountEntity);
     return true;
 }
コード例 #18
0
        public static async Task<SecretMailEntity> GetMail(long postId, UserAccountEntity userAccountEntity)
        {
            string url = string.Format(EndPoints.STATUS_SHOW, postId);

            var theAuthClient = new HttpClient();
            var request = new HttpRequestMessage(HttpMethod.Get, url);
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", userAccountEntity.GetAccessToken());
            try
            {
                HttpResponseMessage response = await theAuthClient.SendAsync(request);
                string responseContent = await response.Content.ReadAsStringAsync();
                JObject post = JObject.Parse(responseContent);
                return SecretMailEntity.ParseMail(post, userAccountEntity);
            }
            catch (Exception)
            {
                return null;
            }
        }
コード例 #19
0
ファイル: UserManager.cs プロジェクト: happy-ryo/CrouMetro
 public static async Task<bool> ChangeUserProfileImage(String filePath, byte[] fileStream,
     UserAccountEntity userAccountEntity)
 {
     try
     {
         var theAuthClient = new HttpClient();
         var request = new HttpRequestMessage(HttpMethod.Post, EndPoints.ACCOUNT_UPDATE_IMAGE);
         var form = new MultipartFormDataContent();
         if (userAccountEntity != null)
         {
             if (userAccountEntity.GetAccessToken().Equals("refresh"))
             {
                 await Auth.RefreshAccessToken(userAccountEntity);
             }
         }
         if (userAccountEntity != null)
             request.Headers.Authorization = new AuthenticationHeaderValue("Bearer",
                 userAccountEntity.GetAccessToken());
         Stream stream = new MemoryStream(fileStream);
         var t = new StreamContent(stream);
         const string fileName = "testtesttesttest.jpg";
         if (Path.GetExtension(fileName).Equals(".png"))
         {
             t.Headers.ContentType = new MediaTypeHeaderValue("image/png");
         }
         else if (Path.GetExtension(fileName).Equals(".jpg") || Path.GetExtension(fileName).Equals(".jpeg"))
         {
             t.Headers.ContentType = new MediaTypeHeaderValue("image/jpg");
         }
         else
         {
             t.Headers.ContentType = new MediaTypeHeaderValue("image/gif");
         }
         form.Add(t, @"""image""", fileName);
         request.Content = form;
         HttpResponseMessage response = await theAuthClient.SendAsync(request);
         return response.IsSuccessStatusCode;
     }
     catch (WebException e)
     {
         return false;
     }
 }
コード例 #20
0
        public static async Task<List<PostEntity>> GetConversation(PostEntity startingPost,
            UserAccountEntity userAccountEntity)
        {
            if (userAccountEntity.GetAccessToken().Equals("refresh"))
            {
                await Auth.RefreshAccessToken(userAccountEntity);
            }
            var conversationList = new List<PostEntity>();
            conversationList.Add(startingPost);
            if (startingPost.InReplyToStatusID == 0) return conversationList;
            PostEntity nextEntry =
                await StatusManager.GetPost(false, false, startingPost.InReplyToStatusID, userAccountEntity);
            conversationList.Add(nextEntry);
            while (nextEntry.InReplyToStatusID != 0)
            {
                nextEntry =
                    await StatusManager.GetPost(false, false, nextEntry.InReplyToStatusID, userAccountEntity);
                conversationList.Add(nextEntry);
            }

            return conversationList;
        }