Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
1.5.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
nickhodge committed May 21, 2014
1 parent afe3c18 commit 10e1572
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 35 deletions.
Binary file added build/BoxKite.Twitter.1.5.0.nupkg
Binary file not shown.
3 changes: 0 additions & 3 deletions src/BoxKite.LiveFireTests/BoxKite.LiveFireTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@
<Compile Include="..\Boxkite.Twitter.Console\Helpers\SecureIt.cs">
<Link>Helpers\SecureIt.cs</Link>
</Compile>
<Compile Include="..\BoxKite.Twitter.Desktop\Helpers\DesktopPlatformAdaptor.cs">
<Link>Helpers\DesktopPlatformAdaptor.cs</Link>
</Compile>
<Compile Include="Tests\ApiManagementLiveFireTests.cs" />
<Compile Include="Tests\ApplicationOnlyAuthLiveFireTests.cs" />
<Compile Include="Tests\CombosLiveFireTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ public class ApplicationOnlyAuthFireTests
public async Task<bool> DoCombosTest(IUserSession session, List<int> testSeq)
{
var successStatus = true;

// first, let's make our own session with clientkey/secret
//var twitterClientKeys = await ClientKeyManager.GetTwitterClientKeys();
//var newsession = new UserSession(twitterClientKeys.Item1, twitterClientKeys.Item2, new DesktopPlatformAdaptor());
var newsession = new UserSession("", "", new DesktopPlatformAdaptor());


try
{
// 1
if (testSeq.Contains(1))
{
ConsoleOutput.PrintMessage("12.1 User Time Line//Application Auth Only", ConsoleColor.Gray);

var combo1 = await session.GetUserTimeline("KatyPerry");
var combo1 = await newsession.GetUserTimeline("KatyPerry");

if (combo1.OK)
{
Expand All @@ -40,8 +47,7 @@ public async Task<bool> DoCombosTest(IUserSession session, List<int> testSeq)
successStatus = false;
throw new Exception("cannot user time line app only auth");
}

}
} // end test 1

}
catch (Exception e)
Expand Down
4 changes: 2 additions & 2 deletions src/BoxKite.Twitter.Desktop/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
27 changes: 27 additions & 0 deletions src/BoxKite.Twitter.Tests/Helpers/TestableSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class TestableSession : IUserSession

public string clientID { get; set; }
public string clientSecret { get; set; }
public string bearerToken { get; set; }
public int WaitTimeoutSeconds { get; set; }
public TwitterCredentials TwitterCredentials { get; set; }
public IPlatformAdaptor PlatformAdaptor { get; set; }

Expand All @@ -31,6 +33,31 @@ public IUserStream UserStreamBuilder()
throw new System.NotImplementedException();
}

public Task<HttpResponseMessage> GetApplicationAuthAsync(string relativeUrl, SortedDictionary<string, string> parameters)
{
if (!string.IsNullOrWhiteSpace(expectedGetUrl))
{
Assert.AreEqual(expectedGetUrl, relativeUrl);
}

this.receviedParameters = parameters;

if (simulatingError)
{
var response = new HttpResponseMessage(httpStatusCode) { Content = new StringContent(contents) }; //grab the supplied error code in setup
return Task.FromResult(response);
}
else
{
var response = new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(contents)
};
return Task.FromResult(response);
}
}

