Class: AnswersEngine::Client::JobPage

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



8
9
10
11
# File 'lib/answersengine/client/job_page.rb', line 8

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

#enqueue(job_id, method, url, opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/answersengine/client/job_page.rb', line 24

def enqueue(job_id, method, url, opts={})
  body = {}
  body[:method] =  method != "" ? method : "GET"
  body[:url] =  url
  body[:page_type] = opts[:page_type] if opts[:page_type]
  body[:priority] = opts[:priority] if opts[:priority]
  body[:fetch_type] = opts[:fetch_type] if opts[:fetch_type]
  body[:body] = opts[:body] if opts[:body]
  body[:headers] = opts[:headers] if opts[:headers]
  body[:vars] = opts[:vars] if opts[:vars]
  body[:force_fetch] = opts[:force_fetch] if opts[:force_fetch]
  body[:freshness] = opts[:freshness] if opts[:freshness]
  body[:ua_type] = opts[:ua_type] if opts[:ua_type]
  body[:no_redirect] = opts[:no_redirect] if opts[:no_redirect]
  body[:cookie] = opts[:cookie] if opts[:cookie]

  params = @options.merge({body: body.to_json})

  self.class.post("/jobs/#{job_id}/pages", params)
end

#find(job_id, gid) ⇒ Object



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

def find(job_id, gid)
  self.class.get("/jobs/#{job_id}/pages/#{gid}", @options)
end

#parsing_update(job_id, gid, opts = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/answersengine/client/job_page.rb', line 45

def parsing_update(job_id, gid, opts={})
  body = {}
  body[:outputs] = opts.fetch(:outputs) {[]}
  body[:pages] = opts.fetch(:pages) {[]}
  body[:parsing_status] = opts.fetch(:parsing_status){ nil }
  body[:log_error] = opts[:log_error] if opts[:log_error]

  params = @options.merge({body: body.to_json})

  self.class.put("/jobs/#{job_id}/pages/#{gid}/parsing_update", params)
end

#update(job_id, gid, opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/answersengine/client/job_page.rb', line 13

def update(job_id, gid, opts={})
  body = {}
  body[:page_type] = opts[:page_type] if opts[:page_type]
  body[:priority] = opts[:priority] if opts[:priority]
  body[:vars] = opts[:vars] if opts[:vars]

  params = @options.merge({body: body.to_json})

  self.class.put("/jobs/#{job_id}/pages/#{gid}", params)
end