 #   hubot scripts for amazon-product-api hubot
 #
 # Commands:
-#   hubot "考え中" - "考え中"
+#   hubot kindle最新刊 <title> - kindle 版の最新刊を検索して表示
+#   hubot comic最新刊 <title> - コミック(kindle除く)版の最新刊を検索して表示
 #
 # Author:
 #   aha-oretama <sekine_y_529@msn.com>

    operationHelper = new OperationHelper config
  return operationHelper

search = (msg, operationHelper, query, isKindle, during, page) ->

  binding = if isKindle then 'kindle' else 'not kindle'

  operationHelper.execute('ItemSearch',{
    'SearchIndex': 'Books',
    'BrowseNode': comicNode,
    'Title': query,
#    'Power':"pubdate:#{during} and binding:#{binding}",
    'Power':"pubdate:during 08-2016 or pubdate:during 07-2016 and binding:#{binding}",
    'ResponseGroup':'Large',
    'Sort':'daterank',
    'ItemPage': page

      msg.send "#{baseItem.Title[0]}が見つかったよー\n発売日は #{if isKindle then baseItem.ReleaseDate[0] else baseItem.PublicationDate[0]}だよ #{item.DetailPageURL[0]}"

    if page < totalPages and page < 10
      setTimeout(search, 5000, msg, operationHelper, query,isKindle,month, page + 1)

  ).catch((err) ->
    console.log("error:", err)
