Skip to content

Commit

Permalink
Changed Twitterizer back to JSON.Net 4.0.5 as this version works with…
Browse files Browse the repository at this point in the history
… our converters correctly. We'll need to look into the JSON.net changes more before moving up to the latest versions.

Fixed OAuth signature being generated incorrectly for streaming connections.
Added Silverlight support back to Twitterizer for the entire library.
Added/updated list endpoints and options
Improved Stream event deserialisation
Fixed ignore folders.
Added MaxStatusId to Favorites
Added Hack for bad tracking cookies being sent from twitter on Siverlight search and api calls.
Fixed a few bugs with Trends deserialisation
  • Loading branch information
GoldenTao committed Mar 13, 2012
1 parent 08b8dd4 commit ee55517
Show file tree
Hide file tree
Showing 30 changed files with 396 additions and 245 deletions.
3 changes: 1 addition & 2 deletions Twitterizer.OAuth/Twitterizer.OAuth.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\Debug\Twitterizer2\Full\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down Expand Up @@ -121,7 +121,6 @@
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>

<!-- 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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<OutputPath>..\Debug\Twitterizer2\SL\</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
Expand Down
182 changes: 155 additions & 27 deletions Twitterizer2.Async/AsyncUtility.cs

Large diffs are not rendered by default.

64 changes: 21 additions & 43 deletions Twitterizer2.Async/TwitterListAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,7 @@ public static class TwitterListAsync
/// <returns></returns>
public static IAsyncResult AddMember(OAuthTokens tokens, string ownerUsername, string listId, decimal userIdToAdd, OptionalProperties options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterList>> function)
{
Func<OAuthTokens, string, string, decimal, OptionalProperties, TwitterResponse<TwitterList>> methodToCall = TwitterList.AddMember;

return methodToCall.BeginInvoke(
tokens,
ownerUsername,
listId,
userIdToAdd,
options,
result => AsyncUtility.FourParamsCallback(result, timeout, methodToCall, function),
null);
return AsyncUtility.ExecuteAsyncMethod(tokens, ownerUsername, listId, userIdToAdd, options, timeout, TwitterList.AddMember, function);
}

