diff Agendas/trunk/src/Agendas.Twitter/ITwitterAdapter.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
children 0bca45e1e664
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Twitter/ITwitterAdapter.cs	Wed Jun 08 08:40:04 2011 -0300
@@ -0,0 +1,54 @@
+using System;
+using Twitterizer;
+
+namespace AltNetHispano.Agendas.Twitter
+{
+	public interface ITwitterAdapter
+	{
+		Uri BuildAuthorizationUri(string consumerKey, string consumerSecret, string callbackAddress);
+		string GetAccessToken(string consumerKey, string consumerSecret, string requestToken, string verifier);
+		TwitterResponse<TwitterStatus> UpdateStatus(OAuthTokens tokens, string status);
+	}
+
+	public class TwitterAdapter : ITwitterAdapter
+	{
+		public Uri BuildAuthorizationUri(string consumerKey, string consumerSecret, 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;
+		}
+
+		public string GetAccessToken(string consumerKey, string consumerSecret, 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;
+
+		}
+
+		public TwitterResponse<TwitterStatus> UpdateStatus(OAuthTokens tokens, string status)
+		{
+			return TwitterStatus.Update(tokens, status);
+		}
+	}
+}
\ No newline at end of file