public TwitterOAuthMessageHandler(OAuthCredential oAuthCredential, OAuthSignatureEntity signatureEntity,
            TwitterQueryCollection parameters, HttpMessageHandler innerHandler)
            : base(innerHandler)
        {
            //TODO: Parameters needs to come here as encoded so that they can be encoded twice
            //      for the signature base. Handle that.

            //TODO: We don't even need to get parameters seperately. We can get them through
            //      query string and by reading the body but reading the body is a overhead here.

            _oAuthState = new OAuthState() {
                Credential = new OAuthCredentialState() {
                    ConsumerKey = oAuthCredential.ConsumerKey,
                    //encode it here first
                    CallbackUrl = OAuthUtil.PercentEncode(oAuthCredential.CallbackUrl),
                    Token = oAuthCredential.Token
                },
                SignatureEntity = new OAuthSignatureEntityState() {
                    ConsumerSecret = signatureEntity.ConsumerSecret,
                    TokenSecret = signatureEntity.TokenSecret
                },
                Parameters = parameters,
                Nonce = GenerateNonce(),
                SignatureMethod = GetOAuthSignatureMethod(),
                Timestamp = GenerateTimestamp(),
                Version = GetVersion()
            };
        }
Ejemplo n.º 2
0
        public Task <HttpResponseMessage> GetLocationBasedConnection(string location)
        {
            if (_httpClient != null)
            {
                throw new NotSupportedException("Multiple connections with one instance of TwitterConnector is not allowed");
            }

            TwitterQueryCollection collection = new TwitterQueryCollection();

            //{southwest}long,lat,{northeast}long,lat
            //The polygon which covers the whole world
            //collection.Add("locations", "-165.0,-75.0,165.0,75.0");
            collection.Add("locations", location);

            _httpClient         = new TwitterHttpClient(_creds, _signatureEntity, collection);
            _httpClient.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);

            var filterContent = new StringContent(collection.ToString());

            filterContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
            var filterRequest = new HttpRequestMessage(HttpMethod.Post, filterEndpointUri);

            filterRequest.Content = filterContent;

            return(_httpClient.SendAsync(filterRequest, HttpCompletionOption.ResponseHeadersRead));
        }
        public TwitterHttpClient(OAuthCredential oAuthCredential, OAuthSignatureEntity oAuthSignatureEntity,
            TwitterQueryCollection queryCollection)
            : base(new TwitterOAuthMessageHandler(oAuthCredential, oAuthSignatureEntity, queryCollection, new HttpClientHandler()))
        {
            if (oAuthCredential == null) {
                throw new NullReferenceException("oAuthCredential");
            }

            if (oAuthSignatureEntity == null) {
                throw new NullReferenceException("signatureEntity");
            }

            _oAuthCredential = oAuthCredential;
            _twitterQueryCollection = queryCollection;
            _oAuthSignatureEntity = oAuthSignatureEntity;
        }
Ejemplo n.º 4
0
        public Task<HttpResponseMessage> GetLocationBasedConnection(string location)
        {
            if (_httpClient != null) {
                throw new NotSupportedException("Multiple connections with one instance of TwitterConnector is not allowed");
            }

            TwitterQueryCollection collection = new TwitterQueryCollection();
            //{southwest}long,lat,{northeast}long,lat
            //The polygon which covers the whole world
            //collection.Add("locations", "-165.0,-75.0,165.0,75.0");
            collection.Add("locations", location);

            _httpClient = new TwitterHttpClient(_creds, _signatureEntity, collection);
            _httpClient.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);

            var filterContent = new StringContent(collection.ToString());
            filterContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
            var filterRequest = new HttpRequestMessage(HttpMethod.Post, filterEndpointUri);
            filterRequest.Content = filterContent;

            return _httpClient.SendAsync(filterRequest, HttpCompletionOption.ResponseHeadersRead);
        }
 //TODO: Get rid of this! They already one
 //      OOB you smart-ass: FormUrlEncodedContent
 public TwitterQueryContent(TwitterQueryCollection collection)
     : base(collection.ToString())
 {
     this.Headers.ContentType = MediaTypeConstants.ApplicationFormUrlEncodedMediaType;
 }