comparison Agendas/trunk/src/Agendas.Twitter/TwitterPublicador.cs @ 111:90ce239cfa6d

Tests sobre el publicador de twitter, cada track se pulica solo una vez
author Nelo@Kenia.neluz.int
date Wed, 08 Jun 2011 08:40:04 -0300
parents a456eb519e23
children c3573defd18f
comparison
equal deleted inserted replaced
110:a456eb519e23 111:90ce239cfa6d
1 using System.Collections.Generic; 1 using System.Collections.Generic;
2 using System.Configuration; 2 using System.Configuration;
3 using System.Linq;
3 using AltNetHispano.Agendas.Domain; 4 using AltNetHispano.Agendas.Domain;
4 using Twitterizer; 5 using Twitterizer;
5 6
6 namespace AltNetHispano.Agendas.Twitter 7 namespace AltNetHispano.Agendas.Twitter
7 { 8 {
8 public class TwitterPublicador : IPublicador 9 public class TwitterPublicador : IPublicador
9 { 10 {
11 private readonly ITwitterAdapter _twitterAdapter;
12
13 public TwitterPublicador()
14 {
15 _twitterAdapter = new TwitterAdapter();
16 }
17
18 public TwitterPublicador(ITwitterAdapter twitterAdapter)
19 {
20 _twitterAdapter = twitterAdapter;
21 }
22
10 public const int LIMITE_MENSAJE = 140; 23 public const int LIMITE_MENSAJE = 140;
11 24
12 private string ConsumerKey 25 private string ConsumerKey
13 { 26 {
14 get { return ConfigurationManager.AppSettings["consumerKeyAppTwitt"]; } 27 get { return ConfigurationManager.AppSettings["consumerKeyAppTwitt"]; }
33 46
34 public void Publicar(IEnumerable<Track> tracks) 47 public void Publicar(IEnumerable<Track> tracks)
35 { 48 {
36 foreach (var track in tracks) 49 foreach (var track in tracks)
37 { 50 {
38 string message; 51 //Si ya hicimos el twitt de este track, no volvemos a hacerlo
52 if (track.Logs.Any(l => l.Propietario == TrackLogPropietario.Twitter)) continue;
53
39 var twitt = BuildTwitt(track); 54 var twitt = BuildTwitt(track);
40 if (!string.IsNullOrWhiteSpace(twitt)) 55 if (!string.IsNullOrWhiteSpace(twitt))
56 {
57 string message;
41 Publicar(twitt, out message); 58 Publicar(twitt, out message);
59 track.LogAdd(new TrackLog(TrackLogPropietario.Twitter, message));
60 }
42 } 61 }
43 } 62 }
44 63
45 private static string BuildTwitt(Track track) 64 private static string BuildTwitt(Track track)
46 { 65 {
72 ConsumerSecret = ConsumerSecret, 91 ConsumerSecret = ConsumerSecret,
73 AccessToken = AccessToken, 92 AccessToken = AccessToken,
74 AccessTokenSecret = AccessTokenSecret 93 AccessTokenSecret = AccessTokenSecret
75 }; 94 };
76 95
77 var response = TwitterStatus.Update(tokens, status); 96 var response = _twitterAdapter.UpdateStatus(tokens, status);
78 97
79 message = response.ErrorMessage; 98 message = response.ErrorMessage;
80 return response.Result == RequestResult.Success; 99 return response.Result == RequestResult.Success;
81 } 100 }
82 } 101 }