Exemple #1
0
 public sealed override void Start(StreamingAPIParameters p = null)
 {
     try {
         this.request = CreateWebRequest(p);
         StartThread();
     } catch (WebException wex) {
         throw new ApplicationException("Could not start: " + wex.Message, wex);
     }
 }
        protected override HttpWebRequest CreateWebRequest(StreamingAPIParameters p)
        {
            string url     = ConstructUrlWithQueryString(StreamRequestUrl, p);
            var    request = (HttpWebRequest)WebRequest.Create(url);

            request.Method = "GET";

            var header = CreateAuthHeader(request);

            request.Headers.Add("Authorization", header.GetHeaderString());

            return(request);
        }
        protected static string ConstructUrlWithQueryString(string url, StreamingAPIParameters p)
        {
            // This technique create a specialized version of NameValueCollection.
            // Calling its ToString() method yields a correctly encoded querystring.
            var nv = HttpUtility.ParseQueryString(string.Empty);

            if (p != null)
            {
                if (p.Count != 0)
                {
                    nv.Add("count", p.Count.ToString());
                }
                if (p.Delimited != 0)
                {
                    nv.Add("delimited", p.Delimited.ToString());
                }
            }

            return(url + (nv.Count == 0 ? string.Empty : "?" + nv.ToString()));
        }
        protected static NameValueCollection ConstructPostData(StreamingAPIParameters p)
        {
            var postData = new NameValueCollection();

            if (p != null)
            {
                if (p.Count != 0)
                {
                    postData.Add("count", p.Count.ToString());
                }

                if (p.Delimited != 0)
                {
                    postData.Add("delimited", p.Delimited.ToString());
                }

                if (p.Follow.Length != 0)
                {
                    postData.Add("follow", string.Join(",",
                                                       p.Follow.Select(x => x.ToString()).ToArray()));
                }

                if (p.Locations.Length != 0)
                {
                    postData.Add("locations", string.Join(",",
                                                          p.Locations.Select(x => x.ToString()).ToArray()));
                }

                if (p.Track.Length != 0)
                {
                    postData.Add("track", string.Join(",", p.Track));
                }
            }

            return(postData);
        }
        protected override HttpWebRequest CreateWebRequest(StreamingAPIParameters p)
        {
            PostData.Add(ConstructPostData(p));

            var request = (HttpWebRequest)WebRequest.Create(StreamRequestUrl);

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            var header = CreateAuthHeader(request);

            request.Headers.Add("Authorization", header.GetHeaderString());

            using (var sw = new StreamWriter(request.GetRequestStream()))
            {
                string encoded = HttpUtil.EncodeFormPostData(PostData);
                if (!string.IsNullOrEmpty(encoded))
                {
                    sw.Write(encoded);
                }
            }

            return(request);
        }
Exemple #6
0
 /// <summary>
 /// This starts the internal thread that pulls tweets from Twitter via Streaming API.
 /// The tweets are put into internal queue. User has to call Dispatch() in order to fire
 /// EventReceived event that let him/her process tweets.
 /// </summary>
 /// <param name="p"></param>
 public abstract void Start(StreamingAPIParameters p = null);
Exemple #7
0
 protected abstract HttpWebRequest CreateWebRequest(StreamingAPIParameters p);