OSDN Git Service

TwitterDataModel.Status を TwitterStatus に移行
authorKimura Youichi <kim.upsilon@bucyou.net>
Mon, 5 May 2014 14:10:47 +0000 (23:10 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Mon, 5 May 2014 17:20:37 +0000 (02:20 +0900)
OpenTween/Api/GeoJson.cs [new file with mode: 0644]
OpenTween/Api/TwitterDataModel.cs
OpenTween/Api/TwitterStatus.cs [new file with mode: 0644]
OpenTween/Api/TwitterUser.cs
OpenTween/OpenTween.csproj
OpenTween/Twitter.cs
OpenTween/UserInfoDialog.cs

diff --git a/OpenTween/Api/GeoJson.cs b/OpenTween/Api/GeoJson.cs
new file mode 100644 (file)
index 0000000..6b9e35c
--- /dev/null
@@ -0,0 +1,49 @@
+// 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.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpenTween.Api
+{
+    [DataContract]
+    public abstract class GeoJson
+    {
+        [DataMember(Name = "type")]
+        public string Type { get; set; }
+    }
+
+    [DataContract]
+    public class GeoJsonPoint : GeoJson
+    {
+        [DataMember(Name = "coordinates")]
+        public double[] Coordinates { get; set; }
+
+        public GeoJsonPoint()
+        {
+            this.Type = "Point";
+        }
+    }
+}
index 421db2c..4825a37 100644 (file)
@@ -42,13 +42,6 @@ namespace OpenTween.Api
         }
 
         [DataContract]
-        public class Coordinates
-        {
-            [DataMember(Name = "type", IsRequired = false)] public string Type;
-            [DataMember(Name = "coordinates", IsRequired = false)] public double[] coordinates = new double[2];
-        }
-
-        [DataContract]
         public class BoundingBox
         {
             [DataMember(Name = "type", IsRequired = false)] public string Type;
@@ -77,52 +70,7 @@ namespace OpenTween.Api
         }
 
         [DataContract]
