http://sourceforge.jp/projects/futonwriter/の旧リポジトリ
Revision | 41e1624398247ded15c66c77ef9b661dc8a3e6d6 (tree) |
---|---|
Zeit | 2011-05-11 19:28:48 |
Autor | azyobuzin <azyobuzin@user...> |
Commiter | azyobuzin |
・フォトライフの対応一応完了
・その他いろいろWsseAtomConnectionとかいじった
@@ -1,9 +1,7 @@ | ||
1 | 1 | using System; |
2 | -using System.Collections.Generic; | |
3 | 2 | using System.Linq; |
4 | -using System.Text; | |
5 | -using System.Xml.Linq; | |
6 | 3 | using System.Text.RegularExpressions; |
4 | +using System.Xml.Linq; | |
7 | 5 | |
8 | 6 | namespace Azyobuzi.HatenaDiaryClient.Models.Hatena |
9 | 7 | { |
@@ -19,26 +17,28 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena | ||
19 | 17 | public string HatenaSyntax { set; get; } |
20 | 18 | |
21 | 19 | public FotolifeEntry() { } |
22 | - public FotolifeEntry(XElement xml, bool isRdf) | |
20 | + public FotolifeEntry(XElement xml) | |
23 | 21 | { |
24 | - if (isRdf) | |
25 | - { | |
26 | - //TODO | |
27 | - } | |
28 | - else | |
29 | - { | |
30 | - this.Title = xml.Element(XmlNamespaces.Atom02Spec + "title").Value; | |
31 | - this.PageUri = xml.Elements(XmlNamespaces.Atom02Spec + "link") | |
32 | - .Where(_ => _.Attribute("rel").Value == "alternate") | |
33 | - .Select(_ => _.Attribute("href").Value) | |
34 | - .FirstOrDefault(); | |
35 | - this.Id = Regex.Match(this.PageUri, @"\d+$").ToString(); | |
36 | - this.Issued = DateTime.Parse(xml.Element(XmlNamespaces.Atom02Spec + "issued").Value); | |
37 | - this.Folder = xml.Element(XmlNamespaces.DublinCore + "subject").Value; | |
38 | - this.ImageUri = xml.Element(XmlNamespaces.HatenaNs + "imageurl").Value; | |
39 | - this.ThumbnailUri = xml.Element(XmlNamespaces.HatenaNs + "imageurlsmall").Value; | |
40 | - this.HatenaSyntax = xml.Element(XmlNamespaces.HatenaNs + "syntax").Value; | |
41 | - } | |
22 | + Console.WriteLine(xml.ToString()); | |
23 | + this.Title = xml.Element(XmlNamespaces.Atom02Spec + "title").Value; | |
24 | + this.PageUri = xml.Elements(XmlNamespaces.Atom02Spec + "link") | |
25 | + .Where(_ => _.Attribute("rel").Value == "alternate") | |
26 | + .Select(_ => _.Attribute("href").Value) | |
27 | + .FirstOrDefault(); | |
28 | + this.Id = Regex.Match(this.PageUri, @"\d+$").ToString(); | |
29 | + var issuedXml = xml.Element(XmlNamespaces.Atom02Spec + "issued").Value; | |
30 | + if (!string.IsNullOrWhiteSpace(issuedXml)) | |
31 | + this.Issued = DateTime.Parse(issuedXml); | |
32 | + var folderXml = xml.Element(XmlNamespaces.DublinCore + "subject"); | |
33 | + if (folderXml != null) | |
34 | + this.Folder = folderXml.Value; | |
35 | + this.ImageUri = xml.Element(XmlNamespaces.HatenaNs + "imageurl").Value; | |
36 | + this.ThumbnailUri = xml.Element(XmlNamespaces.HatenaNs + "imageurlsmall").Value; | |
37 | + this.HatenaSyntax = string.Format( | |
38 | + "f:id:{0}:{1}j:image", | |
39 | + xml.Element(XmlNamespaces.Atom02Spec + "author") | |
40 | + .Element(XmlNamespaces.Atom02Spec + "name").Value, | |
41 | + this.Id); | |
42 | 42 | } |
43 | 43 | } |
44 | 44 | } |
@@ -1,9 +1,8 @@ | ||
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | +using System.Collections.Specialized; | |
3 | 4 | using System.Linq; |
4 | -using System.Net; | |
5 | 5 | using System.Text; |
6 | -using System.Text.RegularExpressions; | |
7 | 6 | using System.Xml.Linq; |
8 | 7 | |
9 | 8 | namespace Azyobuzi.HatenaDiaryClient.Models.Hatena |
@@ -23,6 +22,7 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena | ||
23 | 22 | { |
24 | 23 | var xdoc = WsseAtomConnection.Get( |
25 | 24 | string.Format("http://d.hatena.ne.jp/{0}/atom/blog?page={1}", this.userName, page), |
25 | + Encoding.UTF8, | |
26 | 26 | this.userName, |
27 | 27 | this.password); |
28 | 28 | var title = xdoc.Root.Element(XmlNamespaces.Atom + "title").Value; |
@@ -58,6 +58,7 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena | ||
58 | 58 | { |
59 | 59 | var xdoc = WsseAtomConnection.Get( |
60 | 60 | string.Format("http://d.hatena.ne.jp/{0}/atom/blog/{1}", this.userName, dateId), |
61 | + Encoding.UTF8, | |
61 | 62 | this.userName, |
62 | 63 | this.password); |
63 | 64 | return new BlogEntry(xdoc.Root); |
@@ -89,6 +90,7 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena | ||
89 | 90 | { |
90 | 91 | var xdoc = WsseAtomConnection.Get( |
91 | 92 | string.Format("http://d.hatena.ne.jp/{0}/atom/draft?page={1}", this.userName, page), |
93 | + Encoding.UTF8, | |
92 | 94 | this.userName, |
93 | 95 | this.password); |
94 | 96 | var title = xdoc.Root.Element(XmlNamespaces.Atom + "title").Value; |
@@ -114,6 +116,7 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena | ||
114 | 116 | { |
115 | 117 | var xdoc = WsseAtomConnection.Get( |
116 | 118 | string.Format("http://d.hatena.ne.jp/{0}/atom/draft/{1}", this.userName, id), |
119 | + Encoding.UTF8, | |
117 | 120 | this.userName, |
118 | 121 | this.password); |
119 | 122 | return new BlogEntry(xdoc.Root); |
@@ -141,22 +144,22 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena | ||
141 | 144 | this.password); |
142 | 145 | } |
143 | 146 | |
144 | - public string PublishDraft(string id) | |
147 | + public BlogEntry PublishDraft(string id) | |
145 | 148 | { |
146 | - var req = (HttpWebRequest)WebRequest.Create(string.Format( | |
147 | - "http://d.hatena.ne.jp/{0}/atom/draft/{1}", | |
148 | - this.userName, | |
149 | - id)); | |
150 | - req.Method = "PUT"; | |
151 | - req.AllowAutoRedirect = false; | |
152 | - req.Headers.Add(WsseAtomConnection.CreateHeader(this.userName, this.password)); | |
153 | - req.Headers.Add("X-HATENA-PUBLISH: 1"); | |
154 | - using (var res = req.GetResponse()) | |
155 | - return Regex.Match( | |
156 | - res.Headers[HttpResponseHeader.Location], | |
157 | - @"\d+/\d+" | |
149 | + return new BlogEntry( | |
150 | + XElement.Parse( | |
151 | + WsseAtomConnection.Put( | |
152 | + string.Format( | |
153 | + "http://d.hatena.ne.jp/{0}/atom/draft/{1}", | |
154 | + this.userName, | |
155 | + id), | |
156 | + new NameValueCollection() { { "X-HATENA-PUBLISH", "1" } }, | |
157 | + null, | |
158 | + Encoding.UTF8, | |
159 | + this.userName, | |
160 | + this.password) | |
158 | 161 | ) |
159 | - .ToString(); | |
162 | + ); | |
160 | 163 | } |
161 | 164 | } |
162 | 165 | } |
@@ -1,10 +1,9 @@ | ||
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | +using System.IO; | |
3 | 4 | using System.Linq; |
4 | 5 | using System.Text; |
5 | -using System.IO; | |
6 | 6 | using System.Xml.Linq; |
7 | -using System.Net; | |
8 | 7 | |
9 | 8 | namespace Azyobuzi.HatenaDiaryClient.Models.Hatena |
10 | 9 | { |
@@ -38,30 +37,30 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena | ||
38 | 37 | case "bmp": |
39 | 38 | mimeType = "image/x-bmp"; |
40 | 39 | break; |
41 | - case "mov": | |
42 | - mimeType = "video/quicktime"; | |
43 | - break; | |
44 | - case "mpg": | |
45 | - case "mpeg": | |
46 | - case "m1v": | |
47 | - mimeType = "video/mpeg"; | |
48 | - break; | |
49 | - case "wmv": | |
50 | - mimeType = "video/x-ms-wmv"; | |
51 | - break; | |
52 | - case "avi": | |
53 | - mimeType = "video/avi"; | |
54 | - break; | |
55 | - case "flv": | |
56 | - mimeType = "video/x-flv"; | |
57 | - break; | |
58 | - case "3gp": | |
59 | - case "3gpp": | |
60 | - mimeType = "video/3gpp"; | |
61 | - break; | |
62 | - case "3g2": | |
63 | - mimeType = "video/3gpp2"; | |
64 | - break; | |
40 | + //case "mov": | |
41 | + // mimeType = "video/quicktime"; | |
42 | + // break; | |
43 | + //case "mpg": | |
44 | + //case "mpeg": | |
45 | + //case "m1v": | |
46 | + // mimeType = "video/mpeg"; | |
47 | + // break; | |
48 | + //case "wmv": | |
49 | + // mimeType = "video/x-ms-wmv"; | |
50 | + // break; | |
51 | + //case "avi": | |
52 | + // mimeType = "video/avi"; | |
53 | + // break; | |
54 | + //case "flv": | |
55 | + // mimeType = "video/x-flv"; | |
56 | + // break; | |
57 | + //case "3gp": | |
58 | + //case "3gpp": | |
59 | + // mimeType = "video/3gpp"; | |
60 | + // break; | |
61 | + //case "3g2": | |
62 | + // mimeType = "video/3gpp2"; | |
63 | + // break; | |
65 | 64 | default: |
66 | 65 | throw new ArgumentException("対応してないファイルです。"); |
67 | 66 | } |
@@ -84,7 +83,59 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena | ||
84 | 83 | Encoding.GetEncoding("shift_jis"), |
85 | 84 | this.userName, |
86 | 85 | this.password); |
87 | - return new FotolifeEntry(reXml.Root, false); | |
86 | + return new FotolifeEntry(reXml.Root); | |
87 | + } | |
88 | + | |
89 | + public FotolifeEntry GetEntry(string id) | |
90 | + { | |
91 | + return new FotolifeEntry( | |
92 | + WsseAtomConnection.Get( | |
93 | + "http://f.hatena.ne.jp/atom/edit/" + id, | |
94 | + Encoding.UTF8, | |
95 | + this.userName, | |
96 | + this.password | |
97 | + ) | |
98 | + .Root | |
99 | + ); | |
100 | + } | |
101 | + | |
102 | + public void EditEntry(string id, string newTitle) | |
103 | + { | |
104 | + WsseAtomConnection.Put( | |
105 | + "http://f.hatena.ne.jp/atom/edit/" + id, | |
106 | + null, | |
107 | + Encoding.GetEncoding("shift_jis").GetBytes( | |
108 | + new XDocument( | |
109 | + new XElement(XmlNamespaces.Atom02Spec + "entry", | |
110 | + new XElement(XmlNamespaces.Atom02Spec + "title", newTitle) | |
111 | + ) | |
112 | + ) | |
113 | + .ToString() | |
114 | + ), | |
115 | + null, | |
116 | + this.userName, | |
117 | + this.password); | |
118 | + } | |
119 | + | |
120 | + public void DeleteEntry(string id) | |
121 | + { | |
122 | + WsseAtomConnection.Delete( | |
123 | + "http://f.hatena.ne.jp/atom/edit/" + id, | |
124 | + this.userName, | |
125 | + this.password); | |
126 | + } | |
127 | + | |
128 | + public IEnumerable<FotolifeEntry> GetEntrys(int page = 1) | |
129 | + { | |
130 | + return WsseAtomConnection.Get( | |
131 | + "http://f.hatena.ne.jp/atom/feed?page=" + page.ToString(), | |
132 | + Encoding.UTF8, | |
133 | + this.userName, | |
134 | + this.password | |
135 | + ) | |
136 | + .Root | |
137 | + .Elements(XmlNamespaces.Atom02Spec + "entry") | |
138 | + .Select(_ => new FotolifeEntry(_)); | |
88 | 139 | } |
89 | 140 | } |
90 | 141 | } |
@@ -1,4 +1,6 @@ | ||
1 | 1 | using System; |
2 | +using System.Collections.Specialized; | |
3 | +using System.IO; | |
2 | 4 | using System.Linq; |
3 | 5 | using System.Net; |
4 | 6 | using System.Security.Cryptography; |
@@ -25,13 +27,13 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena | ||
25 | 27 | userName, digest, Convert.ToBase64String(nonce), created); |
26 | 28 | } |
27 | 29 | |
28 | - public static XDocument Get(string reqUri, string userName, string password) | |
30 | + public static XDocument Get(string reqUri, Encoding enc, string userName, string password) | |
29 | 31 | { |
30 | 32 | using (var wc = new WebClient()) |
31 | 33 | { |
32 | 34 | wc.Headers.Add(CreateHeader(userName, password)); |
33 | - using (var stream = wc.OpenRead(reqUri)) | |
34 | - return XDocument.Load(stream); | |
35 | + using (var sr = new StreamReader(wc.OpenRead(reqUri), enc ?? Encoding.UTF8)) | |
36 | + return XDocument.Load(sr); | |
35 | 37 | } |
36 | 38 | } |
37 | 39 |
@@ -49,7 +51,7 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena | ||
49 | 51 | req.Method = method; |
50 | 52 | req.Headers.Add(CreateHeader(userName, password)); |
51 | 53 | req.ContentType = "application/x.atom+xml"; |
52 | - var bs = Encoding.GetEncoding("shift_jis").GetBytes(reqData.ToString()); | |
54 | + var bs = enc.GetBytes(reqData.ToString()); | |
53 | 55 | req.ContentLength = bs.Length; |
54 | 56 | using (var stream = req.GetRequestStream()) |
55 | 57 | stream.Write(bs, 0, bs.Length); |
@@ -66,5 +68,21 @@ namespace Azyobuzi.HatenaDiaryClient.Models.Hatena | ||
66 | 68 | { |
67 | 69 | return PostOrPut(reqUri, "PUT", reqData, enc, userName, password); |
68 | 70 | } |
71 | + | |
72 | + public static string Put(string reqUri, NameValueCollection headers, byte[] data, Encoding enc, string userName, string password) | |
73 | + { | |
74 | + var req = WebRequest.Create(reqUri); | |
75 | + req.Method = "PUT"; | |
76 | + req.Headers.Add(CreateHeader(userName, password)); | |
77 | + if (headers != null) | |
78 | + req.Headers.Add(headers); | |
79 | + if (data != null && data.Any()) | |
80 | + { | |
81 | + using (var stream = req.GetRequestStream()) | |
82 | + stream.Write(data, 0, data.Length); | |
83 | + } | |
84 | + using (var sr = new StreamReader(req.GetResponse().GetResponseStream(), enc ?? Encoding.UTF8)) | |
85 | + return sr.ReadToEnd(); | |
86 | + } | |
69 | 87 | } |
70 | 88 | } |
\ No newline at end of file |