Mercurial > altnet-hispano
view Agendas/trunk/src/Agendas.Twitter/ITwitterAdapter.cs @ 137:2d1adbaf0373
CRUD de Patrocinador
author | nelopauselli |
---|---|
date | Thu, 28 Jul 2011 09:26:24 -0300 |
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); } } }