OSDN Git Service

added new plugin
authormasahino <masahino@0978bef0-6439-0410-a06b-a62e4d60c955>
Mon, 14 Jul 2008 14:06:13 +0000 (14:06 +0000)
committermasahino <masahino@0978bef0-6439-0410-a06b-a62e4d60c955>
Mon, 14 Jul 2008 14:06:13 +0000 (14:06 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lbw/ldblogwriter/trunk@62 0978bef0-6439-0410-a06b-a62e4d60c955

plugins/stack.rb [new file with mode: 0644]

diff --git a/plugins/stack.rb b/plugins/stack.rb
new file mode 100644 (file)
index 0000000..364c6b6
--- /dev/null
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+
+# Stack Stock Booksの情報更新
+# #stack(<ASIN>, <STATE>)
+# stateは、"unread"|"reading"|"read"|"wish"
+# 利用者IDとAPIトークンは設定ファイルで指定
+# @options['stack_api_token']
+# @options['stack_id']
+def stack(asin, state)
+  require 'net/http'
+  require 'yaml'
+  require 'uri'
+  require 'date'
+
+  user = @conf.options['stack_id']
+  token = @conf.options['stack_api_token']
+  Net::HTTP.version_1_2
+  update_uri_str = "http://stack.nayutaya.jp/api/#{user}/#{token}/stocks/update.1"
+  uri = URI.parse(update_uri_str)
+  book_info = Hash.new
+  book_info['asin'] = asin
+  book_info['date'] = Date.today.to_s
+  book_info['state'] = state
+  puts update_uri_str
+  Net::HTTP.start(uri.host, uri.port) do |http|
+    response = http.post(uri.path, "request=#{URI.encode([book_info].to_yaml)}")
+    # error処理
+    p response.body
+  end
+  ""
+end
+
+if $0 == __FILE__
+  $test = true
+end
+
+if defined?($test) && $test
+  require 'test/unit'
+  require 'ldblogwriter/config'
+
+
+  class TestStack < Test::Unit::TestCase
+    def setup
+      @conf = LDBlogWriter::Config.new()
+    end
+
+    # 利用者IDとAPIトークンが設定されてなければ、エラー
+    def test_config
+    end
+    
+    # asinとstateのチェック
+    def test_args
+    end
+
+  end
+end
+
+