Method: AnswersEngine::CLI::ScraperPage#add

Defined in:
lib/answersengine/cli/scraper_page.rb

#add(scraper_name, url) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/answersengine/cli/scraper_page.rb', line 47

def add(scraper_name, url)
  begin
    options[:headers] = JSON.parse(options[:headers]) if options[:headers]
    options[:vars] = JSON.parse(options[:vars]) if options[:vars]
    method = options[:method]

    if options[:job]
      client = Client::JobPage.new(options)
      puts "#{client.enqueue(options[:job], method, url, options)}"
    else
      client = Client::ScraperJobPage.new(options)
      puts "#{client.enqueue(scraper_name, method, url, options)}"
    end

  rescue JSON::ParserError
    if options[:headers]
      puts "Error: #{options[:headers]} on headers is not a valid JSON"
    end
    if options[:vars]
      puts "Error: #{options[:vars]} on vars is not a valid JSON"
    end
  end
end