Class: AnswersEngine::Client::Scraper

Inherits:
Base
  • Object
show all
Defined in:
lib/answersengine/client/scraper.rb

Instance Method Summary collapse

Methods inherited from Base

#auth_token, #auth_token=, #env_api_url, env_auth_token, #initialize

Constructor Details

This class inherits a constructor from AnswersEngine::Client::Base

Instance Method Details

#all(opts = {}) ⇒ Object



9
10
11
12
# File 'lib/answersengine/client/scraper.rb', line 9

def all(opts={})
  params = @options.merge opts
  self.class.get("/scrapers", params)
end

#create(scraper_name, git_repository, opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/answersengine/client/scraper.rb', line 14

def create(scraper_name, git_repository, opts={})
  body = {}
  body[:name] = scraper_name
  body[:git_repository] = git_repository
  body[:git_branch] = opts[:branch] || opts[:git_branch] || "master" if opts[:branch] || opts[:git_branch]
  body[:freshness_type] = opts[:freshness_type] if opts[:freshness_type]
  body[:force_fetch] = opts[:force_fetch] if opts[:force_fetch]
  body[:standard_worker_count] = opts[:workers] || opts[:standard_worker_count] if opts[:workers] || opts[:standard_worker_count]
  body[:browser_worker_count] = opts[:browsers] || opts[:browser_worker_count] if opts[:browsers] || opts[:browser_worker_count]
  body[:proxy_type] = opts[:proxy_type] if opts[:proxy_type]
  body[:disable_scheduler] = opts[:disable_scheduler] if opts[:disable_scheduler]
  body[:cancel_current_job] = opts[:cancel_current_job] if opts[:cancel_current_job]
  body[:schedule] = opts[:schedule] if opts[:schedule]
  body[:timezone] = opts[:timezone] if opts[:timezone]
  params = @options.merge({body: body.to_json})
  self.class.post("/scrapers", params)
end

#delete(scraper_name, opts = {}) ⇒ Object



51
52
53
54
# File 'lib/answersengine/client/scraper.rb', line 51

def delete(scraper_name, opts={})
  params = @options.merge(opts)
  self.class.delete("/scrapers/#{scraper_name}", params)
end

#find(scraper_name) ⇒ Object



5
6
7
# File 'lib/answersengine/client/scraper.rb', line 5

def find(scraper_name)
  self.class.get("/scrapers/#{scraper_name}", @options)
end

#update(scraper_name, opts = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/answersengine/client/scraper.rb', line 32

def update(scraper_name, opts={})
  body = {}
  body[:name] = opts[:name] if opts[:name]
  body[:git_repository] = opts[:repo] || opts[:git_repository] if opts[:repo] || opts[:git_repository]
  body[:git_branch] = opts[:branch] || opts[:git_branch] if opts[:branch] || opts[:git_branch]
  body[:freshness_type] = opts[:freshness_type] if opts[:freshness_type]
  body[:force_fetch] = opts[:force_fetch] if opts.has_key?("force_fetch") || opts.has_key?(:force_fetch)
  body[:standard_worker_count] = opts[:workers] || opts[:standard_worker_count] if opts[:workers] || opts[:standard_worker_count]
  body[:browser_worker_count] = opts[:browsers] || opts[:browser_worker_count] if opts[:browsers] || opts[:browser_worker_count]
  body[:proxy_type] = opts[:proxy_type] if opts[:proxy_type]
  body[:disable_scheduler] = opts[:disable_scheduler] if opts.has_key?("disable_scheduler") || opts.has_key?(:disable_scheduler)
  body[:cancel_current_job] = opts[:cancel_current_job] if opts.has_key?("cancel_current_job") || opts.has_key?(:cancel_current_job)
  body[:schedule] = opts[:schedule] if opts[:schedule]
  body[:timezone] = opts[:timezone] if opts[:timezone]
  params = @options.merge({body: body.to_json})

  self.class.put("/scrapers/#{scraper_name}", params)
end