Class: AnswersEngine::Client::ScraperJob

Inherits:
Base
  • Object
show all
Defined in:
lib/answersengine/client/scraper_job.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(scraper_name, opts = {}) ⇒ Object



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

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

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



33
34
35
36
# File 'lib/answersengine/client/scraper_job.rb', line 33

def cancel(scraper_name, opts={})
  opts[:status] = 'cancelled'
  update(scraper_name, opts)
end

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



9
10
11
12
13
14
15
16
# File 'lib/answersengine/client/scraper_job.rb', line 9

def create(scraper_name, opts={})
  body = {}
  body[:standard_worker_count] = opts[:workers] if opts[:workers]
  body[:browser_worker_count] = opts[:browsers] if opts[:browsers]
  body[:proxy_type] = opts[:proxy_type] if opts[:proxy_type]
  params = @options.merge({body: body.to_json})
  self.class.post("/scrapers/#{scraper_name}/jobs", params)
end

#find(scraper_name) ⇒ Object



18
19
20
# File 'lib/answersengine/client/scraper_job.rb', line 18

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

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



43
44
45
46
# File 'lib/answersengine/client/scraper_job.rb', line 43

def pause(scraper_name, opts={})
  opts[:status] = 'paused'
  update(scraper_name, opts)
end

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



38
39
40
41
# File 'lib/answersengine/client/scraper_job.rb', line 38

def resume(scraper_name, opts={})
  opts[:status] = 'active'
  update(scraper_name, opts)
end

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



22
23
24
25
26
27
28
29
30
31
# File 'lib/answersengine/client/scraper_job.rb', line 22

def update(scraper_name, opts={})
  body = {}
  body[:status] = opts[:status] if opts[:status]
  body[:standard_worker_count] = opts[:workers] if opts[:workers]
  body[:browser_worker_count] = opts[:browsers] if opts[:browsers]
  body[:proxy_type] = opts[:proxy_type] if opts[:proxy_type]
  params = @options.merge({body: body.to_json})

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