diff Agendas/trunk/src/Agendas.Twitter/oAuthTwitter.cs @ 111:90ce239cfa6d

Tests sobre el publicador de twitter, cada track se pulica solo una vez
author Nelo@Kenia.neluz.int
date Wed, 08 Jun 2011 08:40:04 -0300
parents a456eb519e23
children 0bca45e1e664
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Twitter/oAuthTwitter.cs	Wed Jun 08 07:33:14 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Twitter/oAuthTwitter.cs	Wed Jun 08 08:40:04 2011 -0300
@@ -1,11 +1,22 @@
 using System;
 using System.Configuration;
-using Twitterizer;
 
 namespace AltNetHispano.Agendas.Twitter
 {
 	public class OAuthTwitter
 	{
+		private readonly ITwitterAdapter _twitterAdapter;
+
+		public OAuthTwitter()
+		{
+			_twitterAdapter = new TwitterAdapter();
+		}
+
+		public OAuthTwitter(ITwitterAdapter twitterAdapter)
+		{
+			_twitterAdapter = twitterAdapter;
+		}
+
 		private string ConsumerKey
 		{
 			get { return ConfigurationManager.AppSettings["consumerKeyAppSignIn"]; }
@@ -18,35 +29,13 @@
 
 		public Uri AuthorizationLinkGet(string callbackAddress)
 		{
-			// Obtain a request token
-			OAuthTokenResponse requestToken = OAuthUtility.GetRequestToken(ConsumerKey, ConsumerSecret, callbackAddress);
-
-			// Direct or instruct the user to the following address:
-			Uri authorizationUri = OAuthUtility.BuildAuthorizationUri(requestToken.Token);
-
-			return authorizationUri;
+			var request = _twitterAdapter.BuildAuthorizationUri(ConsumerKey, ConsumerSecret, callbackAddress);
+			return request;
 		}
 
 		public string AccessTokenGet(string requestToken, string verifier)
 		{
-			OAuthTokenResponse accessToken = OAuthUtility.GetAccessToken(ConsumerKey, ConsumerSecret, requestToken, verifier);
-			
-			if (accessToken!=null)
-			{
-				var tokens = new OAuthTokens
-				             	{
-				             		AccessToken = accessToken.Token,
-				             		AccessTokenSecret = accessToken.TokenSecret,
-				             		ConsumerKey = ConsumerKey,
-				             		ConsumerSecret = ConsumerSecret
-				             	};
-
-				TwitterResponse<TwitterUser> showUserResponse = TwitterUser.Show(tokens, accessToken.UserId);
-				if (showUserResponse.Result == RequestResult.Success)
-					return showUserResponse.Content;
-				return showUserResponse.ErrorMessage;
-			}
-			return string.Empty;
+			return _twitterAdapter.GetAccessToken(ConsumerKey, ConsumerSecret, requestToken, verifier);
 		}
 	}
 }