diff 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
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Twitter/TwitterPublicador.cs	Tue Jun 07 23:21:07 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Twitter/TwitterPublicador.cs	Wed Jun 08 07:33:14 2011 -0300
@@ -1,5 +1,4 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using System.Configuration;
 using AltNetHispano.Agendas.Domain;
 using Twitterizer;
@@ -8,48 +7,77 @@
 {
 	public class TwitterPublicador : IPublicador
 	{
+		public const int LIMITE_MENSAJE = 140;
+
 		private string ConsumerKey
 		{
-			get { return ConfigurationManager.AppSettings["consumerKey"]; }
+			get { return ConfigurationManager.AppSettings["consumerKeyAppTwitt"]; }
 		}
 
 		private string ConsumerSecret
 		{
-			get { return ConfigurationManager.AppSettings["consumerSecret"]; }
+			get { return ConfigurationManager.AppSettings["consumerSecretAppTwitt"]; }
 		}
 
 
 		private string AccessToken
 		{
-			get { return ConfigurationManager.AppSettings["accessToken"]; }
+			get { return ConfigurationManager.AppSettings["accessTokenAppTwitt"]; }
 		}
 
 
 		private string AccessTokenSecret
 		{
-			get { return ConfigurationManager.AppSettings["accessTokenSecret"]; }
+			get { return ConfigurationManager.AppSettings["accessTokenSecretAppTwitt"]; }
 		}
 
 		public void Publicar(IEnumerable<Track> tracks)
 		{
-			throw new NotImplementedException();
+			foreach (var track in tracks)
+			{
+				string message;
+				var twitt = BuildTwitt(track);
+				if (!string.IsNullOrWhiteSpace(twitt))
+					Publicar(twitt, out message);
+			}
 		}
 
-		public bool Publicar (string status, out string message)
+		private static 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;
+			}
+
+			return body.Length > LIMITE_MENSAJE ? body.Substring(0, LIMITE_MENSAJE - 1) : body;
+		}
+
+		public bool Publicar(string status, out string message)
 		{
 			var tokens = new OAuthTokens
-			             	{
-			             		ConsumerKey = ConsumerKey,
-			             		ConsumerSecret = ConsumerSecret,
-			             		AccessToken = AccessToken,
-			             		AccessTokenSecret = AccessTokenSecret
-			             	};
+							{
+								ConsumerKey = ConsumerKey,
+								ConsumerSecret = ConsumerSecret,
+								AccessToken = AccessToken,
+								AccessTokenSecret = AccessTokenSecret
+							};
 
 			var response = TwitterStatus.Update(tokens, status);
 
 			message = response.ErrorMessage;
 			return response.Result == RequestResult.Success;
-
 		}
 	}
 }
\ No newline at end of file