Skip to content

Commit

Permalink
Merge pull request #25 from Yortw/Feature-TwitterApiSupportUpdates
Browse files Browse the repository at this point in the history
Various updates to support new Twitter API's. A few fixes for broken …
  • Loading branch information
Yortw committed Dec 29, 2015
2 parents 2877ba2 + 77e3dba commit 88c014e
Show file tree
Hide file tree
Showing 25 changed files with 686 additions and 59 deletions.
25 changes: 16 additions & 9 deletions TweetMoaSharp.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
<package>
<metadata>
<id>TweetMoaSharp</id>
<version>3.0.0.12</version>
<version>3.0.0.13</version>
<dependencies>
<group>
<dependency id="Newtonsoft.Json" version="6.0.1" />
</group>
<group targetFramework="net40">
<dependency id="Newtonsoft.Json" version="8.0.1" />
</group>
<group targetFramework="net45">
<dependency id="Newtonsoft.Json" version="8.0.1" />
</group>
<group targetFramework="portable-win81+wpa81">
<dependency id="Newtonsoft.Json" version="6.0.8" />
</group>
Expand All @@ -27,15 +33,16 @@
<iconUrl>https://raw.githubusercontent.com/Yortw/tweetmoasharp/master/logo_tweetmoasharp.png</iconUrl>
<tags>twitter tweetmoasharp tweetsharp web api http rest wrapper json wp7 mango silverlight winrt uwp</tags>
<releaseNotes>
New in 3.0.0.12
New in 3.0.0.13
----------
- Added Until option to Search method.
- Added Count option to ListFollowersOptions and ListFriendsOptions.
- Many fixes to streaming system.
- Added RetrievedAt property to TwitterStatus, set by deserailiser at serialisation time to current time.
- TwitterExtendedEntity now has default entity type of 'Media'.
- JsonSerialiser now correctly deserialises cursor collections on WinRT.
- Fixes to deflate decompression handling.
- Added methods to mute/unmute/list muted users etc.
- Added Direct Message character count to config response.
- Added IsMuting to TwitterFriend.
- Added Following and Entities properties to TwitterUser.
- Added ToTwitterUrl extension method on TwitterStatus - returns link to tweet on web.
- Fixed TwitterTrends so it accepts long ids.
- Fixed post status so it uses a long for place id.
- Fixed bug in media upload.
</releaseNotes>
</metadata>
<files>
Expand Down
2 changes: 1 addition & 1 deletion hammock
Submodule hammock updated from dd22d4 to 636be5
8 changes: 6 additions & 2 deletions src/TweetSharp.Net35/TweetSharp.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@
<AssemblyOriginatorKeyFile>..\TweetSharp\key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
3 changes: 2 additions & 1 deletion src/TweetSharp.Net35/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net35-Client" />
<package id="Newtonsoft.Json" version="8.0.1" targetFramework="net35-client" />
<package id="NUnit" version="2.6.4" targetFramework="net35-client" />
</packages>
8 changes: 6 additions & 2 deletions src/TweetSharp.Net45/TweetSharp.Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@
<ApplicationIcon>assembly.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
3 changes: 2 additions & 1 deletion src/TweetSharp.Net45/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="8.0.1" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
</packages>
4 changes: 2 additions & 2 deletions src/TweetSharp.Tests/TweetSharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
Expand Down
8 changes: 8 additions & 0 deletions src/TweetSharp.Tests/TwitterServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,15 @@ public void Can_tweet_with_image()
var service = GetAuthenticatedService();
using (var stream = new FileStream("daniel_8bit.png", FileMode.Open))
{
#pragma warning disable CS0618 // Type or member is obsolete
var tweet = service.SendTweetWithMedia(new SendTweetWithMediaOptions
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning restore CS0618 // Type or member is obsolete
{
Status = "Can_tweet_with_image:Tweet",
Images = new Dictionary<string, Stream> {{"test", stream}}
});
#pragma warning restore CS0618 // Type or member is obsolete
Assert.IsNotNull(tweet);
Assert.AreNotEqual(0, tweet.Id);
}
Expand All @@ -425,11 +429,15 @@ public void Can_tweet_with_image_and_accented_char()
service.TraceEnabled = true;
using (var stream = new FileStream("daniel_8bit.png", FileMode.Open, FileAccess.Read, FileShare.Read))
{
#pragma warning disable CS0618 // Type or member is obsolete
var tweet = service.SendTweetWithMedia(new SendTweetWithMediaOptions
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning restore CS0618 // Type or member is obsolete
{
Status = "Can_tweet_with_image:Tweet and accented char à",
Images = new Dictionary<string, Stream> { { "test", stream } }
});
#pragma warning restore CS0618 // Type or member is obsolete

AssertResultWas(service, HttpStatusCode.OK);
Assert.IsNotNull(tweet);
Expand Down
4 changes: 2 additions & 2 deletions src/TweetSharp.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net4" requireReinstallation="true" />
<package id="NUnit" version="2.6.4" targetFramework="net4" />
<package id="Newtonsoft.Json" version="8.0.1" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
</packages>
4 changes: 4 additions & 0 deletions src/TweetSharp.WinRT/TweetSharp.WinRT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">.\</SolutionDir>
<RestorePackages>true</RestorePackages>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -250,6 +252,7 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\..\..\Me\uTweet\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\..\Me\uTweet\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
<PropertyGroup>
<PreBuildEvent>
Expand All @@ -259,6 +262,7 @@
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Import Project="..\..\..\..\..\Me\uTweet\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\..\..\Me\uTweet\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
2 changes: 2 additions & 0 deletions src/TweetSharp.WinRT/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="portable46-win81+wpa81" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="portable46-win81+wpa81" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="portable-win81+wpa81" />
</packages>
2 changes: 1 addition & 1 deletion src/TweetSharp/Properties/AssemblyInfoVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
// [assembly: AssemblyVersion("1.0.*")]
using System.Reflection;
[assembly: AssemblyVersion("3.0.0.1")]
[assembly: AssemblyFileVersion("3.0.0.12")]
[assembly: AssemblyFileVersion("3.0.0.13")]
8 changes: 6 additions & 2 deletions src/TweetSharp/TweetSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
<ApplicationIcon>assembly.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down
22 changes: 21 additions & 1 deletion src/TweetSharp/TwitterConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace TweetSharp
public class TwitterConfiguration : PropertyChangedBase
{
private int _CharactersReservedPerMedia;
private int _MaxMediaPerUpload;
private int _DirectMessageCharacterLimit;
private int _MaxMediaPerUpload;
private int _ShortUrlLength;
private int _ShortUrlLengthHttps;
private int _PhotoSizeLimit;
Expand All @@ -44,6 +45,25 @@ public virtual int CharactersReservedPerMedia
}
}

