~ubuntu-branches/ubuntu/karmic/gtwitter/karmic

« back to all changes in this revision

Viewing changes to gtwitter/GetTwitterData.cs

  • Committer: Bazaar Package Importer
  • Author(s): Michael Janssen
  • Date: 2007-08-09 17:14:13 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20070809171413-28ppa0f2oxmr6qyt
Tags: upstream-1.0~beta
ImportĀ upstreamĀ versionĀ 1.0~beta

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
                        }
65
65
                }
66
66
                
 
67
                public bool GetTwitterDirectData(string TwitterDirectUrl, string TwitterName, string TwitterPass, string configDir)
 
68
                {
 
69
                        try {
 
70
                                //HTTP BasicAuth
 
71
                                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(TwitterDirectUrl);
 
72
                            /* setup authentication */
 
73
                            request.PreAuthenticate = true;
 
74
                            NetworkCredential creds = new NetworkCredential(TwitterName, TwitterPass, null);
 
75
                            request.Credentials = creds;
 
76
                            /* setup request paras */
 
77
                                request.ProtocolVersion = HttpVersion.Version10;
 
78
                                request.PreAuthenticate = true;
 
79
                                request.Method = "POST";
 
80
                                request.ContentType = "text/xml";
 
81
                                request.AllowWriteStreamBuffering = true;
 
82
                                /* send response */
 
83
                                Stream stream = request.GetRequestStream();
 
84
                                XmlTextWriter xWriter = new XmlTextWriter(stream, Encoding.ASCII);
 
85
                                xWriter.WriteStartDocument(true);
 
86
                                xWriter.Flush();
 
87
                                xWriter.Close();
 
88
                                /* receive response and parse */
 
89
                                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
 
90
                                Stream responseStream = response.GetResponseStream();
 
91
                                StreamReader input = new StreamReader(responseStream, Encoding.UTF8);
 
92
 
 
93
                                string temp = input.ReadToEnd();
 
94
                                
 
95
                                //save XML
 
96
                                using (TextWriter textwrite = File.CreateText(configDir + "directXML")) {
 
97
                        
 
98
                                        textwrite.WriteLine(temp);
 
99
                                }
 
100
                                
 
101
                                input.Close();
 
102
                                response.Close();
 
103
                                
 
104
                                return true;
 
105
                        }
 
106
                        catch (Exception ex) {
 
107
                                if (MainClass.debug) {
 
108
                                        Console.WriteLine("Get data exception: GetTwitterData.cs - GetTwitterDirectData()");
 
109
                                        Console.WriteLine(ex.StackTrace);
 
110
                                }
 
111
                                
 
112
                                return false;
 
113
                        }
 
114
                }
 
115
                
67
116
                public bool GetTwitterPublicData(string TwitterPublicUrl, string configDir)
68
117
                {
69
118
                        try {
107
156
                        }
108
157
                }
109
158
                
110
 
                public Gdk.Pixbuf GetUserImage(string imageUrl, string configDir)
 
159
                public Gdk.Pixbuf GetUserImage(string imageUrl)
111
160
                {
112
161
                        Gdk.Pixbuf pix1;
113
162
                        
115
164
 
116
165
                                /* read image */
117
166
                                HttpWebRequest req = (HttpWebRequest) WebRequest.Create (imageUrl);
118
 
                                //req.UserAgent = "USERAGENTSTRING HERE";
119
167
                                req.KeepAlive = false;
120
168
                                req.Timeout = 10000;    
121
169
                                WebResponse resp = null;