OSDN Git Service

Streaming APIのメソッドの返り値にIObservableを使用する
[opentween/open-tween.git] / OpenTween / Api / DataModel / TwitterTextConfiguration.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2017 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     [DataContract]
27     public class TwitterTextConfiguration
28     {
29         [DataMember(Name = "version")]
30         public int Version { get; set; }
31
32         [DataMember(Name = "maxWeightedTweetLength")]
33         public int MaxWeightedTweetLength { get; set; }
34
35         [DataMember(Name = "scale")]
36         public int Scale { get; set; }
37
38         [DataMember(Name = "defaultWeight")]
39         public int DefaultWeight { get; set; }
40
41         [DataMember(Name = "transformedURLLength")]
42         public int TransformedURLLength { get; set; }
43
44         [DataContract]
45         public class CodepointRange
46         {
47             [DataMember(Name = "start")]
48             public int Start { get; set; }
49
50             [DataMember(Name = "end")]
51             public int End { get; set; }
52
53             [DataMember(Name = "weight")]
54             public int Weight { get; set; }
55         }
56
57         [DataMember(Name = "ranges")]
58         public CodepointRange[] Ranges { get; set; }
59
60         /// <exception cref="SerializationException"/>
61         public static TwitterTextConfiguration ParseJson(string json)
62         {
63             return MyCommon.CreateDataFromJson<TwitterTextConfiguration>(json);
64         }
65
66         public static TwitterTextConfiguration DefaultConfiguration()
67         {
68             // 参照: https://github.com/twitter/twitter-text/blob/v2.0.5/config/v2.json
69             return new TwitterTextConfiguration
70             {
71                 Version = 2,
72                 MaxWeightedTweetLength = 280,
73                 Scale = 100,
74                 DefaultWeight = 200,
75                 TransformedURLLength = 23,
76                 Ranges = new[]
77                 {
78                     new CodepointRange { Start = 0, End = 4351, Weight = 100 },
79                     new CodepointRange { Start = 8192, End = 8205, Weight = 100 },
80                     new CodepointRange { Start = 8208, End = 8223, Weight = 100 },
81                     new CodepointRange { Start = 8242, End = 8247, Weight = 100 },
82                 },
83             };
84         }
85     }
86 }