This repository has been archived by the owner on Apr 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
86 additions
and
35 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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; } | ||
|
||
|
@@ -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(); | ||
|
@@ -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) | ||
|
@@ -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) | ||
|