Class: Jenkins2::API::Plugins::Proxy

Inherits:
ResourceProxy show all
Defined in:
lib/jenkins2/api/plugins.rb

Constant Summary collapse

BOUNDARY =
'----Jenkins2RubyMultipartClient' + rand(1_000_000).to_s

Instance Attribute Summary

Attributes inherited from ResourceProxy

#connection, #path

Instance Method Summary collapse

Methods inherited from ResourceProxy

#initialize, #method_missing, #raw, #respond_to_missing?, #subject

Constructor Details

This class inherits a constructor from Jenkins2::ResourceProxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Jenkins2::ResourceProxy

Instance Method Details

#install(*short_names) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/jenkins2/api/plugins.rb', line 13

def install(*short_names)
	path = build_path 'install'
	form_data = short_names.flatten.inject({}) do |memo, obj|
		memo.merge "plugin.#{obj}.default" => 'on'
	end.merge('dynamicLoad' => 'Install without restart')
	connection.post(path, ::URI.encode_www_form(form_data)).code == '302'
end

#plugin(id, params = {}) ⇒ Object



34
35
36
37
# File 'lib/jenkins2/api/plugins.rb', line 34

def plugin(id, params={})
	path = build_path 'plugin', id
	Plugin::Proxy.new connection, path, params
end

#upload(hpi_file, filename) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jenkins2/api/plugins.rb', line 21

def upload(hpi_file, filename)
	body = "--#{BOUNDARY}\r\n"\
		"Content-Disposition: form-data; name=\"file0\"; filename=\"#{filename}\"\r\n"\
		"Content-Type: application/octet-stream\r\n\r\n"\
		"#{hpi_file}\r\n"\
		"--#{BOUNDARY}\r\n"\
		"Content-Disposition: form-data; name=\"json\"\r\n\r\n"\
		"\r\n\r\n--#{BOUNDARY}--\r\n"
	connection.post(build_path('uploadPlugin'), body) do |req|
		req['Content-Type'] = "multipart/form-data, boundary=#{BOUNDARY}"
	end.code == '302'
end