view Agendas/trunk/src/Agendas.Twitter/oAuthTwitter.cs @ 298:9bc60d166c8a

Se corrigieron los tests por el cambio de Patrocinador, para que no persista el logo en disco. Se comentó el código de PatrocinadorApiController, que no se utiliza.
author juanjose.montesdeocaarbos
date Sun, 19 Feb 2012 16:00:38 -0300
parents a7420f05716a
children
line wrap: on
line source

using System;
using System.Collections.Generic;
using System.Web.Script.Serialization; 
using AltNetHispano.Agendas.Configurations;

namespace AltNetHispano.Agendas.Twitter
{
	public class OAuthTwitter
	{
		private readonly ITwitterAdapter _twitterAdapter;

		public OAuthTwitter()
		{
			_twitterAdapter = new TwitterAdapter();
		}

		public OAuthTwitter(ITwitterAdapter twitterAdapter)
		{
			_twitterAdapter = twitterAdapter;
		}

		private string ConsumerKey
		{
			get { return AgendasConfigurationManager.Publicadores.Twitter.SignIn.ConsumerKey; }
		}

		private string ConsumerSecret
		{
			get { return AgendasConfigurationManager.Publicadores.Twitter.SignIn.ConsumerSecret; }
		}

		public Uri AuthorizationLinkGet(string callbackAddress)
		{
			var request = _twitterAdapter.BuildAuthorizationUri(ConsumerKey, ConsumerSecret, callbackAddress);
			return request;
		}

		public string AccessTokenGet(string requestToken, string verifier)
		{
			return _twitterAdapter.GetAccessToken(ConsumerKey, ConsumerSecret, requestToken, verifier);
		}

		public static string GetResponseContent(string response, string tagName)
		{
			var serializer = new JavaScriptSerializer();
			var responseDictionary = (Dictionary<string,object>)serializer.DeserializeObject(response);

			return responseDictionary.ContainsKey(tagName) ? responseDictionary[tagName].ToString() : string.Empty;
		}
	}
}