Mercurial > altnet-hispano
comparison 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 |
comparison
equal
deleted
inserted
replaced
110:a456eb519e23 | 111:90ce239cfa6d |
---|---|
1 using System; | |
2 using Twitterizer; | |
3 | |
4 namespace AltNetHispano.Agendas.Twitter | |
5 { | |
6 public interface ITwitterAdapter | |
7 { | |
8 Uri BuildAuthorizationUri(string consumerKey, string consumerSecret, string callbackAddress); | |
9 string GetAccessToken(string consumerKey, string consumerSecret, string requestToken, string verifier); | |
10 TwitterResponse<TwitterStatus> UpdateStatus(OAuthTokens tokens, string status); | |
11 } | |
12 | |
13 public class TwitterAdapter : ITwitterAdapter | |
14 { | |
15 public Uri BuildAuthorizationUri(string consumerKey, string consumerSecret, string callbackAddress) | |
16 { | |
17 // Obtain a request token | |
18 OAuthTokenResponse requestToken = OAuthUtility.GetRequestToken(consumerKey, consumerSecret, callbackAddress); | |
19 | |
20 // Direct or instruct the user to the following address: | |
21 Uri authorizationUri = OAuthUtility.BuildAuthorizationUri(requestToken.Token); | |
22 | |
23 return authorizationUri; | |
24 } | |
25 | |
26 public string GetAccessToken(string consumerKey, string consumerSecret, string requestToken, string verifier) | |
27 { | |
28 OAuthTokenResponse accessToken = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, requestToken, verifier); | |
29 | |
30 if (accessToken != null) | |
31 { | |
32 var tokens = new OAuthTokens | |
33 { | |
34 AccessToken = accessToken.Token, | |
35 AccessTokenSecret = accessToken.TokenSecret, | |
36 ConsumerKey = consumerKey, | |
37 ConsumerSecret = consumerSecret | |
38 }; | |
39 | |
40 TwitterResponse<TwitterUser> showUserResponse = TwitterUser.Show(tokens, accessToken.UserId); | |
41 if (showUserResponse.Result == RequestResult.Success) | |
42 return showUserResponse.Content; | |
43 return showUserResponse.ErrorMessage; | |
44 } | |
45 return string.Empty; | |
46 | |
47 } | |
48 | |
49 public TwitterResponse<TwitterStatus> UpdateStatus(OAuthTokens tokens, string status) | |
50 { | |
51 return TwitterStatus.Update(tokens, status); | |
52 } | |
53 } | |
54 } |