comparison Agendas/trunk/src/Agendas.Twitter/TwitterPublicador.cs @ 110:a456eb519e23

Lanzando twitts desde el sitio con la cuenta de AltNetHispanoDESA
author Nelo@Kenia.neluz.int
date Wed, 08 Jun 2011 07:33:14 -0300
parents 786a90e26c9b
children 90ce239cfa6d
comparison
equal deleted inserted replaced
109:6bd9be78caa0 110:a456eb519e23
1 using System; 1 using System.Collections.Generic;
2 using System.Collections.Generic;
3 using System.Configuration; 2 using System.Configuration;
4 using AltNetHispano.Agendas.Domain; 3 using AltNetHispano.Agendas.Domain;
5 using Twitterizer; 4 using Twitterizer;
6 5
7 namespace AltNetHispano.Agendas.Twitter 6 namespace AltNetHispano.Agendas.Twitter
8 { 7 {
9 public class TwitterPublicador : IPublicador 8 public class TwitterPublicador : IPublicador
10 { 9 {
10 public const int LIMITE_MENSAJE = 140;
11
11 private string ConsumerKey 12 private string ConsumerKey
12 { 13 {
13 get { return ConfigurationManager.AppSettings["consumerKey"]; } 14 get { return ConfigurationManager.AppSettings["consumerKeyAppTwitt"]; }
14 } 15 }
15 16
16 private string ConsumerSecret 17 private string ConsumerSecret
17 { 18 {
18 get { return ConfigurationManager.AppSettings["consumerSecret"]; } 19 get { return ConfigurationManager.AppSettings["consumerSecretAppTwitt"]; }
19 } 20 }
20 21
21 22
22 private string AccessToken 23 private string AccessToken
23 { 24 {
24 get { return ConfigurationManager.AppSettings["accessToken"]; } 25 get { return ConfigurationManager.AppSettings["accessTokenAppTwitt"]; }
25 } 26 }
26 27
27 28
28 private string AccessTokenSecret 29 private string AccessTokenSecret
29 { 30 {
30 get { return ConfigurationManager.AppSettings["accessTokenSecret"]; } 31 get { return ConfigurationManager.AppSettings["accessTokenSecretAppTwitt"]; }
31 } 32 }
32 33
33 public void Publicar(IEnumerable<Track> tracks) 34 public void Publicar(IEnumerable<Track> tracks)
34 { 35 {
35 throw new NotImplementedException(); 36 foreach (var track in tracks)
37 {
38 string message;
39 var twitt = BuildTwitt(track);
40 if (!string.IsNullOrWhiteSpace(twitt))
41 Publicar(twitt, out message);
42 }
36 } 43 }
37 44
38 public bool Publicar (string status, out string message) 45 private static string BuildTwitt(Track track)
46 {
47 string body = string.Empty;
48 switch (track.Accion)
49 {
50 case Accion.Proponer:
51 body = "Se ha propuesto un/a nuevo/a " + track.Evento.Tipo;
52 break;
53 case Accion.Agendar:
54 body = "Se ha agendando el evento" + track.Evento.Titulo;
55 if (track.Evento.Ponente.Twitter != null)
56 body += " con @" + track.Evento.Ponente.Twitter;
57 break;
58 case Accion.Confirmar:
59 if (track.Evento.Fecha.HasValue)
60 body = "Se confirma para el " + track.Evento.Fecha.Value.ToShortDateString() + " el evento " + track.Evento.Titulo;
61 break;
62 }
63
64 return body.Length > LIMITE_MENSAJE ? body.Substring(0, LIMITE_MENSAJE - 1) : body;
65 }
66
67 public bool Publicar(string status, out string message)
39 { 68 {
40 var tokens = new OAuthTokens 69 var tokens = new OAuthTokens
41 { 70 {
42 ConsumerKey = ConsumerKey, 71 ConsumerKey = ConsumerKey,
43 ConsumerSecret = ConsumerSecret, 72 ConsumerSecret = ConsumerSecret,
44 AccessToken = AccessToken, 73 AccessToken = AccessToken,
45 AccessTokenSecret = AccessTokenSecret 74 AccessTokenSecret = AccessTokenSecret
46 }; 75 };
47 76
48 var response = TwitterStatus.Update(tokens, status); 77 var response = TwitterStatus.Update(tokens, status);
49 78
50 message = response.ErrorMessage; 79 message = response.ErrorMessage;
51 return response.Result == RequestResult.Success; 80 return response.Result == RequestResult.Success;
52
53 } 81 }
54 } 82 }
55 } 83 }