Class: Datahen::CLI::JobOutput

Inherits:
Thor
  • Object
show all
Defined in:
lib/datahen/cli/job_output.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



6
7
8
# File 'lib/datahen/cli/job_output.rb', line 6

def self.banner(command, namespace = nil, subcommand = false)
  "#{basename} #{@package_name} #{command.usage}"
end

Instance Method Details

#collections(scraper_name) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/datahen/cli/job_output.rb', line 75

def collections(scraper_name)

  if options[:job]
    client = Client::JobOutput.new(options)
    json = JSON.parse(client.collections(options[:job]).body)
    if json['error'] == ""
      puts "#{JSON.pretty_generate(json['data'])}"
    else 
      puts "#{JSON.pretty_generate(json['error'])}"
    end
  else
    client = Client::ScraperJobOutput.new(options)
    json = JSON.parse(client.collections(scraper_name).body)
    if json['error'] == ""
      puts "#{JSON.pretty_generate(json['data'])}"
    else 
      puts "#{JSON.pretty_generate(json['error'])}"
    end
  end
end

#list(scraper_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/datahen/cli/job_output.rb', line 19

def list(scraper_name)
  collection = options.fetch(:collection) { 'default' }
  if options[:job]
    client = Client::JobOutput.new(options)
    json = JSON.parse(client.all(options[:job], collection).body)
    if json['error'] == ""
      puts "#{JSON.pretty_generate(json['data'])}"
    else 
      puts "#{JSON.pretty_generate(json['error'])}"
    end
  else
    client = Client::ScraperJobOutput.new(options)
    json = JSON.parse(client.all(scraper_name, collection).body)
    if json['error'] == ""
      puts "#{JSON.pretty_generate(json['data'])}"
    else 
      puts "#{JSON.pretty_generate(json['error'])}"
    end
  end
end

#show(scraper_name, id) ⇒ Object



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

def show(scraper_name, id)
  collection = options.fetch(:collection) { 'default' }
  if options[:job]
    client = Client::JobOutput.new(options)
    json = JSON.parse(client.find(options[:job], collection, id).body)
    if json['error'] == ""
      puts "#{JSON.pretty_generate(json['data'])}"
    else 
      puts "#{JSON.pretty_generate(json['error'])}"
    end
  else
    client = Client::ScraperJobOutput.new(options)
    json = JSON.parse(client.find(scraper_name, collection, id).body)
    if json['error'] == ""
      puts "#{JSON.pretty_generate(json['data'])}"
    else 
      puts "#{JSON.pretty_generate(json['error'])}"
    end
  end
end