[JsonProperty("dm_text_character_limit")]
#if !Smartphone && !NET20
[DataMember]
#endif
public virtual int DirectMessageCharacterLimit
{
get { return _DirectMessageCharacterLimit; }
set
{
if (_DirectMessageCharacterLimit == value)
{
return;
}

_DirectMessageCharacterLimit = value;
OnPropertyChanged("DirectMessageCharacterLimit");
}
}

[JsonProperty("max_media_per_upload")]
#if !Smartphone && !NET20
[DataMember]
Expand Down
22 changes: 21 additions & 1 deletion src/TweetSharp/TwitterFriend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class TwitterFriend : PropertyChangedBase, ITwitterModel
private bool? _notificationsEnabled;
private bool? _canDm;
private bool? _blocking;
private bool? _muting;

#if !Smartphone && !NET20
[DataMember]
Expand Down Expand Up @@ -151,7 +152,26 @@ public virtual bool? IsBlocking
}

#if !Smartphone && !NET20
[DataMember]
[DataMember]
#endif
[JsonProperty("muting")]
public virtual bool? IsMuting
{
get { return _muting; }
set
{
if (_muting == value)
{
return;
}

_muting = value;
OnPropertyChanged("IsMuting");
}
}

#if !Smartphone && !NET20
[DataMember]
#endif
public virtual string RawSource { get; set; }
}
Expand Down
81 changes: 66 additions & 15 deletions src/TweetSharp/TwitterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,25 +473,39 @@ private IAsyncResult WithHammock<T>(RestClient client, WebMethod method, Action<
return WithHammockImpl(client, request, action);
}

