2008年 01月 01日

Ruby の Atom/AtomPub ライブラリ

atomutil がいいっぽいですね。http://rubyforge.org/projects/atomutil/ とかいうか他に選択肢ない感 (rubyforge で atom を検索するといっぱいでてくるけど、殆どハズれ (リリースいっこもない))

つかってみたら、feed.links に feed 直下の要素ではない link 要素も含まれてしまう。

--- atomutil.rb.orig	2008-01-01 15:07:56.000000000 +0900
+++ atomutil.rb	2008-01-01 15:05:54.000000000 +0900
@@ -604,10 +604,10 @@
     def child_xpath(ns, element_name, attributes=nil)
       ns_uri = ns.is_a?(Namespace) ? ns.uri : ns
       unless !attributes.nil? && attributes.is_a?(Hash)
-        "descendant-or-self::*[local-name()='#{element_name}' and namespace-uri()='#{ns_uri}']"
+        "child::*[local-name()='#{element_name}' and namespace-uri()='#{ns_uri}']"
       else
         attr_str = attributes.collect{|key, val| "@#{key.to_s}='#{val}'"}.join(' and ')
-        "descendant-or-self::*[local-name()='#{element_name}' and namespace-uri()='#{ns_uri}' and #{attr_str}]"
+        "child::*[local-name()='#{element_name}' and namespace-uri()='#{ns_uri}' and #{attr_str}]"
       end
     end
   end

rubyforge の Tracker は使われてんのかなぁ……

ref. http://d.hatena.ne.jp/lyokato/20071211/1197353609

URI#path がつかわれてるけど、Atom ってクエリ文字列ふくんでる URI はダメなのかな……

client.get_resource("http://example.com/foo?bar") がたぶん失敗する (URI#path => "/foo")。rfc5023 には特に query についての記述はないっぽいけど、こういうリソースが妥当なのかどうか (実際あるのか) わからない。