Mercurial > altnet-hispano
diff Agendas/trunk/src/Agendas.Twitter/TwitterPublicador.cs @ 122:17531db40d4e
Refactoring de la generaciĆ³n de mensajes en twitter
author | nelopauselli |
---|---|
date | Tue, 28 Jun 2011 19:25:22 -0300 |
parents | c3573defd18f |
children | 734d3f0853bf |
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Twitter/TwitterPublicador.cs Fri Jun 24 21:19:42 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Twitter/TwitterPublicador.cs Tue Jun 28 19:25:22 2011 -0300 @@ -2,44 +2,54 @@ using System.Configuration; using System.Linq; using AltNetHispano.Agendas.Domain; +using AltNetHispano.Agendas.Twitter.Writers; using Twitterizer; namespace AltNetHispano.Agendas.Twitter { public class TwitterPublicador : IPublicador { + private readonly IDictionary<Accion, ITwitterWriter> _writers; private readonly ITwitterAdapter _twitterAdapter; public TwitterPublicador() + : this(new TwitterAdapter()) { - _twitterAdapter = new TwitterAdapter(); } public TwitterPublicador(ITwitterAdapter twitterAdapter) { + _writers = new Dictionary<Accion, ITwitterWriter> + { + {Accion.Proponer, new ProponerTwitterWriter()}, + {Accion.Agendar, new AgendarTwitterWriter()}, + {Accion.Confirmar, new ConfirmarTwitterWriter()}, + {Accion.Publicar, new PublicarTwitterWriter()} + }; + _twitterAdapter = twitterAdapter; } - public const int LIMITE_MENSAJE = 140; + private const int LIMITE_MENSAJE = 140; - private string ConsumerKey + private static string ConsumerKey { get { return ConfigurationManager.AppSettings["consumerKeyAppTwitt"]; } } - private string ConsumerSecret + private static string ConsumerSecret { get { return ConfigurationManager.AppSettings["consumerSecretAppTwitt"]; } } - private string AccessToken + private static string AccessToken { get { return ConfigurationManager.AppSettings["accessTokenAppTwitt"]; } } - private string AccessTokenSecret + private static string AccessTokenSecret { get { return ConfigurationManager.AppSettings["accessTokenSecretAppTwitt"]; } } @@ -61,24 +71,13 @@ } } - private static string BuildTwitt(Track track) + private string BuildTwitt(Track track) { - string body = string.Empty; - switch (track.Accion) - { - case Accion.Proponer: - body = "Se ha propuesto un/a nuevo/a " + track.Evento.Tipo; - break; - case Accion.Agendar: - body = "Se ha agendando el evento" + track.Evento.Titulo; - if (track.Evento.Ponente.Twitter != null) - body += " con @" + track.Evento.Ponente.Twitter; - break; - case Accion.Confirmar: - if (track.Evento.Fecha.HasValue) - body = "Se confirma para el " + track.Evento.Fecha.Value.ToShortDateString() + " el evento " + track.Evento.Titulo; - break; - } + ITwitterWriter writer; + if (!_writers.TryGetValue(track.Accion, out writer)) + return string.Empty; + + string body = writer.Write(track); return body.Length > LIMITE_MENSAJE ? body.Substring(0, LIMITE_MENSAJE - 1) : body; }