private IAsyncResult WithHammock<T>(RestClient client, WebMethod method, Action<T, TwitterResponse> action, MediaFile media, string path) where T : class
{
var request = PrepareHammockQuery(path);
request.Method = method;
request.AddFile("media", media.FileName, media.Content);

return WithHammockImpl(client, request, action);
}

private IAsyncResult WithHammock<T>(RestClient client, WebMethod method, Action<T, TwitterResponse> action, string path, params object[] segments) where T : class
{
return WithHammock(client, method, action, ResolveUrlSegments(path, segments.ToList()));
}

private IAsyncResult WithHammockImpl<T>(RestClient client, RestRequest request, Action<T, TwitterResponse> action) where T : class
{
return client.BeginRequest(
request, new RestCallback<T>((req, response, state) =>
{
if (response == null)
{
return;
}
SetResponse(response);
var entity = response.ContentEntity;
action.Invoke(entity, new TwitterResponse(response));
}));
}
private IAsyncResult WithHammock<T>(RestClient client, WebMethod method, Action<T, TwitterResponse> action, string path, MediaFile media, params object[] segments) where T : class
{
return WithHammock(client, method, action, media, ResolveUrlSegments(path, segments.ToList()));
}

private IAsyncResult WithHammockImpl<T>(RestClient client, RestRequest request, Action<T, TwitterResponse> action) where T : class
{
return client.BeginRequest(
request, new RestCallback<T>((req, response, state) =>
{
if (response == null)
{
return;
}
SetResponse(response);
var entity = response.ContentEntity;
action.Invoke(entity, new TwitterResponse(response));
}));
}

private IAsyncResult BeginWithHammock<T>(RestClient client, WebMethod method, string path, params object[] segments)
{
Expand Down Expand Up @@ -631,6 +645,15 @@ private void WithHammock<T>(IRestClient restClient, WebMethod method, Action<T,
WithHammockImpl(restClient, request, action);
}

private void WithHammock<T>(IRestClient restClient, WebMethod method, Action<T, TwitterResponse> action, MediaFile media, string path) where T : class
{
var request = PrepareHammockQuery(path);
request.Method = method;
request.AddFile("media", media.FileName, media.Content);

WithHammockImpl(restClient, request, action);
}

private void WithHammock<T>(IRestClient restClient, WebMethod method, Action<T, TwitterResponse> action, string path, params object[] segments) where T : class
{
WithHammock(restClient, method, action, ResolveUrlSegments(path, segments.ToList()));
Expand Down Expand Up @@ -723,9 +746,37 @@ private Task<TwitterAsyncResult<T1>> WithHammockTask<T1>(RestClient client, WebM
return tcs.Task;
}

private Task<TwitterAsyncResult<T1>> WithHammockTask<T1>(RestClient client, WebMethod method, string path, MediaFile media, params object[] segments) where T1 : class
{
var tcs = new TaskCompletionSource<TwitterAsyncResult<T1>>();
try
{
WithHammock<T1>(client, method,
(Action<T1, TwitterResponse>)((v, r) =>
{
try
{
tcs.SetResult(new TwitterAsyncResult<T1>(v, r));
}
catch (Exception ex)
{
tcs.SetException(ex);
}
}),
media,
ResolveUrlSegments(path, segments.ToList())
);
}
catch (Exception ex)
{
tcs.SetException(ex);
}

return tcs.Task;
}
#endif

private static T TryAsyncResponse<T>(Func<T> action, out Exception exception)
private static T TryAsyncResponse<T>(Func<T> action, out Exception exception)
{
exception = null;
var entity = default(T);
Expand Down
Loading

0 comments on commit 88c014e

Please sign in to comment.