OSDN Git Service

added tag.rb
authormasahino <masahino@0978bef0-6439-0410-a06b-a62e4d60c955>
Fri, 5 Sep 2008 12:22:20 +0000 (12:22 +0000)
committermasahino <masahino@0978bef0-6439-0410-a06b-a62e4d60c955>
Fri, 5 Sep 2008 12:22:20 +0000 (12:22 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lbw/ldblogwriter/trunk@70 0978bef0-6439-0410-a06b-a62e4d60c955

lib/ldblogwriter/entry.rb
plugins/tag.rb [new file with mode: 0644]

index d169dc2..1371c94 100644 (file)
@@ -5,6 +5,7 @@ module LDBlogWriter
     attr_accessor :summary, :alternate
     attr_accessor :send_tb
     attr_accessor :trackback_url_array
+    attr_accessor :edit_uri
     def initialize(conf, title, category = nil, content = "")
       @conf = conf
       @title = title
@@ -71,6 +72,7 @@ module LDBlogWriter
     end
 
     def get_entry_info(edit_uri)
+      @edit_uri = edit_uri
       entry_info = Command.new.get(edit_uri, @conf.username, @conf.password)
       entry_info.doc.elements.each('entry/title') do |e|
         if $DEBUG
diff --git a/plugins/tag.rb b/plugins/tag.rb
new file mode 100644 (file)
index 0000000..89828c3
--- /dev/null
@@ -0,0 +1,32 @@
+def tag(tag_str)
+  "<!-- #{tag_str} -->"
+end
+
+def tag_post(tag_str)
+  case @conf.service
+  when 'livedoor'
+    require 'rubygems'
+    require 'mechanize'
+    
+    blog_id = @conf.blog_id
+    entry_id = @entry.edit_uri.split("=").last
+    
+    login_uri = "http://member.livedoor.com/login/"
+    edit_uri = "http://cms.blog.livedoor.com/cms/article/edit?blog_id=#{blog_id}&id=#{entry_id}"
+
+    agent = WWW::Mechanize.new
+    page = agent.get(login_uri)
+    login_form = page.forms.with.name('loginForm').first
+
+    login_form['livedoor_id'] = @conf.username
+    login_form['password'] = @conf.password
+    login_form.submit
+
+    page = agent.get(edit_uri)
+    edit_form = page.forms.with.name('ArticleForm').first
+    puts edit_form
+    edit_form['tag'] = tag_str
+    edit_form.submit(edit_form.buttons.with.name('.save').first)
+  else
+  end
+end