You are suppose to post it on a code repository site (like CodePlex or
Google Code), then post a link to it here.  Nobody wants 300 lines of code
in their emails.

Ryan

On Thu, Nov 12, 2009 at 2:03 PM, ch...@stuffworldwide.com <
ch...@stuffworldwide.com> wrote:

> I sent it to the twitter people to post on their site but they asked
> me to post here as well... I was like... okay
>
> On Nov 10, 5:53 pm, Andrew Badera <and...@badera.us> wrote:
> > I for one tend to prefer Google Code or Code Plex for posting lengthy
> > chunks of code intended for resharing ...
> >
> > Also, LinqToTwitter is a pretty solid reference implementation ...
> > FWIW. (Not affiliated, just a user.)
> >
> > ∞ Andy Badera
> > ∞ +1 518-641-1280 Google Voice
> > ∞ This email is: [ ] bloggable [x] ask first [ ] private
> > ∞ Google me:http://www.google.com/search?q=andrew%20badera
> >
> > On Tue, Nov 10, 2009 at 5:49 PM, ch...@stuffworldwide.com
> >
> >
> >
> > <ch...@stuffworldwide.com> wrote:
> >
> > > Not many .NETexamples out there... here it is... have fun...
> >
> > > using System;
> >
> > > using System.Text;
> >
> > > using System.Net;
> >
> > > using System.IO;
> >
> > > using System.Xml;
> >
> > > namespace Tweeter
> >
> > > {
> >
> > >      public class TwitterTools
> >
> > >      {
> >
> > >            #region Members
> >
> > >            #endregion
> >
> > >            public TwitterTools()
> >
> > >            {
> >
> > >                  this.Initialize();
> >
> > >            }
> >
> > >            public TwitterTools(string userName,string password)
> >
> > >            {
> >
> > >                  this.UserName=userName;
> >
> > >                  this.Password=password;
> >
> > >                  this.Initialize();
> >
> > >            }
> >
> > >            private void Initialize()
> >
> > >            {
> >
> > >            }
> >
> > >            public void Dispose()
> >
> > >            {
> >
> > >            }
> >
> > >            #region Properties
> >
> > >            public string UserName=null;
> >
> > >            public string Password=null;
> >
> > >            #endregion
> >
> > >            #region Methods
> >
> > >            public int Update(string message)
> >
> > >            {
> >
> > >                  int retval=0;
> >
> > >                  string code=null;
> >
> > >                  string url="http://twitter.com/account/
> > > rate_limit_status.xml";      //gen.Get("twitterRateService");
> >
> > >                  string result=null;
> >
> > >                  try
> >
> > >                  {
> >
> > >                        result=this.Request(url + "?"
> >
> > >                              ,null
> >
> > >                              ,"GET"
> >
> > >                              );
> >
> > > //                      gen.Test(result);
> >
> > >                  }
> >
> > >                  catch
> >
> > >                  {
> >
> > >                        result=null;
> >
> > >                  }
> >
> > >                  if(result==null)
> >
> > >                        retval=2;
> >
> > >                  else
> >
> > >                  {
> >
> > >                        //parse results
> >
> > >                        try
> >
> > >                        {
> >
> > >                              XmlDocument doc=new XmlDocument();
> >
> > >                              doc.LoadXml(result);
> >
> > >                              XmlNodeList nodes=doc.SelectNodes("/hash/
> > > remaining-hits");
> >
> > >                              int remaining=System.Convert.ToInt32
> > > (nodes[0].InnerText);
> >
> > >                              if(remaining<=0)
> >
> > >                                    retval=2;
> >
> > >                              nodes=null;
> >
> > >                              doc=null;
> >
> > >                        }
> >
> > >                        catch
> >
> > >                        {
> >
> > >                              retval=2;
> >
> > >                        }
> >
> > >                        if(retval!=2)
> >
> > >                        {
> >
> > >                              StringBuilder txt=new StringBuilder();
> >
> > >                              txt.Append("status=");
> >
> > >                              txt.Append(message);
> >
> > >                              code=txt.ToString();
> >
> > >                              try
> >
> > >                              {
> >
> > >                                    string ret=this.Request("http://
> > > twitter.com/statuses/update.xml"//gen.Get("twitterUpdateService")
> >
> > >                                          ,code);
> >
> > >                                    if(ret!=null)
> >
> > >                                          retval=1;
> >
> > >                                    else
> >
> > >                                          retval=0;
> >
> > >                              }
> >
> > >                              catch
> >
> > >                              {
> >
> > >                                    retval=0;
> >
> > >                              }
> >
> > >                        }
> >
> > >                  }
> >
> > >                  return retval;
> >
> > >            }
> >
> > >            private string Request(string url,string code)
> >
> > >            {
> >
> > >                  return this.Request(url,code,"POST");
> >
> > >            }
> >
> > >            private string Request(string url,string code,string
> > > method)
> >
> > >            {
> >
> > >                  byte[] bytes=null;
> >
> > >                  if(code!=null)
> >
> > >                        bytes=System.Text.Encoding.ASCII.GetBytes
> > > (code);
> >
> > >                  string logon=null;
> >
> > >                  if(code==null)
> >
> > >                        logon="Basic " + this.UserName + ":" +
> > > this.Password;
> >
> > >                  else
> >
> > >                        logon=this.UserName + ":" + this.Password;
> >
> > >                  logon=System.Convert.ToBase64String
> > > (System.Text.Encoding.UTF8.GetBytes(logon));
> >
> > >                  //request
> >
> > >                  HttpWebRequest req=(HttpWebRequest)WebRequest.Create
> > > (url);
> >
> > >                  req.Timeout=10000;
> >
> > >                  //req.Timeout=System.Convert.ToInt32(gen.Get
> > > ("twitterTimeout"));
> >
> > >                  if(code==null)
> >
> > >                        req.Headers.Add("Authorization",logon);
> >
> > >                  else
> >
> > >                        req.Headers.Add("Authorization","Basic " +
> > > logon);
> >
> > >                  req.ServicePoint.Expect100Continue=false;
> >
> > >                  if(code!=null)
> >
> > >                  {
> >
> > >                        req.ContentType="application/x-www-form-
> > > urlencoded";
> >
> > >                        req.Method=method;
> >
> > >                        req.ContentLength=code==null ? 0 :
> > > bytes.Length;
> >
> > >                        Stream trans=req.GetRequestStream();
> >
> > >                        trans.Write(bytes,0,bytes.Length);
> >
> > >                        trans.Close();
> >
> > >                  }
> >
> > >                  //get response
> >
> > >                  string result=null;
> >
> > >                  try
> >
> > >                  {
> >
> > >                        HttpWebResponse resp=(HttpWebResponse)
> > > req.GetResponse();
> >
> > >                        StreamReader sr=new StreamReader
> > > (resp.GetResponseStream(),Encoding.GetEncoding(1252));
> >
> > >                        //get results
> >
> > >                        result=sr.ReadToEnd();
> >
> > >                        resp.Close();
> >
> > >                  }
> >
> > >                  catch(WebException ex)
> >
> > >                  {
> >
> > >                        HttpWebResponse resp=((HttpWebResponse)
> > > ex.Response);
> >
> > >                        string test=resp.StatusCode.ToString();
> >
> > > //                      gen.Test("! - Twitter query return error code:
> > > " + test);
> >
> > >                        result=null;
> >
> > >                  }
> >
> > >                  catch(Exception ex)
> >
> > >                  {
> >
> > > //                      gen.Test("! - " + ex.Message);
> >
> > >                        result=null;
> >
> > >                  }
> >
> > >                  return result;
> >
> > >            }
> >
> > >            #endregion
> >
> > >      }
> >
> > > }- Hide quoted text -
> >
> > - Show quoted text -

Reply via email to