Class: Webget

Inherits:
QuartzPlugin show all
Defined in:
lib/plugins/webget.rb

Constant Summary collapse

@@version_major =
0
@@version_minor =
0
@@version_revision =
1

Instance Method Summary collapse

Methods inherited from QuartzPlugin

#get_version, #initialize, #payload, #run_result, #run_shell

Constructor Details

This class inherits a constructor from QuartzPlugin

Instance Method Details

#infoObject



10
11
12
# File 'lib/plugins/webget.rb', line 10

def info
  { :uid => "6b5f722d214f4d71a5be237d44094721", :name => "WebGet", :version => get_version }
end

#run(message) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/plugins/webget.rb', line 14

def run(message)
  @log.debug "Running with #{message}"
  payload = payload(message)
  url = payload['url']
  local = payload['local file']
  @log.info "Webget from #{url} into #{local}"

  begin
    response = HTTParty.get(url)
    if response.code == 200
      body = response.body
      file = File.new(local, "w")
      begin
        file.write(body)
        run_result(true, "Saved WebGet to local file")
      ensure
        file.close
      end
    else
      run_result(false, response.message)
    end
  rescue => ex
    run_result(false, "Failed to webget due to #{ex}")
  end
end