Changeset 13604

Show
Ignore:
Timestamp:
06/10/08 04:12:14 (5 years ago)
Author:
poolmmjp
Message:

TwitterとFriendFeedでfav出来るようにした

Location:
lang/csharp/MMMMB/MMMMB
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • lang/csharp/MMMMB/MMMMB/MMMMB.csproj

    r11290 r13604  
    4141    <Compile Include="Entry.cs" /> 
    4242    <Compile Include="FileLogger.cs" /> 
     43    <Compile Include="IFavoritable.cs" /> 
    4344    <Compile Include="ILogger.cs" /> 
    4445    <Compile Include="IMiniBlog.cs" /> 
  • lang/csharp/MMMMB/MMMMB/MiniBlogView.cs

    r13454 r13604  
    206206        public void PermalinkClick(string permalink) 
    207207        { 
     208            ContextMenuStrip menu = new ContextMenuStrip(); 
     209 
     210            if (miniBlog is IFavoritable) 
     211            { 
     212                IFavoritable favable = (IFavoritable)miniBlog; 
     213                ToolStripItem fav = new ToolStripMenuItem(favable.FeatureName + "(&F)"); 
     214                fav.Click += new EventHandler(delegate(object sender, EventArgs e){ 
     215                    favable.Create(permalink); 
     216                }); 
     217                menu.Items.Add(fav); 
     218                menu.Items.Add(new ToolStripSeparator()); 
     219            } 
     220 
    208221            ToolStripItem open = new ToolStripMenuItem("�J��(&O)"); 
    209222            open.Click += new EventHandler(delegate(object sender, EventArgs e){ 
    210223                Process.Start(permalink); 
    211224            }); 
     225            menu.Items.Add(open); 
     226             
    212227            ToolStripItem copy = new ToolStripMenuItem("URL ��s�[(&C)"); 
    213             copy.Click += new EventHandler(delegate(object sender, EventArgs e) 
    214             { 
     228            copy.Click += new EventHandler(delegate(object sender, EventArgs e){ 
    215229                Clipboard.SetText(permalink); 
    216230            }); 
    217             ContextMenuStrip menu = new ContextMenuStrip(); 
    218             menu.Items.Add(open); 
    219231            menu.Items.Add(copy); 
     232 
    220233            menu.Show(browser, browser.PointToClient(Cursor.Position)); 
    221234        } 
  • lang/csharp/MMMMB/MMMMB/MiniBlogs/FriendFeed.cs

    r10748 r13604  
    99namespace MMMMB.MiniBlogs 
    1010{ 
    11     class FriendFeed : IMiniBlog 
     11    class FriendFeed : IMiniBlog, IFavoritable 
    1212    { 
    1313        private string username; 
     
    8484            return null; 
    8585        } 
     86 
     87        #region "IFavoritable" 
     88        public string FeatureName 
     89        { 
     90            get { return "Like"; } 
     91        } 
     92        public void Create(string permalink) 
     93        { 
     94            string id = Regex.Replace(permalink, @"^http://friendfeed.com/e/([a-z0-9-]+)$", "$1"); 
     95            WebClient client = new WebClient(); 
     96            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); 
     97            client.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password))); 
     98            client.UploadString("http://friendfeed.com/api/like?entry=" + id, "POST", ""); 
     99        } 
     100 
     101        public void Destroy(string permalink) 
     102        { 
     103            string id = Regex.Replace(permalink, @"^http://friendfeed.com/e/([a-z0-9-]+)$", "$1"); 
     104            WebClient client = new WebClient(); 
     105            client.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); 
     106            client.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password))); 
     107            client.UploadString("http://friendfeed.com/api/like/delete?entry=" + id, "POST", ""); 
     108        } 
     109        #endregion 
    86110    } 
    87111} 
  • lang/csharp/MMMMB/MMMMB/MiniBlogs/Twitter.cs

    r13455 r13604  
    22using System.Collections.Generic; 
    33using System.Text; 
     4using System.Text.RegularExpressions; 
    45using System.Net; 
    56using System.Xml; 
     
    910namespace MMMMB.MiniBlogs 
    1011{ 
    11     class Twitter : IMiniBlog 
     12    class Twitter : IMiniBlog, IFavoritable 
    1213    { 
    1314        private string username; 
     
    8081            return "@" + entry.Name; 
    8182        } 
     83 
     84        #region "IFavoritable" 
     85        public string FeatureName 
     86        { 
     87            get { return "Favorite this update"; } 
     88        } 
     89        public void Create(string permalink) 
     90        { 
     91            string id = Regex.Replace(permalink, @"^http://twitter.com/.+?/statuses/([0-9]+)$", "$1"); 
     92            WebClient client = new WebClient(); 
     93            client.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password))); 
     94            client.UploadString("http://twitter.com/favourings/create/" + id + ".xml", "POST", ""); 
     95        } 
     96 
     97        public void Destroy(string permalink) 
     98        { 
     99            string id = Regex.Replace(permalink, @"^http://twitter.com/.+?/statuses/([0-9]+)$", "$1"); 
     100            WebClient client = new WebClient(); 
     101            client.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password))); 
     102            client.UploadString("http://twitter.com/favourings/destroy/" + id + ".xml", "POST", ""); 
     103        } 
     104        #endregion 
    82105    } 
    83106}