• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

http://sourceforge.jp/projects/futonwriter/の旧リポジトリ


Commit MetaInfo

Revision3410d03f2a4be601525efcb9eb04e935ace2989b (tree)
Zeit2011-05-09 18:15:23
Autorazyobuzin <azyobuzin@user...>
Commiterazyobuzin

Log Message

下書きの実装完了

Ändern Zusammenfassung

Diff

--- a/HatenaDiaryClient/Models/Hatena/BlogEntry.cs
+++ b/HatenaDiaryClient/Models/Hatena/BlogEntry.cs
@@ -1,7 +1,5 @@
11 using System;
2-using System.Collections.Generic;
32 using System.Linq;
4-using System.Text;
53 using System.Text.RegularExpressions;
64 using System.Xml.Linq;
75
@@ -29,7 +27,13 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
2927 this.HatenaSyntax = xml.Elements(XmlNamespaces.HatenaNs + "syntax")
3028 .Select(_ => _.Value)
3129 .SingleOrDefault();
32- this.DateId = Regex.Match(this.BlogPage, @"\d+/\d+$").ToString();
30+ this.DateId = Regex.Match(
31+ xml.Elements(XmlNamespaces.Atom + "link")
32+ .Where(_ => _.Attribute("rel").Value == "edit")
33+ .Select(_ => _.Attribute("href").Value)
34+ .First(),
35+ @"(\d+/\d+|\d+)$"
36+ ).ToString();
3337 }
3438 }
3539 }
--- a/HatenaDiaryClient/Models/Hatena/HatenaDiary.cs
+++ b/HatenaDiaryClient/Models/Hatena/HatenaDiary.cs
@@ -1,7 +1,8 @@
11 using System;
22 using System.Collections.Generic;
33 using System.Linq;
4-using System.Text;
4+using System.Net;
5+using System.Text.RegularExpressions;
56 using System.Xml.Linq;
67
78 namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
@@ -31,8 +32,8 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
3132 private static XDocument CreatePostEntryXml(string title, string content, DateTime? updated)
3233 {
3334 var elm = new XElement(XmlNamespaces.Atom02Spec + "entry",
34- new XElement(XmlNamespaces.Atom02Spec + "title", title),
35- new XElement(XmlNamespaces.Atom02Spec + "content", new XAttribute("type", "text/plain"), content));
35+ new XElement(XmlNamespaces.Atom02Spec + "title", title),
36+ new XElement(XmlNamespaces.Atom02Spec + "content", new XAttribute("type", "text/plain"), content));
3637 if (updated.HasValue)
3738 elm.Add(new XElement(XmlNamespaces.Atom02Spec + "updated", updated.Value.ToString("o")));
3839 return new XDocument(elm);
@@ -63,10 +64,10 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
6364 public BlogEntry EditEntry(string dateId, string title, string content, DateTime? updated = null)
6465 {
6566 var reXml = WsseAtomConnection.Put(
66- string.Format("http://d.hatena.ne.jp/{0}/atom/blog/{1}", this.userName, dateId),
67- CreatePostEntryXml(title, content, updated),
68- this.userName,
69- this.password);
67+ string.Format("http://d.hatena.ne.jp/{0}/atom/blog/{1}", this.userName, dateId),
68+ CreatePostEntryXml(title, content, updated),
69+ this.userName,
70+ this.password);
7071 return new BlogEntry(reXml.Root)
7172 {
7273 HatenaSyntax = content
@@ -80,5 +81,77 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
8081 this.userName,
8182 this.password);
8283 }
84+
85+ public Tuple<string, IEnumerable<BlogEntry>> GetDrafts(int page = 1)
86+ {
87+ var xdoc = WsseAtomConnection.Get(
88+ string.Format("http://d.hatena.ne.jp/{0}/atom/draft?page={1}", this.userName, page),
89+ this.userName,
90+ this.password);
91+ var title = xdoc.Root.Element(XmlNamespaces.Atom + "title").Value;
92+ var entrys = xdoc.Root.Elements(XmlNamespaces.Atom + "entry").Select(_ => new BlogEntry(_));
93+ return Tuple.Create(title, entrys);
94+ }
95+
96+ public BlogEntry PostDraft(string title, string content, DateTime? updated = null)
97+ {
98+ var reXml = WsseAtomConnection.Post(
99+ string.Format("http://d.hatena.ne.jp/{0}/atom/draft", this.userName),
100+ CreatePostEntryXml(title, content, updated),
101+ this.userName,
102+ this.password);
103+ return new BlogEntry(reXml.Root)
104+ {
105+ HatenaSyntax = content
106+ };
107+ }
108+
109+ public BlogEntry GetDraft(string id)
110+ {
111+ var xdoc = WsseAtomConnection.Get(
112+ string.Format("http://d.hatena.ne.jp/{0}/atom/draft/{1}", this.userName, id),
113+ this.userName,
114+ this.password);
115+ return new BlogEntry(xdoc.Root);
116+ }
117+
118+ public BlogEntry EditDraft(string id, string title, string content, DateTime? updated = null)
119+ {
120+ var reXml = WsseAtomConnection.Put(
121+ string.Format("http://d.hatena.ne.jp/{0}/atom/draft/{1}", this.userName, id),
122+ CreatePostEntryXml(title, content, updated),
123+ this.userName,
124+ this.password);
125+ return new BlogEntry(reXml.Root)
126+ {
127+ HatenaSyntax = content
128+ };
129+ }
130+
131+ public void DeleteDraft(string id)
132+ {
133+ WsseAtomConnection.Delete(
134+ string.Format("http://d.hatena.ne.jp/{0}/atom/draft/{1}", this.userName, id),
135+ this.userName,
136+ this.password);
137+ }
138+
139+ public string PublishDraft(string id)
140+ {
141+ var req = (HttpWebRequest)WebRequest.Create(string.Format(
142+ "http://d.hatena.ne.jp/{0}/atom/draft/{1}",
143+ this.userName,
144+ id));
145+ req.Method = "PUT";
146+ req.AllowAutoRedirect = false;
147+ req.Headers.Add(WsseAtomConnection.CreateHeader(this.userName, this.password));
148+ req.Headers.Add("X-HATENA-PUBLISH: 1");
149+ using (var res = req.GetResponse())
150+ return Regex.Match(
151+ res.Headers[HttpResponseHeader.Location],
152+ @"\d+/\d+"
153+ )
154+ .ToString();
155+ }
83156 }
84157 }
--- a/HatenaDiaryClient/Models/Hatena/WsseAtomConnection.cs
+++ b/HatenaDiaryClient/Models/Hatena/WsseAtomConnection.cs
@@ -10,7 +10,7 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
1010 {
1111 private static Random random = new Random();
1212
13- private static string CreateHeader(string userName, string password)
13+ public static string CreateHeader(string userName, string password)
1414 {
1515 var tmp = new byte[25];
1616 random.NextBytes(tmp);