Class: Tropeco::Plugins::DownloadFile

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin
Defined in:
lib/tropeco/plugins/download.rb

Instance Method Summary collapse

Instance Method Details

#download(url) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tropeco/plugins/download.rb', line 18

def download(url)
  debug "URL[#{url}]"
  url = URI.parse url
  Net::HTTP.start(url.host, url.port) do |http|
    resp = http.get(url.path)
    open('tempfile', "wb") do |file|
      file.write(resp.body)
    end
  end
  debug "End download"
end

#execute(m, url) ⇒ Object



12
13
14
15
16
# File 'lib/tropeco/plugins/download.rb', line 12

def execute(m, url)
  m.reply "Comecando"
  download(url)
  m.reply "Terminei."
end