Class: PuppetForgeServer::Http::HttpClient
Instance Method Summary
collapse
inspect_without, #inspect_without
#cache_instance, #configure_cache
Constructor Details
#initialize(cache = nil) ⇒ HttpClient
Returns a new instance of HttpClient.
Instance Method Details
#download(url) ⇒ Object
53
54
55
|
# File 'lib/puppet_forge_server/http/http_client.rb', line 53
def download(url)
open_uri(url)
end
|
#get(url) ⇒ Object
49
50
51
|
# File 'lib/puppet_forge_server/http/http_client.rb', line 49
def get(url)
open_uri(url).read
end
|
#inspect ⇒ Object
57
58
59
60
61
62
|
# File 'lib/puppet_forge_server/http/http_client.rb', line 57
def inspect
cache_inspected = @cache.inspect_without [ :@data ]
cache_inspected.gsub!(/>$/, ", @size=#{@cache.size}>")
inspected = inspect_without [ :@cache ]
inspected.gsub(/>$/, ", @cache=#{cache_inspected}>")
end
|
#post_file(url, file_hash, options = {}) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/puppet_forge_server/http/http_client.rb', line 36
def post_file(url, file_hash, options = {})
options = { :http => {}, :headers => {}}.merge(options)
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
options[:http].each {|k,v| http.call(k, v) }
req = Net::HTTP::Post::Multipart.new uri.path, "file" => UploadIO.new(File.open(file_hash[:tempfile]), file_hash[:type], file_hash[:filename])
options[:headers].each {|k,v| req[k] = v }
http.request(req)
end
|