view Agendas/trunk/src/Agendas.Twitter/oAuthTwitter.cs @ 274:72a96459f910

Ticket #123: Patrocinadores de las vans.
author juanjose.montesdeocaarbos
date Wed, 30 Nov 2011 08:56:01 -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;
		}
	}
}