view Agendas/trunk/src/Agendas.Twitter/ITwitterAdapter.cs @ 126:6012f2becf97

Se agrega instalación de nuget package para el calendario de google.
author alabra
date Tue, 28 Jun 2011 23:35:22 -0400
parents 0bca45e1e664
children 734d3f0853bf
line wrap: on
line source

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);
		}
	}
}