/// <summary>
Expand All @@ -45,16 +36,7 @@ public static IAsyncResult AddMember(OAuthTokens tokens, string ownerUsername, s
/// <returns></returns>
public static IAsyncResult CheckMembership(OAuthTokens tokens, string ownerUsername, string listId, decimal userId, OptionalProperties options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterUser>> function)
{
Func<OAuthTokens, string, string, decimal, OptionalProperties, TwitterResponse<TwitterUser>> methodToCall = TwitterList.CheckMembership;

return methodToCall.BeginInvoke(
tokens,
ownerUsername,
listId,
userId,
options,
result => AsyncUtility.FourParamsCallback(result, timeout, methodToCall, function),
null);
return AsyncUtility.ExecuteAsyncMethod(tokens, ownerUsername, listId, userId, options, timeout, TwitterList.CheckMembership, function);
}

/// <summary>
Expand Down Expand Up @@ -139,14 +121,28 @@ public static IAsyncResult GetMembers(
/// List the lists the specified user has been added to.
/// </summary>
/// <param name="tokens">The tokens.</param>
/// <param name="username">The username.</param>
/// <param name="screenname">The screenname.</param>
/// <param name="options">The options.</param>
/// <param name="timeout">The timeout.</param>
/// <param name="function">The function.</param>
/// <returns></returns>
public static IAsyncResult GetMemberships(OAuthTokens tokens, string screenname, ListMembershipsOptions options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterListCollection>> function)
{
return AsyncUtility.ExecuteAsyncMethod(tokens, screenname, options, timeout, TwitterList.GetMemberships, function);
}

/// <summary>
/// List the lists the specified user has been added to.
/// </summary>
/// <param name="tokens">The tokens.</param>
/// <param name="userid">The userid.</param>
/// <param name="options">The options.</param>
/// <param name="timeout">The timeout.</param>
/// <param name="function">The function.</param>
/// <returns></returns>
public static IAsyncResult GetMemberships(OAuthTokens tokens, string username, ListMembershipsOptions options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterListCollection>> function)
public static IAsyncResult GetMemberships(OAuthTokens tokens, decimal userid, ListMembershipsOptions options, TimeSpan timeout, Action<TwitterAsyncResponse<TwitterListCollection>> function)
{
return AsyncUtility.ExecuteAsyncMethod(tokens, username, options, timeout, TwitterList.GetMemberships, function);
return AsyncUtility.ExecuteAsyncMethod(tokens, userid, options, timeout, TwitterList.GetMemberships, function);
}

/// <summary>
Expand Down Expand Up @@ -209,16 +205,7 @@ public static IAsyncResult New(
TimeSpan timeout,
Action<TwitterAsyncResponse<TwitterList>> function)
{
Func<OAuthTokens, string, bool, string, OptionalProperties, TwitterResponse<TwitterList>> methodToCall = TwitterList.New;

return methodToCall.BeginInvoke(
tokens,
name,
isPublic,
description,
options,
result => AsyncUtility.FourParamsCallback(result, timeout, methodToCall, function),
null);
return AsyncUtility.ExecuteAsyncMethod(tokens, name, isPublic, description, options, timeout, TwitterList.New, function);
}

/// <summary>
Expand All @@ -241,16 +228,7 @@ public static IAsyncResult RemoveMember(
TimeSpan timeout,
Action<TwitterAsyncResponse<TwitterList>> function)
{
Func<OAuthTokens, string, string, decimal, OptionalProperties, TwitterResponse<TwitterList>> methodToCall = TwitterList.RemoveMember;

return methodToCall.BeginInvoke(
tokens,
ownerUsername,
listId,
userIdToAdd,
options,
result => AsyncUtility.FourParamsCallback(result, timeout, methodToCall, function),
null);
return AsyncUtility.ExecuteAsyncMethod(tokens, ownerUsername, listId, userIdToAdd, options, timeout, TwitterList.AddMember, function);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions Twitterizer2.Async/Twitterizer2.Async.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\Debug\Twitterizer2\Full\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Twitterizer2.Asynchronous.XML</DocumentationFile>
<DocumentationFile>..\Debug\Twitterizer2\Full\Twitterizer2.Asynchronous.XML</DocumentationFile>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
Expand All @@ -60,9 +60,9 @@
<AssemblyOriginatorKeyFile>..\Twitterizer2\Twitterizer2.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=4.0.8.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<Reference Include="Newtonsoft.Json, Version=4.0.5.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.4.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.4.0.5\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion Twitterizer2.Async/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="4.0.8" />
<package id="Newtonsoft.Json" version="4.0.5" />
</packages>
6 changes: 3 additions & 3 deletions Twitterizer2.Silverlight/Twitterizer2.Silverlight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<OutputPath>..\Debug\Twitterizer2\SL\</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
Expand All @@ -58,9 +58,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="Newtonsoft.Json, Version=4.0.8.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Newtonsoft.Json, Version=4.0.5.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.4.0.8\lib\sl4\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.4.0.5\lib\sl4\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
Expand Down
2 changes: 1 addition & 1 deletion Twitterizer2.Silverlight/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="4.0.8" />
<package id="Newtonsoft.Json" version="4.0.5" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Bin\Debug</OutputPath>
<OutputPath>..\Debug\Twitterizer2\SL\</OutputPath>
<DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
<NoStdLib>true</NoStdLib>
<NoConfig>true</NoConfig>
Expand All @@ -50,9 +50,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="Newtonsoft.Json, Version=4.0.8.0, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="Newtonsoft.Json, Version=4.0.5.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.4.0.8\lib\sl4\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.4.0.5\lib\sl4\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Windows" />
Expand Down
2 changes: 1 addition & 1 deletion Twitterizer2.Streaming.Silverlight/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="4.0.8" />
<package id="Newtonsoft.Json" version="4.0.5" />
</packages>
2 changes: 1 addition & 1 deletion Twitterizer2.Streaming/StreamOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Twitterizer.Streaming

public class StreamOptions
{
protected StreamOptions()
public StreamOptions()
{
this.Track = new List<string>();
this.Locations = new List<Location>();
Expand Down
4 changes: 2 additions & 2 deletions Twitterizer2.Streaming/TwitterSteamEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Newtonsoft.Json;
using System.Runtime.Serialization;

namespace Twitterizer2.Streaming
namespace Twitterizer.Streaming
{
/// <summary>
/// Describes the type of event that has occured on twitter
Expand Down Expand Up @@ -96,7 +96,7 @@ public enum TwitterSteamEvent
/// <summary>
/// The source users profile was updated.
/// </summary>
[EnumMemberAttribute(Value = "user_updated")]
[EnumMemberAttribute(Value = "user_update")]
UserUpdated
}
}
56 changes: 33 additions & 23 deletions Twitterizer2.Streaming/TwitterStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@
// <summary>The Twitter Stream class</summary>
//-----------------------------------------------------------------------

using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Twitterizer.Streaming
{
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Twitterizer.Core;

/// <summary>
/// The different stop reasons for stopping a stream.
/// </summary>
Expand All @@ -65,21 +66,15 @@ public enum StopReasons
}

public delegate void InitUserStreamCallback(TwitterIdCollection friendIds);

public delegate void StatusCreatedCallback(TwitterStatus status);

public delegate void StatusDeletedCallback(TwitterStreamDeletedEvent status);

public delegate void DirectMessageCreatedCallback(TwitterDirectMessage status);

public delegate void DirectMessageDeletedCallback(TwitterStreamDeletedEvent status);

public delegate void EventCallback(TwitterStreamEvent eventDetails);

public delegate void StreamStoppedCallback(StopReasons stopreason);

public delegate void RawJsonCallback(string json);


/// <summary>
/// The TwitterStream class. Provides an interface to real-time status changes.
/// </summary>
Expand Down Expand Up @@ -287,9 +282,8 @@ private void PrepareStreamOptions(WebRequestBuilder builder)
if (StreamOptions.Track != null && StreamOptions.Track.Count > 0)
builder.Parameters.Add("track", string.Join(",", StreamOptions.Track.ToArray()));

if (StreamOptions.UseCompression != null)
builder.Parameters.Add("UseCompression", StreamOptions.UseCompression);
}
builder.UseCompression = StreamOptions.UseCompression;
}
}

/// <summary>
Expand Down Expand Up @@ -444,6 +438,7 @@ private void StreamCallback(IAsyncResult result)
req.Abort();
if (response != null)
response.Close();
request = null;
}
}