public Task<HttpResponseMessage> GetAsync(string relativeUrl, SortedDictionary<string, string> parameters)
{
if (!string.IsNullOrWhiteSpace(expectedGetUrl))
Expand Down
4 changes: 2 additions & 2 deletions src/BoxKite.Twitter.Universal/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
4 changes: 2 additions & 2 deletions src/BoxKite.Twitter.W8/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
4 changes: 2 additions & 2 deletions src/BoxKite.Twitter.WP8/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: NeutralResourcesLanguageAttribute("en-US")]
3 changes: 3 additions & 0 deletions src/BoxKite.Twitter/Authentication/TwitterAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ public static async Task<bool> StartApplicationOnlyAuth(this IUserSession sessio
var basicAuth = string.Format("Basic {0}", authToPost.ToBase64String());
var response = await PostData(OAuth2TokenUrl, basicAuth, OAuth2TokenUrlPostRequestRFC6749);
var jresponse = JObject.Parse(response);
// pretty blantant response
// Todo: make response match API response at https://dev.twitter.com/docs/auth/application-only-auth
// Todo: 401/403 response
if (jresponse["errors"] != null)
{
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/BoxKite.Twitter/Connection/TwitterConnectionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class TwitterConnection
//

// largestSeenIds
// TBD: these should/could be properties on Account so they can be persisted across launches
// ToDo: these should/could be properties on Account so they can be persisted across launches
private long _homeTimeLineLargestSeenId;
private long _directMessagesReceivedLargestSeenId;
private long _directMessagesSentLargestSeenId;
Expand Down
2 changes: 1 addition & 1 deletion src/BoxKite.Twitter/Connection/TwitterConnectionSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace BoxKite.Twitter
public partial class TwitterConnection
{
// largestSeenIds
// TBD: these should/could be properties on Account so they can be persisted across launches
// todo: these should/could be properties on Account so they can be persisted across launches
private long _searchLargestSeenId;
//

Expand Down
2 changes: 1 addition & 1 deletion src/BoxKite.Twitter/Modules/TimelineExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async static Task<TwitterResponseCollection<Tweet>> GetUserTimeline(this
var parameters = new TwitterParametersCollection();
parameters.Create(include_entities: true, include_rts: true, count: count, since_id: since_id, max_id: max_id, screen_name:screen_name);

return await session.GetApplicationAuthAsync(Api.Resolve("/1.1/statuses/user_timeline.json"), parameters)
return await session.GetAsync(Api.Resolve("/1.1/statuses/user_timeline.json"), parameters)
.ContinueWith(c => c.MapToMany<Tweet>());
}

Expand Down
4 changes: 2 additions & 2 deletions src/BoxKite.Twitter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
50 changes: 34 additions & 16 deletions src/BoxKite.Twitter/UserSession.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (c) 2012-2013 Nick Hodge mailto:[email protected] & Brendan Forster
// (c) 2012-2014 Nick Hodge mailto:[email protected] & Brendan Forster
// License: MS-PL

using System;
Expand Down Expand Up @@ -41,7 +41,7 @@ public TwitterCredentials TwitterCredentials {

public IEventAggregator TwitterConnectionEvents { get; set; }
public IPlatformAdaptor PlatformAdaptor { get; set; }
public IUserStream UserStream { get; set; }
public IUserStream UserStream { get; set; }
public ISearchStream SearchStream { get; set; }
public int WaitTimeoutSeconds { get; set; }

Expand All @@ -54,49 +54,55 @@ public UserSession(string clientID, string clientSecret, IPlatformAdaptor platfo
{
this.clientID = clientID;
this.clientSecret = clientSecret;
this.TwitterCredentials = TwitterCredentials.Null;
this.PlatformAdaptor = platformAdaptor;
this.WaitTimeoutSeconds = waitTimeoutSeconds;
TwitterCredentials = TwitterCredentials.Null;
PlatformAdaptor = platformAdaptor;
WaitTimeoutSeconds = waitTimeoutSeconds;
}

public UserSession(string clientID, string clientSecret, string bearerToken, IPlatformAdaptor platformAdaptor, int waitTimeoutSeconds = 30)
{
this.clientID = clientID;
this.clientSecret = clientSecret;
this.bearerToken = bearerToken;
this.TwitterCredentials = TwitterCredentials.Null;
this.PlatformAdaptor = platformAdaptor;
this.WaitTimeoutSeconds = waitTimeoutSeconds;
TwitterCredentials = TwitterCredentials.Null;
PlatformAdaptor = platformAdaptor;
WaitTimeoutSeconds = waitTimeoutSeconds;
}


public UserSession(TwitterCredentials credentials, IPlatformAdaptor platformAdaptor, int waitTimeoutSeconds = 30)
{
this.TwitterCredentials = credentials;
this.clientID = credentials.ConsumerKey;
this.clientSecret = credentials.ConsumerSecret;
this.bearerToken = credentials.BearerToken;
this.PlatformAdaptor = platformAdaptor;
this.WaitTimeoutSeconds = waitTimeoutSeconds;
TwitterCredentials = credentials;
clientID = credentials.ConsumerKey;
clientSecret = credentials.ConsumerSecret;
bearerToken = credentials.BearerToken;
PlatformAdaptor = platformAdaptor;
WaitTimeoutSeconds = waitTimeoutSeconds;
}

public IUserStream UserStreamBuilder()
{
return UserStream ?? this.GetUserStream(TwitterConnectionEvents);
}

/// <summary>
/// Use OAuth2 Bearer To do read-only query
/// </summary>
/// <param name="url">URL to call</param>
/// <param name="parameters">Params to send</param>
/// <returns></returns>
public async Task<HttpResponseMessage> GetApplicationAuthAsync(string url, SortedDictionary<string, string> parameters)
{
if (clientID != null && clientSecret != null && bearerToken == null)
{
await this.StartApplicationOnlyAuth();
}
if (TwitterCredentials == TwitterCredentials.Null && String.IsNullOrEmpty(this.bearerToken))
if (TwitterCredentials == TwitterCredentials.Null && String.IsNullOrEmpty(bearerToken))
throw new ArgumentException("Need to must be specified and validated");

var querystring = parameters.Aggregate("", (current, entry) => current + (entry.Key + "=" + entry.Value + "&"));

var oauth2 = String.Format("Bearer {0}",this.bearerToken);
var oauth2 = String.Format("Bearer {0}",bearerToken);
var fullUrl = url;

var handler = new HttpClientHandler();
Expand All @@ -117,6 +123,12 @@ public async Task<HttpResponseMessage> GetApplicationAuthAsync(string url, Sorte
return clientdownload;
}

/// <summary>
/// Use OAuth1.0a auth to do more intensive reads
/// </summary>
/// <param name="url">URL to call</param>
/// <param name="parameters">Params to send</param>
/// <returns></returns>
public async Task<HttpResponseMessage> GetAsync(string url, SortedDictionary<string, string> parameters)
{
if (TwitterCredentials == TwitterCredentials.Null || TwitterCredentials.Valid == false)
Expand Down Expand Up @@ -145,6 +157,12 @@ public async Task<HttpResponseMessage> GetAsync(string url, SortedDictionary<str
return clientdownload;
}

/// <summary>
/// Use OAuth1.0a auth to do more intensive POST
/// </summary>
/// <param name="url">URL to call</param>
/// <param name="parameters">Params to send</param>
/// <returns></returns>
public async Task<HttpResponseMessage> PostAsync(string url, SortedDictionary<string, string> parameters)
{
if (TwitterCredentials == TwitterCredentials.Null || TwitterCredentials.Valid == false)
Expand Down

0 comments on commit 10e1572

Please sign in to comment.