[Pkg-cli-apps-commits] r4971 - in /packages/gnome-do-plugins/trunk/debian: changelog patches/00list patches/20_twitter_overflow.dpatch
laney-guest at users.alioth.debian.org
laney-guest at users.alioth.debian.org
Mon Jun 15 23:29:53 UTC 2009
Author: laney-guest
Date: Mon Jun 15 23:29:53 2009
New Revision: 4971
URL: http://svn.debian.org/wsvn/pkg-cli-apps/?sc=1&rev=4971
Log:
debian/patches/20_twitter_overflow.dpatch: Backport patch from upstream
bzr to fix broken Twitter message sending. The number of messages posted
to Twitter has overflowed the size of an int(!), so these variables have
been converted to longs.
Added:
packages/gnome-do-plugins/trunk/debian/patches/20_twitter_overflow.dpatch (with props)
Modified:
packages/gnome-do-plugins/trunk/debian/changelog
packages/gnome-do-plugins/trunk/debian/patches/00list
Modified: packages/gnome-do-plugins/trunk/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-cli-apps/packages/gnome-do-plugins/trunk/debian/changelog?rev=4971&op=diff
==============================================================================
--- packages/gnome-do-plugins/trunk/debian/changelog (original)
+++ packages/gnome-do-plugins/trunk/debian/changelog Mon Jun 15 23:29:53 2009
@@ -1,3 +1,12 @@
+gnome-do-plugins (0.8.1.3+dfsg-3) UNRELEASED; urgency=low
+
+ * debian/patches/20_twitter_overflow.dpatch: Backport patch from upstream
+ bzr to fix broken Twitter message sending. The number of messages posted
+ to Twitter has overflowed the size of an int(!), so these variables have
+ been converted to longs.
+
+ -- Iain Lane <laney at ubuntu.com> Tue, 16 Jun 2009 00:15:15 +0100
+
gnome-do-plugins (0.8.1.3+dfsg-2) unstable; urgency=low
* debian/patches/00_use_system_gdata.dpatch: Patch build system to use
Modified: packages/gnome-do-plugins/trunk/debian/patches/00list
URL: http://svn.debian.org/wsvn/pkg-cli-apps/packages/gnome-do-plugins/trunk/debian/patches/00list?rev=4971&op=diff
==============================================================================
--- packages/gnome-do-plugins/trunk/debian/patches/00list (original)
+++ packages/gnome-do-plugins/trunk/debian/patches/00list Mon Jun 15 23:29:53 2009
@@ -3,3 +3,4 @@
04_fix_pidgin_dbus_ints
10_fix_rhythmbox_file
15_twitter_api
+20_twitter_overflow
Added: packages/gnome-do-plugins/trunk/debian/patches/20_twitter_overflow.dpatch
URL: http://svn.debian.org/wsvn/pkg-cli-apps/packages/gnome-do-plugins/trunk/debian/patches/20_twitter_overflow.dpatch?rev=4971&op=file
==============================================================================
--- packages/gnome-do-plugins/trunk/debian/patches/20_twitter_overflow.dpatch (added)
+++ packages/gnome-do-plugins/trunk/debian/patches/20_twitter_overflow.dpatch Mon Jun 15 23:29:53 2009
@@ -1,0 +1,662 @@
+#! /bin/sh /usr/share/dpatch/dpatch-run
+## 15_twitter_api_overflow.dpatch by Iain Lane <laney at ubuntu.com>
+##
+## All lines beginning with `## DP:' are a description of the patch.
+## DP: No description.
+
+ at DPATCH@
+diff -urNad gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/MicroblogClient.cs gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/MicroblogClient.cs
+--- gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/MicroblogClient.cs 2009-03-17 17:56:56.000000000 +0000
++++ gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/MicroblogClient.cs 2009-06-15 23:48:45.000000000 +0100
+@@ -97,7 +97,7 @@
+ UpdateStatus (status, null);
+ }
+
+- public void UpdateStatus (string status, Nullable<int> inReplyToID)
++ public void UpdateStatus (string status, Nullable<long> inReplyToID)
+ {
+ string errorMessage = "";
+ try {
+diff -urNad gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/MicroblogClient.cs.orig gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/MicroblogClient.cs.orig
+--- gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/MicroblogClient.cs.orig 1970-01-01 01:00:00.000000000 +0100
++++ gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/MicroblogClient.cs.orig 2009-03-17 17:56:56.000000000 +0000
+@@ -0,0 +1,251 @@
++/* MicroblogClient.cs
++ *
++ * GNOME Do is the legal property of its developers. Please refer to the
++ * COPYRIGHT file distributed with this
++ * source distribution.
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation, either version 3 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program. If not, see <http://www.gnu.org/licenses/>.
++ */
++
++using System;
++using System.IO;
++using System.Net;
++using System.Linq;
++using System.Threading;
++using System.Collections.Generic;
++
++using Mono.Unix;
++
++using Twitterizer.Framework;
++
++using Do.Platform;
++using Do.Universe;
++
++namespace Microblogging
++{
++
++ public class MicroblogClient
++ {
++ #region Class constants, error messages
++
++ readonly string DownloadFailedMsg = Catalog.GetString ("Failed to fetch file from {0}");
++ readonly string GenericErrorMsg = Catalog.GetString ("Twitter encountered an error in {0}. {1}");
++
++ readonly string FailedPostMsg = Catalog.GetString ("Unable to post tweet. Check your login settings. If you "
++ + "are behind a proxy make sure that the settings in /system/http_proxy are correct.");
++
++ const int UpdateTimelineTimeout = 30 * 1000;
++ const int UpdateContactsTimeout = 10 * 60 * 1000;
++ const int CheckForMessagesTimeout = 5 * 60 * 1000;
++
++ #endregion
++
++ Twitter blog;
++ string username;
++ DateTime timeline_last_updated, messages_last_updated;
++
++ Timer [] timers;
++
++ public IEnumerable<FriendItem> Contacts { get; private set; }
++
++ static MicroblogClient ()
++ {
++ PhotoDirectory = new [] { Services.Paths.UserDataDirectory, "Microblogging", "photos"}.Aggregate (Path.Combine);
++ }
++
++ public MicroblogClient (string username, string password, Service service)
++ {
++ timers = new Timer [3];
++ this.username = username;
++ Contacts = Enumerable.Empty<FriendItem> ();
++ blog = new Twitter (username, password, service);
++ timeline_last_updated = messages_last_updated = DateTime.UtcNow;
++
++ timers [0] = new Timer (UpdateContacts, null, 1 * 1000, UpdateContactsTimeout);
++ timers [1] = new Timer (UpdateTimeline, null, 60 *1000, UpdateTimelineTimeout);
++ timers [2] = new Timer (CheckForMessages, null, 120 * 1000, CheckForMessagesTimeout);
++ }
++
++ /// <value>
++ /// The ContactItem key that contains the user's microblogging screen name
++ /// </value>
++ public static string ContactKeyName {
++ get { return "microblog.screenname"; }
++ }
++
++ public static readonly string PhotoDirectory;
++
++ /// <summary>
++ /// Update your miroblogging status
++ /// </summary>
++ /// <param name="status">
++ /// A <see cref="System.String"/> status message
++ /// </param>
++ public void UpdateStatus (string status)
++ {
++ UpdateStatus (status, null);
++ }
++
++ public void UpdateStatus (string status, Nullable<int> inReplyToID)
++ {
++ string errorMessage = "";
++ try {
++ blog.Status.Update (status, inReplyToID);
++ } catch (TwitterizerException e) {
++ errorMessage = FailedPostMsg;
++ Log<MicroblogClient>.Debug (GenericErrorMsg, "Post", e.Message);
++ }
++
++ OnStatusUpdated (status, errorMessage);
++ }
++
++ void UpdateContacts (object o)
++ {
++ FriendItem newContact;
++ MicroblogStatus status;
++ List<FriendItem> newContacts;
++ TwitterUserCollection friends;
++
++ try {
++ newContacts = new List<FriendItem> ();
++ friends = blog.User.Friends ();
++ } catch (TwitterizerException e) {
++ Log<MicroblogClient>.Debug (GenericErrorMsg, "UpdateContacts", e.Message);
++ return;
++ }
++
++ foreach (TwitterUser friend in friends) {
++ if (friend.Status != null) {
++ status = new MicroblogStatus (friend.Status.ID, friend.Status.Text, friend.ScreenName, friend.Status.Created);
++ newContact = new FriendItem (friend.ID, friend.ScreenName, status);
++ } else {
++ newContact = new FriendItem (friend.ID, friend.ScreenName);
++ }
++
++ newContacts.Add (newContact);
++ }
++
++ Contacts = newContacts;
++ Log<MicroblogClient>.Debug ("Found {0} contacts", Contacts.Count ());
++ return;
++ }
++
++ void UpdateTimeline (object o)
++ {
++ string icon = "";
++ TwitterStatus tweet;
++ TwitterParameters parameters;
++
++ try {
++ // get the most recent update
++ parameters = new TwitterParameters ();
++ parameters.Add (TwitterParameterNames.Count, 1);
++ tweet = blog.Status.FriendsTimeline (parameters) [0];
++
++ if (tweet.TwitterUser.ScreenName.Equals (username) || tweet.Created <= timeline_last_updated)
++ return;
++
++ icon = FindIconForUser (tweet.TwitterUser);
++ timeline_last_updated = tweet.Created;
++
++ OnTimelineUpdated (tweet.TwitterUser.ScreenName, tweet.Text, icon);
++
++ Contacts.Where (contact => contact.Id == tweet.TwitterUser.ID)
++ .First ()
++ .AddStatus (new MicroblogStatus (tweet.ID, tweet.Text, tweet.TwitterUser.ScreenName, tweet.Created));
++ } catch (Exception e) {
++ Log<MicroblogClient>.Debug (GenericErrorMsg, "UpdateTimeline", e.Message);
++ }
++ }
++
++ void CheckForMessages (object o)
++ {
++ string icon = "";
++ TwitterStatus message;
++ TwitterParameters parameters;
++
++ try {
++ // get the most recent update
++ parameters = new TwitterParameters ();
++ parameters.Add (TwitterParameterNames.Count, 1);
++ message = blog.DirectMessages.DirectMessages (parameters) [0];
++
++ if (message.Created <= messages_last_updated) return;
++
++ messages_last_updated = message.Created;
++ icon = FindIconForUser (message.TwitterUser);
++
++ OnMessageFound (message.TwitterUser.ScreenName, message.Text, icon);
++ } catch (Exception e) {
++ Log<MicroblogClient>.Debug (GenericErrorMsg, "CheckForMessages", e.Message);
++ }
++ }
++
++ string FindIconForUser (TwitterUser user)
++ {
++ string icon = "";
++
++ if (File.Exists (Path.Combine (PhotoDirectory, "" + user.ID)))
++ icon = Path.Combine (PhotoDirectory, "" + user.ID);
++ else
++ DownloadBuddyIcon (user);
++
++ return icon;
++ }
++
++ void DownloadBuddyIcon (TwitterUser user)
++ {
++ string imageDestination;
++ imageDestination = Path.Combine (PhotoDirectory, "" + user.ID);
++
++ if (File.Exists (imageDestination)) return;
++ if (!Directory.Exists (PhotoDirectory)) Directory.CreateDirectory (PhotoDirectory);
++
++ using (WebClient client = new WebClient ())
++ {
++ try {
++ client.DownloadFile (user.ProfileImageUri.AbsoluteUri, imageDestination);
++ } catch (Exception e) {
++ Log.Error (string.Format (DownloadFailedMsg, user.ProfileImageUri.AbsoluteUri), e.Message);
++ Log.Debug (e.StackTrace);
++ }
++ }
++ }
++
++ void OnStatusUpdated (string status, string errorMessage)
++ {
++ if (StatusUpdated != null)
++ Gtk.Application.Invoke ((o, e) => StatusUpdated (this, new StatusUpdatedEventArgs (status, errorMessage)));
++ }
++
++ void OnTimelineUpdated (string screenname, string status, string icon)
++ {
++ if (TimelineUpdated != null)
++ Gtk.Application.Invoke ((o, e) => TimelineUpdated (this, new TimelineUpdatedEventArgs (screenname, status, icon)));
++ }
++
++ void OnMessageFound (string screenname, string status, string icon)
++ {
++ if (MessageFound != null)
++ Gtk.Application.Invoke ((o, e) => MessageFound (this, new TimelineUpdatedEventArgs (screenname, status, icon)));
++ }
++
++ public event StatusUpdatedDelegate StatusUpdated;
++ public event TimelineUpdatedDelegate MessageFound;
++ public event TimelineUpdatedDelegate TimelineUpdated;
++
++ public delegate void StatusUpdatedDelegate (object sender, StatusUpdatedEventArgs args);
++ public delegate void TimelineUpdatedDelegate (object sender, TimelineUpdatedEventArgs args);
++ }
++}
+diff -urNad gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/MicroblogStatus.cs gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/MicroblogStatus.cs
+--- gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/MicroblogStatus.cs 2009-03-17 17:56:56.000000000 +0000
++++ gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/MicroblogStatus.cs 2009-06-15 23:48:45.000000000 +0100
+@@ -8,7 +8,7 @@
+
+ public class MicroblogStatus : Item
+ {
+- public MicroblogStatus (int id, string status, string owner, DateTime time)
++ public MicroblogStatus (long id, string status, string owner, DateTime time)
+ {
+ Id = id;
+ Owner = owner;
+@@ -28,7 +28,7 @@
+ get { return "microblogging.svg@" + GetType ().Assembly.FullName; }
+ }
+
+- public int Id { get; private set; }
++ public long Id { get; private set; }
+ public string Owner { get; private set; }
+ public string Status { get; private set; }
+ public DateTime Created { get; private set; }
+@@ -36,13 +36,13 @@
+
+ public class MicroblogStatusReply
+ {
+- public MicroblogStatusReply (Nullable<int> inReplyToID, string status)
++ public MicroblogStatusReply (Nullable<long> inReplyToID, string status)
+ {
+ Status = status;
+ InReplyToId = inReplyToID;
+ }
+
+- public Nullable<int> InReplyToId { get; private set; }
++ public Nullable<long> InReplyToId { get; private set; }
+ public string Status { get; private set; }
+ }
+ }
+diff -urNad gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/Twitterizer/Twitterizer.Framework/DataTransferObjects/TwitterStatus.cs gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/Twitterizer/Twitterizer.Framework/DataTransferObjects/TwitterStatus.cs
+--- gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/Twitterizer/Twitterizer.Framework/DataTransferObjects/TwitterStatus.cs 2009-03-17 17:56:56.000000000 +0000
++++ gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/Twitterizer/Twitterizer.Framework/DataTransferObjects/TwitterStatus.cs 2009-06-15 23:48:45.000000000 +0100
+@@ -40,8 +40,8 @@
+ set { created = value; }
+ }
+
+- private int id;
+- public int ID
++ private long id;
++ public long ID
+ {
+ get { return id; }
+ set { id = value; }
+@@ -82,8 +82,8 @@
+ set { isFavorited = value; }
+ }
+
+- private int inReplyToStatusID;
+- public int InReplyToStatusID
++ private long inReplyToStatusID;
++ public long InReplyToStatusID
+ {
+ get { return inReplyToStatusID; }
+ set { inReplyToStatusID = value; }
+diff -urNad gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/Twitterizer/Twitterizer.Framework/MethodClasses/TwitterStatusMethods.cs gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/Twitterizer/Twitterizer.Framework/MethodClasses/TwitterStatusMethods.cs
+--- gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/Twitterizer/Twitterizer.Framework/MethodClasses/TwitterStatusMethods.cs 2009-03-17 17:56:56.000000000 +0000
++++ gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/Twitterizer/Twitterizer.Framework/MethodClasses/TwitterStatusMethods.cs 2009-06-15 23:50:29.000000000 +0100
+@@ -131,7 +131,7 @@
+ /// <param name="Status">Required. The text of your status update.</param>
+ /// <param name="InReplyToStatusID">Optional. The ID of an existing status that the status to be posted is in reply to.</param>
+ /// <returns></returns>
+- public TwitterStatus Update(string Status, int? InReplyToStatusID)
++ public TwitterStatus Update(string Status, long? InReplyToStatusID)
+ {
+ TwitterRequest Request = new TwitterRequest();
+ TwitterRequestData Data = new TwitterRequestData();
+diff -urNad gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/Twitterizer/Twitterizer.Framework/TwitterRequest.cs gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/Twitterizer/Twitterizer.Framework/TwitterRequest.cs
+--- gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/Twitterizer/Twitterizer.Framework/TwitterRequest.cs 2009-03-17 17:56:56.000000000 +0000
++++ gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/Twitterizer/Twitterizer.Framework/TwitterRequest.cs 2009-06-15 23:48:45.000000000 +0100
+@@ -160,13 +160,13 @@
+ if (Element == null) return null;
+
+ //Mon May 12 15:56:07 +0000 2008
+- Status.ID = int.Parse(Element["id"].InnerText);
++ Status.ID = long.Parse(Element["id"].InnerText);
+ Status.Created = ParseDateString(Element["created_at"].InnerText);
+ Status.Text = Element["text"].InnerText;
+ Status.Source = Element["source"].InnerText;
+ Status.IsTruncated = bool.Parse(Element["truncated"].InnerText);
+ if (Element["in_reply_to_status_id"].InnerText != string.Empty)
+- Status.InReplyToStatusID = int.Parse(Element["in_reply_to_status_id"].InnerText);
++ Status.InReplyToStatusID = long.Parse(Element["in_reply_to_status_id"].InnerText);
+ if (Element["in_reply_to_user_id"].InnerText != string.Empty)
+ Status.InReplyToUserID = int.Parse(Element["in_reply_to_user_id"].InnerText);
+
+@@ -199,7 +199,7 @@
+
+ TwitterStatus Status = new TwitterStatus();
+
+- Status.ID = int.Parse(Element["id"].InnerText);
++ Status.ID = long.Parse(Element["id"].InnerText);
+ Status.Created = ParseDateString(Element["created_at"].InnerText);
+ Status.Text = Element["text"].InnerText;
+
+diff -urNad gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/Twitterizer/Twitterizer.Framework/TwitterRequest.cs.orig gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/Twitterizer/Twitterizer.Framework/TwitterRequest.cs.orig
+--- gnome-do-plugins-0.8.1.3+dfsg~/Microblogging/src/Twitterizer/Twitterizer.Framework/TwitterRequest.cs.orig 1970-01-01 01:00:00.000000000 +0100
++++ gnome-do-plugins-0.8.1.3+dfsg/Microblogging/src/Twitterizer/Twitterizer.Framework/TwitterRequest.cs.orig 2009-03-17 17:56:56.000000000 +0000
+@@ -0,0 +1,282 @@
++/*
++ * This file is part of the Twitterizer library <http://code.google.com/p/twitterizer/>
++ *
++ * Copyright (c) 2008, Patrick "Ricky" Smith <ricky at digitally-born.com>
++ * All rights reserved.
++ *
++ * Redistribution and use in source and binary forms, with or without modification, are
++ * permitted provided that the following conditions are met:
++ *
++ * - Redistributions of source code must retain the above copyright notice, this list
++ * of conditions and the following disclaimer.
++ * - Redistributions in binary form must reproduce the above copyright notice, this list
++ * of conditions and the following disclaimer in the documentation and/or other
++ * materials provided with the distribution.
++ * - Neither the name of the Twitterizer nor the names of its contributors may be
++ * used to endorse or promote products derived from this software without specific
++ * prior written permission.
++ *
++ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
++ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
++ * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
++ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
++ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
++ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
++ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
++ * POSSIBILITY OF SUCH DAMAGE.
++ */
++using System;
++using System.Text;
++using System.Text.RegularExpressions;
++using System.Net;
++using System.Xml;
++using System.IO;
++
++namespace Twitterizer.Framework
++{
++ internal class TwitterRequest
++ {
++ public TwitterRequestData PerformWebRequest(TwitterRequestData Data)
++ {
++ PerformWebRequest(Data, "POST");
++
++ return (Data);
++
++ }
++
++ public TwitterRequestData PerformWebRequest(TwitterRequestData Data, string HTTPMethod)
++ {
++ HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(Data.ActionUri);
++
++
++ Request.Method = HTTPMethod;
++
++ StreamReader readStream;
++
++ // Some limitations
++ Request.MaximumAutomaticRedirections = 4;
++ Request.MaximumResponseHeadersLength = 4;
++ Request.ContentLength = 0;
++
++ // Set our credentials
++ Request.Credentials = new NetworkCredential(Data.UserName, Data.Password);
++
++ HttpWebResponse Response;
++
++ // Get the respon
++ try
++ {
++ Response = (HttpWebResponse)Request.GetResponse();
++
++ // Get the stream associated with the response.
++ Stream receiveStream = Response.GetResponseStream();
++
++ // Pipes the stream to a higher level stream reader with the required encoding format.
++ readStream = new StreamReader(receiveStream, Encoding.UTF8);
++
++ Data.Response = readStream.ReadToEnd();
++ Data = ParseResponseData(Data);
++
++ Response.Close();
++ readStream.Close();
++ }
++ catch (Exception ex)
++ {
++ throw new TwitterizerException(ex.Message, Data, ex);
++ }
++
++ return Data;
++ }
++
++ private TwitterRequestData ParseResponseData(TwitterRequestData Data)
++ {
++ if (Data == null || Data.Response == string.Empty)
++ return null;
++
++ try
++ {
++ XmlDocument ResultXmlDocument = new XmlDocument();
++ ResultXmlDocument.LoadXml(Data.Response);
++
++ if (ResultXmlDocument.DocumentElement != null)
++ switch (ResultXmlDocument.DocumentElement.Name.ToLower())
++ {
++ case "status":
++ Data.Statuses = new TwitterStatusCollection();
++ Data.Statuses.Add(ParseStatusNode(ResultXmlDocument.DocumentElement));
++ break;
++ case "statuses":
++ Data.Statuses = ParseStatuses(ResultXmlDocument.DocumentElement);
++ break;
++ case "users":
++ Data.Users = ParseUsers(ResultXmlDocument.DocumentElement);
++ break;
++ case "user":
++ Data.Users = new TwitterUserCollection();
++ Data.Users.Add(ParseUserNode(ResultXmlDocument.DocumentElement));
++ break;
++ case "direct-messages":
++ Data.Statuses = new TwitterStatusCollection();
++ Data.Statuses = ParseDirectMessages(ResultXmlDocument.DocumentElement);
++ break;
++
++ case "nil-classes":
++ // do nothing, this seems to be a null response i.e. no messages since
++ break;
++
++ case "error":
++ throw new Exception("Error response from Twitter: " + ResultXmlDocument.DocumentElement.InnerText);
++ default:
++
++ throw new Exception("Invalid response from Twitter");
++ }
++ }
++ catch (Exception ex)
++ {
++ throw new TwitterizerException("Error Parsing Twitter Response.", Data, ex);
++ }
++
++ return Data;
++ }
++
++ #region Parse Statuses
++ private TwitterStatusCollection ParseStatuses(XmlElement Element)
++ {
++ TwitterStatusCollection Collection = new TwitterStatusCollection();
++ foreach (XmlElement Child in Element.GetElementsByTagName("status"))
++ {
++ Collection.Add(ParseStatusNode(Child));
++ }
++
++ return Collection;
++ }
++
++ private TwitterStatus ParseStatusNode(XmlNode Element)
++ {
++ TwitterStatus Status = new TwitterStatus();
++
++ if (Element == null) return null;
++
++ //Mon May 12 15:56:07 +0000 2008
++ Status.ID = int.Parse(Element["id"].InnerText);
++ Status.Created = ParseDateString(Element["created_at"].InnerText);
++ Status.Text = Element["text"].InnerText;
++ Status.Source = Element["source"].InnerText;
++ Status.IsTruncated = bool.Parse(Element["truncated"].InnerText);
++ if (Element["in_reply_to_status_id"].InnerText != string.Empty)
++ Status.InReplyToStatusID = int.Parse(Element["in_reply_to_status_id"].InnerText);
++ if (Element["in_reply_to_user_id"].InnerText != string.Empty)
++ Status.InReplyToUserID = int.Parse(Element["in_reply_to_user_id"].InnerText);
++
++ // Fix for Issued #4
++ bool isFavorited;
++ bool.TryParse(Element["favorited"].InnerText, out isFavorited);
++ Status.IsFavorited = isFavorited;
++
++ Status.TwitterUser = ParseUserNode(Element["user"]);
++
++ return Status;
++ }
++ #endregion
++
++ #region Parse DirectMessages
++ private static TwitterStatusCollection ParseDirectMessages(XmlElement Element)
++ {
++ TwitterStatusCollection Collection = new TwitterStatusCollection();
++ foreach (XmlElement Child in Element.GetElementsByTagName("direct_message"))
++ {
++ Collection.Add(ParseDirectMessageNode(Child));
++ }
++
++ return Collection;
++ }
++
++ private static TwitterStatus ParseDirectMessageNode(XmlNode Element)
++ {
++ if (Element == null) return null;
++
++ TwitterStatus Status = new TwitterStatus();
++
++ Status.ID = int.Parse(Element["id"].InnerText);
++ Status.Created = ParseDateString(Element["created_at"].InnerText);
++ Status.Text = Element["text"].InnerText;
++
++ if (Element["favorited"] != null && (Element["in_reply_to_status_id"].InnerText != string.Empty))
++ Status.IsFavorited = bool.Parse(Element["favorited"].InnerText);
++
++ Status.TwitterUser = new TwitterUser();
++ Status.TwitterUser.ScreenName = Element["sender_screen_name"].InnerText;
++ Status.TwitterUser.ID = int.Parse(Element["sender_id"].InnerText);
++ Status.RecipientID = int.Parse(Element["recipient_id"].InnerText);
++
++
++
++
++ return Status;
++ }
++ #endregion
++
++ #region Parse Users
++ private TwitterUserCollection ParseUsers(XmlElement Element)
++ {
++ if (Element == null) return null;
++
++ TwitterUserCollection Collection = new TwitterUserCollection();
++ foreach (XmlElement Child in Element.GetElementsByTagName("user"))
++ {
++ Collection.Add(ParseUserNode(Child));
++ }
++
++ return Collection;
++ }
++
++ private TwitterUser ParseUserNode(XmlNode Element)
++ {
++ if (Element == null)
++ return null;
++
++ TwitterUser User = new TwitterUser();
++ User.ID = int.Parse(Element["id"].InnerText);
++ User.UserName = Element["name"].InnerText;
++ User.ScreenName = Element["screen_name"].InnerText;
++ User.Location = Element["location"].InnerText;
++ User.Description = Element["description"].InnerText;
++ if (Element["profile_image_url"].InnerText != string.Empty)
++ User.ProfileImageUri = new Uri(Element["profile_image_url"].InnerText);
++ if (Element["url"].InnerText != string.Empty)
++ User.ProfileUri = new Uri(Element["url"].InnerText);
++ User.IsProtected = bool.Parse(Element["protected"].InnerText);
++ User.NumberOfFollowers = int.Parse(Element["followers_count"].InnerText);
++
++ if (Element["friends_count"] != null)
++ User.Friends_count = int.Parse(Element["friends_count"].InnerText);
++ else
++ User.Friends_count = -1; // flag that we don't know, which is different than having zero friends
++
++ if (Element["status"] != null)
++ User.Status = ParseStatusNode(Element["status"]);
++
++ return User;
++ }
++ #endregion
++
++ private static DateTime ParseDateString(string DateString)
++ {
++ Regex re = new Regex(@"(?<DayName>[^ ]+) (?<MonthName>[^ ]+) (?<Day>[^ ]{1,2}) (?<Hour>[0-9]{1,2}):(?<Minute>[0-9]{1,2}):(?<Second>[0-9]{1,2}) (?<TimeZone>[+-][0-9]{4}) (?<Year>[0-9]{4})");
++ Match CreatedAt = re.Match(DateString);
++ DateTime parsedDate = DateTime.Parse(
++ string.Format(
++ "{0} {1} {2} {3}:{4}:{5}",
++ CreatedAt.Groups["MonthName"].Value,
++ CreatedAt.Groups["Day"].Value,
++ CreatedAt.Groups["Year"].Value,
++ CreatedAt.Groups["Hour"].Value,
++ CreatedAt.Groups["Minute"].Value,
++ CreatedAt.Groups["Second"].Value));
++
++ return parsedDate;
++ }
++ }
++}
Propchange: packages/gnome-do-plugins/trunk/debian/patches/20_twitter_overflow.dpatch
------------------------------------------------------------------------------
svn:executable = *
More information about the Pkg-cli-apps-commits
mailing list