Class: DiffbotSimple::V2::Crawlbot

Inherits:
Object
  • Object
show all
Includes:
ApiHelper
Defined in:
lib/diffbot_simple/v2/crawlbot.rb

Overview

Instance Method Summary collapse

Methods included from ApiHelper

#initialize, #to_crawl_api_url

Instance Method Details

#allArray

Get all your crawls as an array The “jobs” parameter is stripped and only the array is returned



12
13
14
# File 'lib/diffbot_simple/v2/crawlbot.rb', line 12

def all
  execute_call()[:jobs]
end

#delete(name: nil) ⇒ Hash

Deletes a crawl



32
33
34
35
# File 'lib/diffbot_simple/v2/crawlbot.rb', line 32

def delete name: nil
  raise ArgumentError.new "Must pass a name for the crawl to delete" unless name
  execute_call name: name, delete: 1
end

#pause(name: nil) ⇒ Hash

Pauses a crawl



41
42
43
# File 'lib/diffbot_simple/v2/crawlbot.rb', line 41

def pause name: nil
  single_crawl name: name, pause: 1
end

#post_initializeObject



5
6
7
# File 'lib/diffbot_simple/v2/crawlbot.rb', line 5

def post_initialize
  @api = :crawl
end

#restart(name: nil) ⇒ Hash

Restarts a crawl



57
58
59
60
# File 'lib/diffbot_simple/v2/crawlbot.rb', line 57

def restart name: nil
  raise ArgumentError.new "Must pass a name for the crawl to restart" unless name
  execute_call name: name, restart: 1
end

#result(name: nil) ⇒ Array

Get the crawl-result (downloadJson from diffbot crawl)



66
67
68
69
70
71
# File 'lib/diffbot_simple/v2/crawlbot.rb', line 66

def result name: nil
  crawl = single_crawl name: name
  download_url = crawl[:downloadJson]
  response = api_client.get download_url
  symbolize response
end

#single_crawl(name: nil, **options) ⇒ Hash

Gets, creates or updates a named crawl

@**options options from www.diffbot.com/dev/docs/crawl/ when updating or creating a crawl



21
22
23
24
25
26
# File 'lib/diffbot_simple/v2/crawlbot.rb', line 21

def single_crawl name: nil, **options
  raise ArgumentError.new "Must pass a name for the crawl" unless name
  response = execute_call options.merge(name: name)
  jobs = response[:jobs]
  jobs.first
end

#unpause(name: nil) ⇒ Hash

Unpauses/ resumes a crawl



49
50
51
# File 'lib/diffbot_simple/v2/crawlbot.rb', line 49

def unpause name: nil
  single_crawl name: name, pause: 0
end