Expand Down Expand Up @@ -499,9 +494,24 @@ private void ParseMessage(string p)
var events = obj.SelectToken("event", false);
if (events != null)
{
if (eventCallback != null && events.HasValues)
if (eventCallback != null)
{
eventCallback(JsonConvert.DeserializeObject<TwitterStreamEvent>(ConvertJTokenToString(obj)));
var targetobject = obj.SelectToken("target_object", false);
TwitterObject endtargetobject = null;
if (targetobject != null)
{
if (targetobject.SelectToken("subscriber_count", false) != null)
{
endtargetobject = JsonConvert.DeserializeObject<TwitterList>(targetobject.ToString());
}
else if (targetobject.SelectToken("user", false) != null)
{
endtargetobject = JsonConvert.DeserializeObject<TwitterStatus>(targetobject.ToString());
}
}
var endevent = JsonConvert.DeserializeObject<TwitterStreamEvent>(obj.ToString());
endevent.TargetObject = endtargetobject;
this.eventCallback(endevent);
}
return;
}
Expand Down
3 changes: 1 addition & 2 deletions Twitterizer2.Streaming/TwitterStreamEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Twitterizer2.Streaming;
namespace Twitterizer.Streaming
namespace Twitterizer.Streaming
{
using System;
using Newtonsoft.Json;
Expand Down
Loading

0 comments on commit ee55517

Please sign in to comment.