diff --git a/TweetMoaSharp.nuspec b/TweetMoaSharp.nuspec index 37eae94..908cb11 100644 --- a/TweetMoaSharp.nuspec +++ b/TweetMoaSharp.nuspec @@ -2,7 +2,7 @@ TweetMoaSharp - 5.1.0 + 5.2.0 @@ -18,9 +18,9 @@ https://raw.githubusercontent.com/Yortw/tweetmoasharp/master/logo_tweetmoasharp.png twitter tweetmoasharp tweetsharp web api http rest wrapper json winrt uwp netcore netstandard10 netstandard20 - New in 5.1.0 + New in 5.2.0 ---------- - - Async Direct Message methods now use the new API (and actually work) + - CreatedAt now set properly on direct message events. diff --git a/src/TweetSharp.Tests/TwitterServiceTests.cs b/src/TweetSharp.Tests/TwitterServiceTests.cs index 37e6502..2188ef0 100644 --- a/src/TweetSharp.Tests/TwitterServiceTests.cs +++ b/src/TweetSharp.Tests/TwitterServiceTests.cs @@ -1745,6 +1745,7 @@ public async Task Can_Send_DirectMessageWithMedia() Assert.IsNotNull(result); Assert.IsNotNull(result.Event); Assert.NotZero(result.Event.Id); + Assert.AreNotEqual(DateTime.MinValue, result.Event.CreatedAt); var rate = service.Response.RateLimitStatus; Assert.IsNotNull(rate); diff --git a/src/TweetSharp/Properties/AssemblyInfoVersion.cs b/src/TweetSharp/Properties/AssemblyInfoVersion.cs index 11bcc65..fefa728 100644 --- a/src/TweetSharp/Properties/AssemblyInfoVersion.cs +++ b/src/TweetSharp/Properties/AssemblyInfoVersion.cs @@ -9,5 +9,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] using System.Reflection; -[assembly: AssemblyVersion("5.1.0.0")] -[assembly: AssemblyFileVersion("5.1.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("5.2.0.0")] +[assembly: AssemblyFileVersion("5.2.0.0")] \ No newline at end of file diff --git a/src/TweetSharp/TwitterDateFormat.cs b/src/TweetSharp/TwitterDateFormat.cs index d97fdd1..bb79661 100644 --- a/src/TweetSharp/TwitterDateFormat.cs +++ b/src/TweetSharp/TwitterDateFormat.cs @@ -45,6 +45,10 @@ public enum TwitterDateFormat /// TrendsWeekly /// [Description("yyyy-MM-dd")] - TrendsWeekly + TrendsWeekly, + /// + /// Used by the new direct messaging/event API. + /// + MillisecondsSinceEpoch } } \ No newline at end of file diff --git a/src/TweetSharp/TwitterDateTime.cs b/src/TweetSharp/TwitterDateTime.cs index 757d8ac..adf39ec 100644 --- a/src/TweetSharp/TwitterDateTime.cs +++ b/src/TweetSharp/TwitterDateTime.cs @@ -33,6 +33,8 @@ public class TwitterDateTime : ITwitterModel private static readonly IDictionary _map = new Dictionary(); + private static readonly DateTime Epoch = new DateTime(1970, 01, 01, 0, 0, 0, DateTimeKind.Utc); + /// /// Gets or sets the Twitter-based date format. /// @@ -76,6 +78,9 @@ public static string ConvertFromDateTime(DateTime input, TwitterDateFormat forma { EnsureDateFormatsAreMapped(); + if (format == TwitterDateFormat.MillisecondsSinceEpoch) + return input.Subtract(Epoch).TotalMilliseconds.ToString(); + #if !SILVERLIGHT && !Smartphone var name = Enum.GetName(typeof(TwitterDateFormat), format); #else @@ -120,6 +125,15 @@ public static DateTime ConvertToDateTime(string input) } } + if (Int64.TryParse(input, out var millisecondsSinceEpoch)) + { + return new DateTime + ( + Epoch.Add(TimeSpan.FromMilliseconds(millisecondsSinceEpoch)).Ticks, + DateTimeKind.Utc + ); + } + return default(DateTime); } @@ -152,6 +166,15 @@ public static TwitterDateTime ConvertToTwitterDateTime(string input) } } + if (Int64.TryParse(input, out var millisecondsSinceEpoch)) + { + return new TwitterDateTime + ( + new DateTime(Epoch.Add(TimeSpan.FromMilliseconds(millisecondsSinceEpoch)).Ticks, DateTimeKind.Utc), + TwitterDateFormat.MillisecondsSinceEpoch + ); + } + return default(TwitterDateTime); } finally @@ -188,9 +211,12 @@ private static void EnsureDateFormatsAreMapped() var fi = typeof(TwitterDateFormat).GetTypeInfo().GetDeclaredField(name); var attributes = System.Linq.Enumerable.ToArray(fi.GetCustomAttributes(typeof(DescriptionAttribute), false)); #endif - var format = (DescriptionAttribute)attributes[0]; - - _map.Add(name, format.Description); + if (attributes.Length > 0) + { + var format = (DescriptionAttribute)attributes[0]; + if (!String.IsNullOrEmpty(format.Description)) + _map.Add(name, format.Description); + } } finally { diff --git a/src/TweetSharp/TwitterDirectMessageEvent.cs b/src/TweetSharp/TwitterDirectMessageEvent.cs index f245910..469fb29 100644 --- a/src/TweetSharp/TwitterDirectMessageEvent.cs +++ b/src/TweetSharp/TwitterDirectMessageEvent.cs @@ -64,7 +64,7 @@ public virtual string Type #if !Smartphone && !NET20 [DataMember] #endif - [JsonProperty("created_at")] + [JsonProperty("created_timestamp")] public virtual DateTime CreatedAt { get { return _createdAt; } diff --git a/tweetmoasharp-push-nuget.bat b/tweetmoasharp-push-nuget.bat index ba8d146..cd4c253 100644 --- a/tweetmoasharp-push-nuget.bat +++ b/tweetmoasharp-push-nuget.bat @@ -1 +1 @@ -".nuget\NuGet.exe" push TweetMoaSharp.5.1.0.nupkg -Source https://api.nuget.org/v3/index.json \ No newline at end of file +".nuget\NuGet.exe" push TweetMoaSharp.5.2.0.nupkg -Source https://api.nuget.org/v3/index.json \ No newline at end of file