Mercurial > altnet-hispano
view Agendas/trunk/src/Agendas.Twitter/ITwitterAdapter.cs @ 200:5346c0500594 deploy pre 1.0
Pasando a estructura de db fija, ya no se crea automáticamente.
Se comenta lo referente a Patrocinadores que queda para alguna futura versión.
Script para tablas de v1.0
author | nelopauselli |
---|---|
date | Wed, 17 Aug 2011 17:54:45 -0300 |
parents | 734d3f0853bf |
children |
line wrap: on
line source
using System; using AltNetHispano.Agendas.Configurations; 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); bool Update(string status, out string message); } public class TwitterAdapter : ITwitterAdapter { private static TwitterConfigurationElement _config; public TwitterAdapter() { _config = AgendasConfigurationManager.Publicadores.Twitter; } private static string ConsumerKey { get { return _config.SendTwitter.ConsumerKey; } } private static string ConsumerSecret { get { return _config.SendTwitter.ConsumerSecret; } } private static string AccessToken { get { return _config.SendTwitter.AccessToken; } } private static string AccessTokenSecret { get { return _config.SendTwitter.AccessTokenSecret; } } 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 bool Update(string status, out string message) { var tokens = new OAuthTokens { ConsumerKey = ConsumerKey, ConsumerSecret = ConsumerSecret, AccessToken = AccessToken, AccessTokenSecret = AccessTokenSecret }; var response = TwitterStatus.Update(tokens, status); message = response.ErrorMessage; return response.Result == RequestResult.Success; } } }