-        public class RetweetedStatus
-        {
-            [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 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;
-            [DataMember(Name = "favorited")] public bool Favorited;
-            [DataMember(Name = "truncated")] public bool? Truncated;
-            [DataMember(Name = "id")] public Int64 Id;
-            [DataMember(Name = "annotations", IsRequired = false)] public Annotations Annotations;
-            [DataMember(Name = "place", IsRequired = false)] public Place Place;
-            [DataMember(Name = "in_reply_to_status_id")] public long? InReplyToStatusId;
-            [DataMember(Name = "text")] public string Text;
-            [DataMember(Name = "entities", IsRequired = false)] public TwitterEntities Entities;
-        }
-
-        [DataContract]
-        public class Status
-        {
-            [DataMember(Name = "in_reply_to_status_id_str")] public string InReplyToStatusIdStr;
-            [DataMember(Name = "contributors", IsRequired = false)] public int[] Contributors;
-            [DataMember(Name = "in_reply_to_screen_name")] public string InReplyToScreenName;
-            [DataMember(Name = "in_reply_to_status_id")] public long? InReplyToStatusId;
-            [DataMember(Name = "in_reply_to_user_id_str")] public string InReplyToUserIdStr;
-            [DataMember(Name = "retweet_count")] public int RetweetCount;
-            [DataMember(Name = "created_at")] public string CreatedAt;
-            [DataMember(Name = "retweeted")] public bool Retweeted;
-            [DataMember(Name = "in_reply_to_user_id")] public long? InReplyToUserId;
-            [DataMember(Name = "source")] public string Source;
-            [DataMember(Name = "id_str")] public string IdStr;
-            [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 TwitterUser User;
-            [DataMember(Name = "retweeted_status", IsRequired = false)] public RetweetedStatus RetweetedStatus;
-            [DataMember(Name = "id")] public Int64 Id;
-            [DataMember(Name = "favorited")] public bool Favorited;
-            [DataMember(Name = "text")] public string Text;
-            [DataMember(Name = "entities", IsRequired = false)] public TwitterEntities Entities;
-        }
-
-        [DataContract]
-        public class TargetObject : Status
+        public class TargetObject : TwitterStatus
         {
             [DataMember(Name = "mode")] public string Mode;
             [DataMember(Name = "description")] public string Description;
@@ -221,7 +169,7 @@ namespace OpenTween.Api
             [DataMember(Name = "annotations")] public Annotations Annotations;
             [DataMember(Name = "kind")] public string Kind;
             [DataMember(Name = "score")] public double Score;
-            [DataMember(Name = "value")] public Status Status;
+            [DataMember(Name = "value")] public TwitterStatus Status;
         }
 
         [DataContract]
@@ -391,7 +339,7 @@ namespace OpenTween.Api
         [DataContract]
         public class SearchResult
         {
-            [DataMember(Name = "statuses")] public List<Status> Statuses;
+            [DataMember(Name = "statuses")] public List<TwitterStatus> Statuses;
             [DataMember(Name = "search_metadata")] public SearchMetadata SearchMetadata;
         }
 
diff --git a/OpenTween/Api/TwitterStatus.cs b/OpenTween/Api/TwitterStatus.cs
new file mode 100644 (file)
index 0000000..017da2c
--- /dev/null
@@ -0,0 +1,142 @@
+// 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.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OpenTween.Api
+{
+    // 参照: https://dev.twitter.com/docs/platform-objects/tweets
+
+    [DataContract]
+    public class TwitterStatus
+    {
+        [DataMember(Name = "contributors", IsRequired = false)]
+        public TwitterStatus.Contributor[] Contributors { get; set; } // Nullable
+
+        [DataContract]
+        public class Contributor
+        {
+            [DataMember(Name = "id")]
+            public long Id { get; set; }
+
+            [DataMember(Name = "id_str")]
+            public string IdStr { get; set; }
+
+            [DataMember(Name = "screen_name")]
+            public string ScreenName { get; set; }
+        }
+
+        [DataMember(Name = "coordinates", IsRequired = false)]
+        public GeoJsonPoint Coordinates { get; set; }
+
+        [DataMember(Name = "created_at")]
+        public string CreatedAt { get; set; }
+
+        [DataMember(Name = "entities")]
+        public TwitterEntities Entities { get; set; }
+
+        [DataMember(Name = "favorite_count")]
+        public int? FavoriteCount { get; set; }
+
+        [DataMember(Name = "favorited")]
+        public bool? Favorited { get; set; }
+
+        [DataMember(Name = "filter_level")]
+        public string FilterLevel { get; set; }
+
+        [DataMember(Name = "id")]
+        public long Id { get; set; }
+
+        [DataMember(Name = "id_str")]
+        public string IdStr { get; set; }
+
+        [DataMember(Name = "in_reply_to_screen_name")]
+        public string InReplyToScreenName { get; set; } // Nullable
+
+        [DataMember(Name = "in_reply_to_status_id")]
+        public long? InReplyToStatusId { get; set; }
+
+        [DataMember(Name = "in_reply_to_status_id_str")]
+        public string InReplyToStatusIdStr { get; set; } // Nullable
+
+        [DataMember(Name = "in_reply_to_user_id")]
+        public long? InReplyToUserId { get; set; }
+
+        [DataMember(Name = "in_reply_to_user_id_str")]
+        public string InReplyToUserIdStr { get; set; } // Nullable
+
+        [DataMember(Name = "lang")]
+        public string Lang { get; set; } // Nullable
+
+        [DataMember(Name = "place", IsRequired = false)]
+        public TwitterDataModel.Place Place { get; set; }
+
+        [DataMember(Name = "possibly_sensitive")]
+        public bool? PossiblySensitive { get; set; }
+
+        [DataMember(Name = "retweet_count")]
+        public int RetweetCount { get; set; }
+
+        [DataMember(Name = "retweeted")]
+        public bool Retweeted { get; set; }
+
+        [DataMember(Name = "retweeted_status", IsRequired = false)]
+        public TwitterStatus RetweetedStatus { get; set; }
+
+        [DataMember(Name = "source")]
+        public string Source { get; set; }
+
+        [DataMember(Name = "text")]
+        public string Text { get; set; }
+
+        [DataMember(Name = "truncated")]
+        public bool Truncated { get; set; }
+
+        [DataMember(Name = "user")]
+        public TwitterUser User { get; set; }
+
+        [DataMember(Name = "withheld_copyright")]
+        public bool WithheldCopyright { get; set; }
+
+        [DataMember(Name = "withheld_in_countries")]
+        public string[] WithheldInCountries { get; set; }
+
+        [DataMember(Name = "withheld_scope")]
+        public string WithheldScope { get; set; }
+
+        /// <exception cref="SerializationException"/>
+        public static TwitterStatus ParseJson(string json)
+        {
+            return MyCommon.CreateDataFromJson<TwitterStatus>(json);
+        }
+
+        /// <exception cref="SerializationException"/>
+        public static TwitterStatus[] ParseJsonArray(string json)
+        {
+            return MyCommon.CreateDataFromJson<TwitterStatus[]>(json);
+        }
+    }
+}
index 395ef0a..941144b 100644 (file)
@@ -133,7 +133,7 @@ namespace OpenTween.Api
         public bool ShowAllInlineMedia { get; set; }
 
         [DataMember(Name = "status", IsRequired = false)]
-        public TwitterDataModel.Status Status { get; set; } // Nullable
+        public TwitterStatus Status { get; set; } // Nullable
 
         [DataMember(Name = "statuses_count")]
         public int StatusesCount { get; set; }
index f1032aa..6125414 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Api\ApiLimit.cs" />
+    <Compile Include="Api\GeoJson.cs" />
     <Compile Include="Api\TwitterConfiguration.cs" />
     <Compile Include="Api\TwitterEntity.cs" />
     <Compile Include="Api\TwitterList.cs" />
+    <Compile Include="Api\TwitterStatus.cs" />
     <Compile Include="Api\TwitterUser.cs" />
     <Compile Include="Api\TwitterApiAccessLevel.cs" />
     <Compile Include="Api\TwitterApiStatus.cs" />
index c12add0..a91bb38 100644 (file)
@@ -429,7 +429,7 @@ namespace OpenTween
         }
 
         static private PostInfo _prev = new PostInfo("", "", "", "");
-        private bool IsPostRestricted(TwitterDataModel.Status status)
+        private bool IsPostRestricted(TwitterStatus status)
         {
             var _current = new PostInfo("", "", "", "");
 
@@ -485,10 +485,10 @@ namespace OpenTween
             var err = this.CheckStatusCode(res, content);
             if (err != null) return err;
 
-            TwitterDataModel.Status status;
+            TwitterStatus status;
             try
             {
-                status = MyCommon.CreateDataFromJson<TwitterDataModel.Status>(content);
+                status = TwitterStatus.ParseJson(content);
             }
             catch(SerializationException ex)
             {
@@ -536,10 +536,10 @@ namespace OpenTween
             var err = this.CheckStatusCode(res, content);
             if (err != null) return err;
 
-            TwitterDataModel.Status status;
+            TwitterStatus status;
             try
             {
-                status = MyCommon.CreateDataFromJson<TwitterDataModel.Status>(content);
+                status = TwitterStatus.ParseJson(content);
             }
             catch(SerializationException ex)
             {
@@ -665,10 +665,10 @@ namespace OpenTween
             var err = this.CheckStatusCode(res, content);
             if (err != null) return err;
 
-            TwitterDataModel.Status status;
+            TwitterStatus status;
             try
             {
-                status = MyCommon.CreateDataFromJson<TwitterDataModel.Status>(content);
+                status = TwitterStatus.ParseJson(content);
             }
             catch(SerializationException ex)
             {
@@ -931,10 +931,10 @@ namespace OpenTween
             var err = this.CheckStatusCode(res, content);
             if (err != null) return err;
 
-            TwitterDataModel.Status status;
+            TwitterStatus status;
             try
             {
-                status = MyCommon.CreateDataFromJson<TwitterDataModel.Status>(content);
+                status = TwitterStatus.ParseJson(content);
             }
             catch (SerializationException ex)
             {
@@ -992,10 +992,10 @@ namespace OpenTween
             err = this.CheckStatusCode(res, content);
             if (err != null) return err;
 
-            TwitterDataModel.Status status;
+            TwitterStatus status;
             try
             {
-                status = MyCommon.CreateDataFromJson<TwitterDataModel.Status>(content);
+                status = TwitterStatus.ParseJson(content);
             }
             catch (SerializationException ex)
             {
@@ -1007,7 +1007,7 @@ namespace OpenTween
                 MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content);
                 return "Err:Invalid Json!";
             }
-            if (status.Favorited)
+            if (status.Favorited == true)
             {
                 return "";
             }
@@ -1424,10 +1424,10 @@ namespace OpenTween
             var err = this.CheckStatusCode(res, content);
             if (err != null) return err;
 
-            List<TwitterDataModel.Status> items;
+            TwitterStatus[] items;
             try
             {
-                items = MyCommon.CreateDataFromJson<List<TwitterDataModel.Status>>(content);
+                items = TwitterStatus.ParseJsonArray(content);
             }
             catch(SerializationException ex)
             {
@@ -1480,10 +1480,10 @@ namespace OpenTween
             var err = this.CheckStatusCode(res, content);
             if (err != null) return err;
 
-            TwitterDataModel.Status status;
+            TwitterStatus status;
             try
             {
-                status = MyCommon.CreateDataFromJson<TwitterDataModel.Status>(content);
+                status = TwitterStatus.ParseJson(content);
             }
             catch(SerializationException ex)
             {
@@ -1522,7 +1522,7 @@ namespace OpenTween
             return r;
         }
 
-        private PostClass CreatePostsFromStatusData(TwitterDataModel.Status status)
+        private PostClass CreatePostsFromStatusData(TwitterStatus status)
         {
             var post = new PostClass();
             TwitterEntities entities;
@@ -1550,7 +1550,7 @@ namespace OpenTween
                 var tc = TabInformations.GetInstance().GetTabByType(MyCommon.TabUsageType.Favorites);
                 post.IsFav = tc.Contains(retweeted.Id);
 
-                if (retweeted.Coordinates != null) post.PostGeo = new PostClass.StatusGeo { Lng = retweeted.Coordinates.coordinates[0], Lat = retweeted.Coordinates.coordinates[1] };
+                if (retweeted.Coordinates != null) post.PostGeo = new PostClass.StatusGeo { Lng = retweeted.Coordinates.Coordinates[0], Lat = retweeted.Coordinates.Coordinates[1] };
 
                 //以下、ユーザー情報
                 var user = retweeted.User;
@@ -1580,7 +1580,7 @@ namespace OpenTween
                 post.InReplyToUser = status.InReplyToScreenName;
                 post.InReplyToUserId = status.InReplyToUserId;
 
-                if (status.Coordinates != null) post.PostGeo = new PostClass.StatusGeo { Lng = status.Coordinates.coordinates[0], Lat = status.Coordinates.coordinates[1] };
+                if (status.Coordinates != null) post.PostGeo = new PostClass.StatusGeo { Lng = status.Coordinates.Coordinates[0], Lat = status.Coordinates.Coordinates[1] };
 
                 //以下、ユーザー情報
                 var user = status.User;
@@ -1627,10 +1627,10 @@ namespace OpenTween
 
         private string CreatePostsFromJson(string content, MyCommon.WORKERTYPE gType, TabClass tab, bool read, int count, ref long minimumId)
         {
-            List<TwitterDataModel.Status> items;
+            TwitterStatus[] items;
             try
             {
-                items = MyCommon.CreateDataFromJson<List<TwitterDataModel.Status>>(content);
+                items = TwitterStatus.ParseJsonArray(content);
             }
             catch(SerializationException ex)
             {
@@ -2170,10 +2170,10 @@ namespace OpenTween
             var err = this.CheckStatusCode(res, content);
             if (err != null) return err;
 
-            List<TwitterDataModel.Status> item;
+            TwitterStatus[] item;
             try
             {
-                item = MyCommon.CreateDataFromJson<List<TwitterDataModel.Status>>(content);
+                item = TwitterStatus.ParseJsonArray(content);
             }
             catch(SerializationException ex)
             {
index 078f518..997ae9a 100644 (file)
@@ -197,7 +197,7 @@ namespace OpenTween
             }
         }
 
-        private async Task SetRecentStatusAsync(TwitterDataModel.Status status)
+        private async Task SetRecentStatusAsync(TwitterStatus status)
         {
             var atlist = new List<string>();