Module: ConfigHelper

Included in:
ConfigController
Defined in:
lib/helpers/config_helper.rb

Instance Method Summary collapse

Instance Method Details

#upload(url, file, key, username, password) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/helpers/config_helper.rb', line 2

def upload(url, file, key, username, password)
  res = ''
  url = URI.parse(url)
  File.open(File.join(LIB_DIR,file)) do |conf|
    req = Net::HTTP::Post::Multipart.new(url.path,
      key => UploadIO.new(conf, "application/octet-stream", File.join(LIB_DIR,file)))
    req.basic_auth username, password
    res = Net::HTTP.start(url.host, url.port) do |http|
      http.request(req)
    end
  end
  res.body
end