Class: Ruboty::Handlers::Crawl

Inherits:
Base
  • Object
show all
Defined in:
lib/ruboty/handlers/ymcrawl.rb

Instance Method Summary collapse

Instance Method Details

#crawl(message) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ruboty/handlers/ymcrawl.rb', line 41

def crawl(message)
  puts "crawl start in handlers"
  url = (message[:url] == nil) ? "-- please set url --" : message[:url]
  begin
    crawl = CrawlManager.instance.get_crawl
    uploader = crawl.get_uploader

    # upload先がlocal以外かつアクセストークンが取得されていない場合は、取得先URLを示して終了
    if not uploader.access_token? and uploader.get_name != "local"
      message.reply( get_access_token_message( uploader.get_access_token_url ) )
      return nil
    end

    message.reply("rubot is crawling from #{url}")
    zip_paths = crawl.start([url])
    message.reply("get zip file => #{zip_paths}")
  rescue URI::InvalidURIError => ex
    puts ex
    message.reply("URL is invalid. please retry.")
  rescue => ex
    puts "error raise in Crawl.crawl"
    puts ex
    message.reply("Sorry, error occurred.")
    message.reply("Please feedback this error to [email protected]")
    message.reply(ex)
  end
end

#get_access_token_message(url) ⇒ Object



34
35
36
37
38
39
# File 'lib/ruboty/handlers/ymcrawl.rb', line 34

def get_access_token_message(url)
  return "You don't have access token.
  1. Go to: #{url}
  2. Click \"Allow\" (you might have to log in first).
  3. reply to bot as \"@bot dropbox:auth (auth_code) \""
end