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
pass = @conf.options['booklog_password']
booklog = Booklog::Agent.new(user, pass)
- booklog.comment(asin, @entry.alternate)
+ booklog.comment(asin, @entry.alternate_uri)
""
end
end
booklog.edit(asin, {'rank' => rank.to_s,
'status' => booklog_status,
- 'description' => @entry.alternate})
+ 'description' => @entry.alternate_uri})
""
end