OSDN Git Service

TwitterDataModel.User を TwitterUser に移行
authorKimura Youichi <kim.upsilon@bucyou.net>
Mon, 5 May 2014 10:11:24 +0000 (19:11 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Mon, 5 May 2014 17:20:23 +0000 (02:20 +0900)
OpenTween/Api/TwitterDataModel.cs
OpenTween/Api/TwitterUser.cs [new file with mode: 0644]
OpenTween/OpenTween.csproj
OpenTween/Tween.cs
OpenTween/Twitter.cs
OpenTween/UserInfo.cs
OpenTween/UserInfoDialog.cs

index 750074e..c32a222 100644 (file)
@@ -28,6 +28,7 @@
 using System;
 using System.Runtime.Serialization;
 using System.Collections.Generic;
+using OpenTween.Api;
 
 namespace OpenTween.Api
 {
@@ -105,46 +106,6 @@ namespace OpenTween.Api
         }
 
         [DataContract]
-        public class User
-        {
-            [DataMember(Name = "statuses_count")] public int StatusesCount;
-            [DataMember(Name = "profile_sidebar_fill_color")] public string ProfileSidebarFillColor;
-            [DataMember(Name = "show_all_inline_media")] public bool ShowAllInlineMedia;
-            [DataMember(Name = "profile_use_background_image")] public bool ProfileUseBackgroundImage;
-            [DataMember(Name = "contributors_enabled")] public bool ContributorsEnabled;
-            [DataMember(Name = "profile_sidebar_border_color")] public string ProfileSidebarBorderColor;
-            [DataMember(Name = "location")] public string Location;
-            [DataMember(Name = "geo_enabled")] public bool GeoEnabled;
-            [DataMember(Name = "description")] public string Description;
-            [DataMember(Name = "friends_count")] public int FriendsCount;
-            [DataMember(Name = "verified")] public bool Verified;
-            [DataMember(Name = "favourites_count")] public int FavouritesCount;
-            [DataMember(Name = "created_at")] public string CreatedAt;
-            [DataMember(Name = "profile_background_color")] public string ProfileBackgroundColor;
-            [DataMember(Name = "follow_request_sent")] public string FollowRequestSent;
-            [DataMember(Name = "time_zone")] public string TimeZone;
-            [DataMember(Name = "followers_count")] public int FollowersCount;
-            [DataMember(Name = "url")] public string Url;
-            [DataMember(Name = "profile_image_url_https")] public string ProfileImageUrlHttps;
-            [DataMember(Name = "notifications")] public string Notifications;
-            [DataMember(Name = "profile_text_color")] public string ProfileTextColor;
-            [DataMember(Name = "protected")] public bool Protected;
-            [DataMember(Name = "id_str")] public string IdStr;
-            [DataMember(Name = "lang")] public string Lang;
-            [DataMember(Name = "profile_background_image_url_https")] public string ProfileBackgroundImageUrlHttps;
-            [DataMember(Name = "screen_name")] public string ScreenName;
-            [DataMember(Name = "name")] public string Name;
-            [DataMember(Name = "following")] public bool? Following;
-            [DataMember(Name = "profile_link_color")] public string ProfileLinkColor;
-            [DataMember(Name = "id")] public Int64 Id;
-            [DataMember(Name = "listed_count")] public int ListedCount;
-            [DataMember(Name = "profile_background_tile")] public bool ProfileBackgroundTile;
-            [DataMember(Name = "utc_offset")] public int? UtcOffset;
-            [DataMember(Name = "place", IsRequired = false)] public Place Place;
-            [DataMember(Name = "status", IsRequired = false)] public Status Status;
-        }
-
-        [DataContract]
         public class Coordinates
         {
             [DataMember(Name = "type", IsRequired = false)] public string Type;
@@ -185,7 +146,7 @@ namespace OpenTween.Api
             [DataMember(Name = "coordinates", IsRequired = false)] public Coordinates Coordinates;
             [DataMember(Name = "in_reply_to_user_id")] public long? InReplyToUserId;
             [DataMember(Name = "source")] public string Source;
-            [DataMember(Name = "user")] public User User;
+            [DataMember(Name = "user")] public TwitterUser User;
             [DataMember(Name = "in_reply_to_screen_name")] public string InReplyToScreenName;
             [DataMember(Name = "created_at")] public string CreatedAt;
             [DataMember(Name = "contributors")] public int[] Contributors;
@@ -216,7 +177,7 @@ namespace OpenTween.Api
             [DataMember(Name = "coordinates", IsRequired = false)] public Coordinates Coordinates;
             [DataMember(Name = "truncated")] public string Truncated;
             [DataMember(Name = "place", IsRequired = false)] public Place Place;
-            [DataMember(Name = "user")] public User User;
+            [DataMember(Name = "user")] public TwitterUser User;
             [DataMember(Name = "retweeted_status", IsRequired = false)] public RetweetedStatus RetweetedStatus;
             [DataMember(Name = "id")] public Int64 Id;
             [DataMember(Name = "favorited")] public bool Favorited;
@@ -244,9 +205,9 @@ namespace OpenTween.Api
             [DataMember(Name = "created_at")] public string CreatedAt;
             [DataMember(Name = "sender_id")] public Int64 SenderId;
             [DataMember(Name = "sender_screen_name")] public string SenderScreenName;
-            [DataMember(Name = "sender")] public User Sender;
+            [DataMember(Name = "sender")] public TwitterUser Sender;
             [DataMember(Name = "id_str")] public string IdStr;
-            [DataMember(Name = "recipient")] public User Recipient;
+            [DataMember(Name = "recipient")] public TwitterUser Recipient;
             [DataMember(Name = "recipient_screen_name")] public string RecipientScreenName;
             [DataMember(Name = "recipient_id")] public Int64 RecipientId;
             [DataMember(Name = "id")] public Int64 Id;
@@ -311,11 +272,11 @@ namespace OpenTween.Api
         [DataContract]
         public class EventData
         {
-            [DataMember(Name = "target")] public User Target;
+            [DataMember(Name = "target")] public TwitterUser Target;
             [DataMember(Name = "target_object", IsRequired = false)] public TargetObject TargetObject;
             [DataMember(Name = "created_at")] public string CreatedAt;
             [DataMember(Name = "event")] public string Event;
-            [DataMember(Name = "source")] public User Source;
+            [DataMember(Name = "source")] public TwitterUser Source;
         }
 
         [DataContract]
@@ -392,7 +353,7 @@ namespace OpenTween.Api
             [DataMember(Name = "member_count")] public int MemberCount;
             [DataMember(Name = "slug")] public string Slug;
             [DataMember(Name = "full_name")] public string FullName;
-            [DataMember(Name = "user")] public User User;
+            [DataMember(Name = "user")] public TwitterUser User;
             [DataMember(Name = "following")] public bool Following;
             [DataMember(Name = "subscriber_count")] public int SubscriberCount;
             [DataMember(Name = "description")] public string Description;
@@ -411,7 +372,7 @@ namespace OpenTween.Api
         [DataContract]
         public class Users
         {
-            [DataMember(Name = "users")] public User[] users;
+            [DataMember(Name = "users")] public TwitterUser[] users;
             [DataMember(Name = "next_cursor")] public long NextCursor;
             [DataMember(Name = "previous_cursor")] public long PreviousCursor;
         }
diff --git a/OpenTween/Api/TwitterUser.cs b/OpenTween/Api/TwitterUser.cs
new file mode 100644 (file)
index 0000000..395ef0a
--- /dev/null
@@ -0,0 +1,159 @@
+// OpenTween - Client of Twitter
+// Copyright (c) 2014 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpenTween.Api
+{
+    // 参照: https://dev.twitter.com/docs/platform-objects/users
+
+    [DataContract]
+    public class TwitterUser
+    {
+        [DataMember(Name = "contributors_enabled")]
+        public bool ContributorsEnabled { get; set; }
+
+        [DataMember(Name = "created_at")]
+        public string CreatedAt { get; set; }
+
+        [DataMember(Name = "description")]
+        public string Description { get; set; } // Nullable
+
+        [DataMember(Name = "entities", IsRequired = false)]
+        public TwitterUser.TwitterUserEntity Entities { get; set; }
+
+        [DataContract]
+        public class TwitterUserEntity
+        {
+            [DataMember(Name = "url", IsRequired = false)]
+            public TwitterEntities Url { get; set; }
+
+            [DataMember(Name = "description", IsRequired = false)]
+            public TwitterEntities Description { get; set; }
+        }
+
+        [DataMember(Name = "favourites_count")]
+        public int FavouritesCount { get; set; }
+
+        [DataMember(Name = "follow_request_sent")]
+        public bool? FollowRequestSent { get; set; }
+
+        [DataMember(Name = "following")]
+        public bool? Following { get; set; }
+
+        [DataMember(Name = "followers_count")]
+        public int FollowersCount { get; set; }
+
+        [DataMember(Name = "friends_count")]
+        public int FriendsCount { get; set; }
+
+        [DataMember(Name = "geo_enabled")]
+        public bool GeoEnabled { get; set; }
+
+        [DataMember(Name = "id")]
+        public long Id { get; set; }
+
+        [DataMember(Name = "id_str")]
+        public string IdStr { get; set; }
+
+        [DataMember(Name = "lang")]
+        public string Lang { get; set; }
+
+        [DataMember(Name = "listed_count")]
+        public int ListedCount { get; set; }
+
+        [DataMember(Name = "location")]
+        public string Location { get; set; } // Nullable
+
+        [DataMember(Name = "name")]
+        public string Name { get; set; }
+
+        [Obsolete]
+        [DataMember(Name = "notifications")]
+        public bool? Notifications { get; set; } // Nullable
+
+        [DataMember(Name = "profile_background_color")]
+        public string ProfileBackgroundColor { get; set; }
+
+        [DataMember(Name = "profile_background_image_url_https")]
+        public string ProfileBackgroundImageUrlHttps { get; set; }
+
+        [DataMember(Name = "profile_background_tile")]
+        public bool ProfileBackgroundTile { get; set; }
+
+        [DataMember(Name = "profile_image_url_https")]
+        public string ProfileImageUrlHttps { get; set; }
+
+        [DataMember(Name = "profile_link_color")]
+        public string ProfileLinkColor { get; set; }
+
+        [DataMember(Name = "profile_sidebar_border_color")]
+        public string ProfileSidebarBorderColor { get; set; }
+
+        [DataMember(Name = "profile_sidebar_fill_color")]
+        public string ProfileSidebarFillColor { get; set; }
+
+        [DataMember(Name = "profile_text_color")]
+        public string ProfileTextColor { get; set; }
+
+        [DataMember(Name = "profile_use_background_image")]
+        public bool ProfileUseBackgroundImage { get; set; }
+
+        [DataMember(Name = "protected")]
+        public bool Protected { get; set; }
+
+        [DataMember(Name = "screen_name")]
+        public string ScreenName { get; set; }
+
+        [DataMember(Name = "show_all_inline_media")]
+        public bool ShowAllInlineMedia { get; set; }
+
+        [DataMember(Name = "status", IsRequired = false)]
+        public TwitterDataModel.Status Status { get; set; } // Nullable
+
+        [DataMember(Name = "statuses_count")]
+        public int StatusesCount { get; set; }
+
+        [DataMember(Name = "time_zone")]
+        public string TimeZone { get; set; } // Nullable
+
+        [DataMember(Name = "url")]
+        public string Url { get; set; } // Nullable
+
+        [DataMember(Name = "utc_offset")]
+        public int? UtcOffset { get; set; }
+
+        [DataMember(Name = "verified")]
+        public bool Verified { get; set; }
+
+        /// <exception cref="SerializationException"/>
+        public static TwitterUser ParseJson(string json)
+        {
+            return MyCommon.CreateDataFromJson<TwitterUser>(json);
+        }
+    }
+}
index 6f691a8..d75f431 100644 (file)
@@ -62,6 +62,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Api\ApiLimit.cs" />
+    <Compile Include="Api\TwitterUser.cs" />
     <Compile Include="Api\TwitterApiAccessLevel.cs" />
     <Compile Include="Api\TwitterApiStatus.cs" />
     <Compile Include="ApplicationEvents.cs">
index a7f3705..8c473fd 100644 (file)
@@ -12002,7 +12002,7 @@ namespace OpenTween
         {
             public Twitter tw;
             public string id;
-            public TwitterDataModel.User user;
+            public TwitterUser user;
         }
 
         private void GetUserInfo_DoWork(object sender, DoWorkEventArgs e)
@@ -12013,7 +12013,7 @@ namespace OpenTween
 
         private void doShowUserStatus(string id, bool ShowInputDialog)
         {
-            TwitterDataModel.User user = null;
+            TwitterUser user = null;
             GetUserInfoArgs args = new GetUserInfoArgs();
             if (ShowInputDialog)
             {
@@ -12068,7 +12068,7 @@ namespace OpenTween
             }
         }
 
-        private void doShowUserStatus(TwitterDataModel.User user)
+        private void doShowUserStatus(TwitterUser user)
         {
             using (var userinfo = new UserInfoDialog())
             {
index cddd436..a86b36a 100644 (file)
@@ -268,10 +268,10 @@ namespace OpenTween
             if (res == HttpStatusCode.OK)
             {
                 Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid;
-                TwitterDataModel.User user;
+                TwitterUser user;
                 try
                 {
-                    user = MyCommon.CreateDataFromJson<TwitterDataModel.User>(content);
+                    user = TwitterUser.ParseJson(content);
                 }
                 catch(SerializationException)
                 {
@@ -872,7 +872,7 @@ namespace OpenTween
             }
         }
 
-        public string GetUserInfo(string screenName, ref TwitterDataModel.User user)
+        public string GetUserInfo(string screenName, ref TwitterUser user)
         {
             if (MyCommon._endingFlag) return "";
 
@@ -896,7 +896,7 @@ namespace OpenTween
 
             try
             {
-                user = MyCommon.CreateDataFromJson<TwitterDataModel.User>(content);
+                user = TwitterUser.ParseJson(content);
             }
             catch (SerializationException ex)
             {
@@ -1044,7 +1044,7 @@ namespace OpenTween
             return this.CheckStatusCode(res, content) ?? "";
         }
 
-        public TwitterDataModel.User PostUpdateProfile(string name, string url, string location, string description)
+        public TwitterUser PostUpdateProfile(string name, string url, string location, string description)
         {
             if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid)
                 throw new WebApiException("AccountState invalid");
@@ -1066,7 +1066,7 @@ namespace OpenTween
 
             try
             {
-                return MyCommon.CreateDataFromJson<TwitterDataModel.User>(content);
+                return TwitterUser.ParseJson(content);
             }
             catch (SerializationException e)
             {
@@ -2020,7 +2020,7 @@ namespace OpenTween
                     post.IsFav = false;
 
                     //以下、ユーザー情報
-                    TwitterDataModel.User user;
+                    TwitterUser user;
                     if (gType == MyCommon.WORKERTYPE.UserStream)
                     {
                         if (twCon.AuthenticatedUsername.Equals(message.Recipient.ScreenName, StringComparison.CurrentCultureIgnoreCase))
@@ -2645,9 +2645,9 @@ namespace OpenTween
             try
             {
                 var users = MyCommon.CreateDataFromJson<TwitterDataModel.Users>(content);
-                Array.ForEach<TwitterDataModel.User>(
+                Array.ForEach<TwitterUser>(
                     users.users,
-                    new Action<TwitterDataModel.User>(u => lists.Add(new UserInfo(u))));
+                    u => lists.Add(new UserInfo(u)));
                 cursor = users.NextCursor;
                 return "";
             }
@@ -2728,7 +2728,7 @@ namespace OpenTween
 
             try
             {
-                var u = MyCommon.CreateDataFromJson<TwitterDataModel.User>(content);
+                var u = TwitterUser.ParseJson(content);
                 value = true;
                 return "";
             }
index 8a5777b..9c63522 100644 (file)
@@ -36,7 +36,7 @@ namespace OpenTween
         {
         }
 
-        public UserInfo(TwitterDataModel.User user)
+        public UserInfo(TwitterUser user)
         {
             this.Id = user.Id;
             this.Name = WebUtility.HtmlDecode(user.Name).Trim();
index 22e6c77..078f518 100644 (file)
@@ -43,8 +43,8 @@ namespace OpenTween
 {
     public partial class UserInfoDialog : OTBaseForm
     {
-        private TwitterDataModel.User _displayUser;
-        public TwitterDataModel.User DisplayUser
+        private TwitterUser _displayUser;
+        public TwitterUser DisplayUser
         {
             get { return this._displayUser; }
             set
@@ -541,7 +541,7 @@ namespace OpenTween
             {
                 var user = await Task.Run(() =>
                 {
-                    TwitterDataModel.User result = null;
+                    TwitterUser result = null;
 
                     var err = this.Twitter.GetUserInfo(this._displayUser.ScreenName, ref result);
                     if (!string.IsNullOrEmpty(err))