OSDN Git Service

TwitterApi.EscapeJsonStringメソッドをJsonUtilsクラスへ移動
[opentween/open-tween.git] / OpenTween / Api / DataModel / TwitterStreamMessage.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2018 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
10 // any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 // for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
21
22 using System.Runtime.Serialization;
23
24 namespace OpenTween.Api.DataModel
25 {
26     public interface ITwitterStreamMessage
27     {
28     }
29
30     public class StreamMessageStatus : ITwitterStreamMessage
31     {
32         public TwitterStatusCompat Status { get; }
33
34         public StreamMessageStatus(TwitterStatusCompat status)
35             => this.Status = status;
36
37         public static StreamMessageStatus ParseJson(string json)
38             => new StreamMessageStatus(TwitterStatusCompat.ParseJson(json));
39     }
40
41     public class StreamMessageEvent : ITwitterStreamMessage
42     {
43         public TwitterStreamEvent Event { get; }
44         public string Json { get; }
45
46         public StreamMessageEvent(TwitterStreamEvent eventData, string json)
47         {
48             this.Event = eventData;
49             this.Json = json;
50         }
51
52         public TwitterStreamEvent<T> ParseTargetObjectAs<T>()
53             => TwitterStreamEvent<T>.ParseJson(this.Json);
54
55         public static StreamMessageEvent ParseJson(string json)
56             => new StreamMessageEvent(TwitterStreamEvent.ParseJson(json), json);
57     }
58
59     [DataContract]
60     public class StreamMessageDirectMessage : ITwitterStreamMessage
61     {
62         [DataMember(Name = "direct_message")]
63         public TwitterDirectMessage DirectMessage { get; set; }
64
65         public static StreamMessageDirectMessage ParseJson(string json)
66             => MyCommon.CreateDataFromJson<StreamMessageDirectMessage>(json);
67     }
68
69     [DataContract]
70     public class StreamMessageDelete : ITwitterStreamMessage
71     {
72         [DataContract]
73         public class DeletedId
74         {
75             [DataMember(Name = "id")]
76             public long Id { get; set; }
77         }
78
79         [DataMember(Name = "direct_message", IsRequired = false)]
80         public DeletedId DirectMessage { get; set; } // Nullable
81
82         [DataMember(Name = "status", IsRequired = false)]
83         public DeletedId Status { get; set; } // Nullable
84
85         public static StreamMessageDelete ParseJson(string json)
86             => MyCommon.CreateDataFromJson<StreamMessageDelete>(json);
87     }
88
89     [DataContract]
90     public class StreamMessageScrubGeo : ITwitterStreamMessage
91     {
92         [DataMember(Name = "user_id")]
93         public long UserId { get; set; }
94
95         [DataMember(Name = "up_to_status_id")]
96         public long UpToStatusId { get; set; }
97
98         public static StreamMessageScrubGeo ParseJson(string json)
99             => MyCommon.CreateDataFromJson<StreamMessageScrubGeo>(json);
100     }
101
102     public class StreamMessageKeepAlive : ITwitterStreamMessage
103     {
104     }
105
106     public class StreamMessageUnknown : ITwitterStreamMessage
107     {
108         public string Json { get; }
109
110         public StreamMessageUnknown(string json)
111             => this.Json = json;
112     }
113 }