Mercurial > altnet-hispano
changeset 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 | 6bd9be78caa0 |
children | 90ce239cfa6d |
files | Agendas/trunk/src/Agendas.Factories/AgendaFactory.cs Agendas/trunk/src/Agendas.Factories/Agendas.Factories.csproj Agendas/trunk/src/Agendas.Twitter.Tests/App.config Agendas/trunk/src/Agendas.Twitter.Tests/Send_twitt_tests.cs Agendas/trunk/src/Agendas.Twitter/TwitterPublicador.cs Agendas/trunk/src/Agendas.Twitter/oAuthTwitter.cs Agendas/trunk/src/Agendas.Web/Web.config |
diffstat | 7 files changed, 69 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Factories/AgendaFactory.cs Tue Jun 07 23:21:07 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Factories/AgendaFactory.cs Wed Jun 08 07:33:14 2011 -0300 @@ -1,9 +1,9 @@ -using System; -using Agendas.NHibernate; +using Agendas.NHibernate; using AltNetHispano.Agendas.Domain; using AltNetHispano.Agendas.Domain.Repositories; using AltNetHispano.Agendas.Domain.Services; using AltNetHispano.Agendas.Repositories.NHibernate; +using AltNetHispano.Agendas.Twitter; using NHibernate; @@ -16,7 +16,10 @@ public static Agenda GetAgenda() { ISessionFactory sessionFactory = NhHelper.GetSessionFactory(); - return _agenda ?? (_agenda = new Agenda(null, new EventoRepository(sessionFactory), new PersonaRepository(sessionFactory))); + return _agenda ?? + (_agenda = + new Agenda(new TwitterPublicador(), new EventoRepository(sessionFactory), + new PersonaRepository(sessionFactory))); } public static IPersonaRepository GetPersonaRepository()
--- a/Agendas/trunk/src/Agendas.Factories/Agendas.Factories.csproj Tue Jun 07 23:21:07 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Factories/Agendas.Factories.csproj Wed Jun 08 07:33:14 2011 -0300 @@ -61,6 +61,10 @@ <Project>{0973DF44-3B90-4D2A-B579-C64C93B6C853}</Project> <Name>Agendas.Repositories.NHibernate</Name> </ProjectReference> + <ProjectReference Include="..\Agendas.Twitter\Agendas.Twitter.csproj"> + <Project>{D8DA7ED2-A274-4DF6-9DD2-A9DC65F4C2F5}</Project> + <Name>Agendas.Twitter</Name> + </ProjectReference> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
--- a/Agendas/trunk/src/Agendas.Twitter.Tests/App.config Tue Jun 07 23:21:07 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Twitter.Tests/App.config Wed Jun 08 07:33:14 2011 -0300 @@ -1,9 +1,9 @@ <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> - <add key="consumerKey" value="UpwG7RKRAqQfdsCKnBfHA"/> - <add key="consumerSecret" value="HIOb9tMewejyFX97mhsQO2FXSEQN4kzJFF6iQLx4k"/> - <add key="accessToken" value="301500900-1GGyiecfAgmbrJMEcjp4XA9KXEJU2bBLyEQNQL5S" /> - <add key="accessTokenSecret" value="46vNqg4djzyh9GRtZoUv0c7uEl7mQ3CjVBeJ4wwRpds"/> + <add key="consumerKeyAppTwitt" value="UpwG7RKRAqQfdsCKnBfHA"/> + <add key="consumerSecretAppTwitt" value="HIOb9tMewejyFX97mhsQO2FXSEQN4kzJFF6iQLx4k"/> + <add key="accessTokenAppTwitt" value="301500900-1GGyiecfAgmbrJMEcjp4XA9KXEJU2bBLyEQNQL5S" /> + <add key="accessTokenSecretAppTwitt" value="46vNqg4djzyh9GRtZoUv0c7uEl7mQ3CjVBeJ4wwRpds"/> </appSettings> </configuration> \ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Twitter.Tests/Send_twitt_tests.cs Tue Jun 07 23:21:07 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Twitter.Tests/Send_twitt_tests.cs Wed Jun 08 07:33:14 2011 -0300 @@ -1,12 +1,6 @@ using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Text; using AltNetHispano.Agendas.Twitter; using NUnit.Framework; -using Twitterizer; namespace Agendas.Twitter.Tests { @@ -19,7 +13,7 @@ var p = new TwitterPublicador(); string message; - var r = p.Publicar("Hello, #Twitterizer. Hora: " + DateTime.Now, out message); + var r = p.Publicar("Ejecutando los tests. Hora: " + DateTime.Now, out message); Console.WriteLine(message); Assert.IsTrue(r);
--- 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
--- a/Agendas/trunk/src/Agendas.Twitter/oAuthTwitter.cs Tue Jun 07 23:21:07 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Twitter/oAuthTwitter.cs Wed Jun 08 07:33:14 2011 -0300 @@ -8,12 +8,12 @@ { private string ConsumerKey { - get { return ConfigurationManager.AppSettings["consumerKey"]; } + get { return ConfigurationManager.AppSettings["consumerKeyAppSignIn"]; } } private string ConsumerSecret { - get { return ConfigurationManager.AppSettings["consumerSecret"]; } + get { return ConfigurationManager.AppSettings["consumerSecretAppSignIn"]; } } public Uri AuthorizationLinkGet(string callbackAddress) @@ -30,6 +30,7 @@ public string AccessTokenGet(string requestToken, string verifier) { OAuthTokenResponse accessToken = OAuthUtility.GetAccessToken(ConsumerKey, ConsumerSecret, requestToken, verifier); + if (accessToken!=null) { var tokens = new OAuthTokens
--- a/Agendas/trunk/src/Agendas.Web/Web.config Tue Jun 07 23:21:07 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Web.config Wed Jun 08 07:33:14 2011 -0300 @@ -11,9 +11,14 @@ </connectionStrings> <appSettings> - <add key="consumerKey" value="uUSzC5EZ2LCNoBmaQXcUFA"/> - <add key="consumerSecret" value="CNN2uUwza4nGNoZf3FlAqC0xoUEKXKFWxZn3Frow"/> - + <add key="consumerKeyAppSignIn" value="uUSzC5EZ2LCNoBmaQXcUFA"/> + <add key="consumerSecretAppSignIn" value="CNN2uUwza4nGNoZf3FlAqC0xoUEKXKFWxZn3Frow"/> + + <add key="consumerKeyAppTwitt" value="UpwG7RKRAqQfdsCKnBfHA"/> + <add key="consumerSecretAppTwitt" value="HIOb9tMewejyFX97mhsQO2FXSEQN4kzJFF6iQLx4k"/> + <add key="accessTokenAppTwitt" value="301500900-1GGyiecfAgmbrJMEcjp4XA9KXEJU2bBLyEQNQL5S" /> + <add key="accessTokenSecretAppTwitt" value="46vNqg4djzyh9GRtZoUv0c7uEl7mQ3CjVBeJ4wwRpds"/> + <add key="ClientValidationEnabled" value="true"/> <add key="UnobtrusiveJavaScriptEnabled" value="true"/> </appSettings>