Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.Twitter/TwitterPublicador.cs @ 158:734d3f0853bf
Manejando configuración de los publicadores con una sección propia en los .config
Agregando la opción de habilitar / deshabilitar un publicador
author | nelopauselli |
---|---|
date | Fri, 05 Aug 2011 16:55:18 -0300 |
parents | 17531db40d4e |
children | beeb48ddb44a |
comparison
equal
deleted
inserted
replaced
157:f17252543cbf | 158:734d3f0853bf |
---|---|
1 using System.Collections.Generic; | 1 using System.Collections.Generic; |
2 using System.Configuration; | |
3 using System.Linq; | 2 using System.Linq; |
3 using AltNetHispano.Agendas.Configurations; | |
4 using AltNetHispano.Agendas.Domain; | 4 using AltNetHispano.Agendas.Domain; |
5 using AltNetHispano.Agendas.Twitter.Writers; | 5 using AltNetHispano.Agendas.Twitter.Writers; |
6 using Twitterizer; | |
7 | 6 |
8 namespace AltNetHispano.Agendas.Twitter | 7 namespace AltNetHispano.Agendas.Twitter |
9 { | 8 { |
10 public class TwitterPublicador : IPublicador | 9 public class TwitterPublicador : IPublicador |
11 { | 10 { |
30 _twitterAdapter = twitterAdapter; | 29 _twitterAdapter = twitterAdapter; |
31 } | 30 } |
32 | 31 |
33 private const int LIMITE_MENSAJE = 140; | 32 private const int LIMITE_MENSAJE = 140; |
34 | 33 |
35 private static string ConsumerKey | |
36 { | |
37 get { return ConfigurationManager.AppSettings["consumerKeyAppTwitt"]; } | |
38 } | |
39 | |
40 private static string ConsumerSecret | |
41 { | |
42 get { return ConfigurationManager.AppSettings["consumerSecretAppTwitt"]; } | |
43 } | |
44 | |
45 | |
46 private static string AccessToken | |
47 { | |
48 get { return ConfigurationManager.AppSettings["accessTokenAppTwitt"]; } | |
49 } | |
50 | |
51 | |
52 private static string AccessTokenSecret | |
53 { | |
54 get { return ConfigurationManager.AppSettings["accessTokenSecretAppTwitt"]; } | |
55 } | |
56 | |
57 public void Publicar(IEnumerable<Track> tracks) | 34 public void Publicar(IEnumerable<Track> tracks) |
58 { | 35 { |
36 if (!AgendasConfigurationManager.Publicadores.Twitter.Enabled) return; | |
37 | |
59 foreach (var track in tracks) | 38 foreach (var track in tracks) |
60 { | 39 { |
61 //Si ya hicimos el twitt de este track, no volvemos a hacerlo | 40 //Si ya hicimos el twitt de este track, no volvemos a hacerlo |
62 if (track.Logs.Any(l => l.Propietario == TrackLogPropietario.Twitter && l.Successful)) continue; | 41 if (track.Logs.Any(l => l.Propietario == TrackLogPropietario.Twitter && l.Successful)) continue; |
63 | 42 |
64 var twitt = BuildTwitt(track); | 43 var twitt = BuildTwitt(track); |
65 if (!string.IsNullOrWhiteSpace(twitt)) | 44 if (!string.IsNullOrWhiteSpace(twitt)) |
66 { | 45 { |
67 string message; | 46 string message; |
68 bool success = Publicar(twitt, out message); | 47 bool success = _twitterAdapter.Update(twitt, out message); |
69 track.LogAdd(new TrackLog(TrackLogPropietario.Twitter, message, track.Usuario, success)); | 48 track.LogAdd(new TrackLog(TrackLogPropietario.Twitter, message, track.Usuario, success)); |
70 } | 49 } |
71 } | 50 } |
72 } | 51 } |
73 | 52 |
79 | 58 |
80 string body = writer.Write(track); | 59 string body = writer.Write(track); |
81 | 60 |
82 return body.Length > LIMITE_MENSAJE ? body.Substring(0, LIMITE_MENSAJE - 1) : body; | 61 return body.Length > LIMITE_MENSAJE ? body.Substring(0, LIMITE_MENSAJE - 1) : body; |
83 } | 62 } |
84 | |
85 public bool Publicar(string status, out string message) | |
86 { | |
87 var tokens = new OAuthTokens | |
88 { | |
89 ConsumerKey = ConsumerKey, | |
90 ConsumerSecret = ConsumerSecret, | |
91 AccessToken = AccessToken, | |
92 AccessTokenSecret = AccessTokenSecret | |
93 }; | |
94 | |
95 var response = _twitterAdapter.UpdateStatus(tokens, status); | |
96 | |
97 message = response.ErrorMessage; | |
98 return response.Result == RequestResult.Success; | |
99 } | |
100 } | 63 } |
101 } | 64 } |