OSDN Git Service

change web bookshelf server API
authormasahino <masahino@gmail.com>
Thu, 10 Mar 2011 13:45:07 +0000 (22:45 +0900)
committermasahino <masahino@gmail.com>
Thu, 10 Mar 2011 13:45:07 +0000 (22:45 +0900)
plugins/add_bookscope.rb
plugins/booklog.rb
plugins/stack.rb

index d56d21c..48e9184 100644 (file)
@@ -14,24 +14,55 @@ def add_bookscope(asin)
   begin
     require 'mechanize'
   rescue LoadError
-    return "<!-- mechanizeが無い -->\n"
+    "<!-- mechanizeが無い -->\n"
+    return
   end
   email = @conf.options['bookscope_email']
   user_name = @conf.options['bookscope_name']
   password = @conf.options['bookscope_password']
   if user_name == nil
-    return "<!-- ユーザIDが設定されていません -->\n"
+    "<!-- ユーザIDが設定されていません -->\n"
   end
-  agent = WWW::Mechanize.new
-  ret = agent.post("http://bookscope.net/account/login", 'email' => email,
-                   'password' => password)
+  agent = Mechanize.new
+  login_form = agent.get("http://bookscope.net/").form_with(:action => /login/)
+  login_form['email'] = email
+  login_form['password'] = password
+  login_form.submit
+#  ret = agent.post("http://bookscope.net/account/login", 'email' => email,
+#                   'password' => password)
   #  $stderr.puts ret.body
   bookscope_uri = "http://bookscope.net/#{user_name}/belongings/create?barcode=#{asin}"
-  if $DEBuG
-    $stderr.puts bookscope_uri
-  end
+  $stderr.puts bookscope_uri
   #  puts bookscope_uri
-  ret = agent.get(bookscope_uri).body
+  begin
+    ret = agent.get(bookscope_uri)
+  rescue
+  end
   return ""
 end
 
+
+if $0 == __FILE__
+  $test = true
+end
+
+if defined?($test) && $test
+  require 'test/unit'
+  require 'ldblogwriter/config'
+
+  class TestAddBookScope < Test::Unit::TestCase
+    def setup
+      @conf = LDBlogWriter::Config.new()
+      @conf.options['bookscope_name'] = 'testid'
+    end
+
+    def test_no_userid
+      assert_equal("<!-- ユーザIDが設定されていません -->\n", add_bookscope('1'))
+    end
+
+    def test_add_bookscope
+      @conf = LDBlogWriter::Config.new(ENV['HOME']+"/.ldblogwriter.conf")
+      assert_equal("<!-- BookScopeに登録しました -->\n", add_bookscope('4480427937'))
+    end
+  end
+end
index 4ce0725..73b8240 100644 (file)
@@ -22,7 +22,7 @@ def booklog_post(asin)
   pass = @conf.options['booklog_password']
   booklog = Booklog::Agent.new(user, pass)
   
-  booklog.comment(asin, @entry.alternate)
+  booklog.comment(asin, @entry.alternate_uri)
   ""
 end
 
@@ -44,7 +44,7 @@ def booklog_post(asin, state, rank)
   end
   booklog.edit(asin, {'rank' => rank.to_s, 
                  'status' => booklog_status,
-                 'description' => @entry.alternate})
+                 'description' => @entry.alternate_uri})
   ""
 end
 
index b9da07a..f3eada6 100644 (file)
@@ -42,7 +42,7 @@ def stack_post(asin, state)
   
   stack = StackStockBooks::Agent.new(user, op_server, op_id, op_password)
   
-  stack.edit_note(asin, @entry.alternate)
+  stack.edit_note(asin, @entry.alternate_uri)
 end