using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinqToTwitter;
using System.Net;
using System.Web;

namespace Azyobuzi.Twirunrun
{
    public class OAuthEcho
    {
        public OAuthEcho(TwitterContext twCtx)
        {
            this.twCtx = twCtx;
        }

        private TwitterContext twCtx;

        public HttpWebRequest CreateRequest(string uri, string method)
        {
            var req = (HttpWebRequest)WebRequest.Create(uri);
            req.Method = method;
            req.Headers["X-Verify-Credentials-Authorization"] = "OAuth " + string.Join(",",
                HttpUtility.ParseQueryString(
                    twCtx.AuthorizedClient.Get(
                        "https://api.twitter.com/1/account/verify_credentials.json").RequestUri.Query
                    )
                .ToDictionary()
                .Select(_ => string.Format(@"{0}=""{1}""", _.Key, _.Value))
            );
            req.Headers["X-Auth-Service-Provider"] = "https://api.twitter.com/1/account/verify_credentials.json";
            return req;
        }
    }
}
