jenkins_api_client2 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,460 @@
1
+ #
2
+ # Copyright (c) 2012-2013 Kannan Manickam <arangamani.kannan@gmail.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+
23
+ module JenkinsApi
24
+ class Client
25
+ # This classes communicates with the /pluginManager API for listing
26
+ # installed plugins, installing new plgins through hacks, and performing a
27
+ # lot of operations on installed plugins. It also gives the ability to
28
+ # obtain the details about available plugins in Jenkins update center by
29
+ # communicating with /updateCenter API.
30
+ #
31
+ class PluginManager
32
+
33
+ # Initializes a new PluginManager object.
34
+ #
35
+ # @param [Object] client a reference to Client
36
+ #
37
+ def initialize(client)
38
+ @client = client
39
+ @logger = @client.logger
40
+ end
41
+
42
+ # Returns a string representation of PluginManager class.
43
+ #
44
+ def to_s
45
+ "#<JenkinsApi::Client::PluginManager>"
46
+ end
47
+
48
+ # Defines a method to perform the given action on plugin(s)
49
+ #
50
+ # @param action [Symbol] the action to perform
51
+ # @param post_endpoint [Symbol] the endpoint in the POST request for the
52
+ # action
53
+ #
54
+ def self.plugin_action_method(action, post_endpoint)
55
+ define_method(action) do |plugins|
56
+ plugins = [plugins] unless plugins.is_a?(Array)
57
+ @logger.info "Performing '#{action}' on plugins: #{plugins.inspect}"
58
+ plugins.each do |plugin|
59
+ @client.api_post_request(
60
+ "/pluginManager/plugin/#{plugin}/#{post_endpoint}"
61
+ )
62
+ end
63
+ end
64
+ end
65
+
66
+ # Obtains the list of installed plugins from Jenkins along with their
67
+ # version numbers with optional filters
68
+ #
69
+ # @param filters [Hash] optional filters to apply. Use symbols for filter
70
+ # keys
71
+ #
72
+ # @option filters [Boolean] :active filter active/non-active plugins
73
+ # @option filters [Boolean] :bundled filter bundled/non-bundled plugins
74
+ # @option filters [Boolean] :deleted filter deleted/available plugins
75
+ # @option filters [Boolean] :downgradable filter downgradable plugins
76
+ # @option filters [Boolean] :enabled filter enabled/disabled plugins
77
+ # @option filters [Boolean] :hasUpdate filter plugins that has update
78
+ # available. Note that 'U' is capitalized in hasUpdate.
79
+ # @option filters [Boolean] :pinned filter pinned/un-pinned plugins
80
+ #
81
+ # @return [Hash<String, String>] installed plugins and their versions
82
+ # matching the filter provided. returns an empty hash if there are no
83
+ # plugins matched the filters or no plugins are installed in jenkins.
84
+ #
85
+ # @example Listing installed plugins from jenkins
86
+ # >> @client.plugin.list_installed
87
+ # => {
88
+ # "mailer" => "1.5",
89
+ # "external-monitor-job" => "1.1",
90
+ # "ldap" => "1.2"
91
+ # }
92
+ # >> @client.plugin.list_installed(true)
93
+ # => {}
94
+ #
95
+ # @example Listing installed plugins based on filters provided
96
+ # >> @client.plugin.list_installed(
97
+ # :active => true, :deleted => false, :bundled => false
98
+ # )
99
+ # => {
100
+ # "sourcemonitor" => "0.2",
101
+ # "sms-notification" => "1.0",
102
+ # "jquery" => "1.7.2-1",
103
+ # "simple-theme-plugin" => "0.3",
104
+ # "jquery-ui" => "1.0.2",
105
+ # "analysis-core" => "1.49"
106
+ # }
107
+ #
108
+ def list_installed(filters = {})
109
+ supported_filters = [
110
+ :active, :bundled, :deleted, :downgradable, :enabled, :hasUpdate,
111
+ :pinned
112
+ ]
113
+ unless filters.keys.all? { |filter| supported_filters.include?(filter) }
114
+ raise ArgumentError, "Unsupported filters specified." +
115
+ " Supported filters: #{supported_filters.inspect}"
116
+ end
117
+ tree_filters = filters.empty? ? "" : ",#{filters.keys.join(",")}"
118
+ plugins = @client.api_get_request(
119
+ "/pluginManager",
120
+ "tree=plugins[shortName,version#{tree_filters}]"
121
+ )["plugins"]
122
+ installed = Hash[plugins.map do |plugin|
123
+ if filters.keys.all? { |key| plugin[key.to_s] == filters[key] }
124
+ [plugin["shortName"], plugin["version"]]
125
+ end
126
+ end.compact]
127
+ installed
128
+ end
129
+
130
+ # Obtains the details of a single installed plugin
131
+ #
132
+ # @param plugin [String] the plugin ID of the desired plugin
133
+ #
134
+ # @return [Hash] the details of the given installed plugin
135
+ #
136
+ # @example Obtain the information of an installed plugin
137
+ # >> @client.plugin.get_installed_info "ldap"
138
+ # => {
139
+ # "active"=>false,
140
+ # "backupVersion"=>"1.2",
141
+ # "bundled"=>true,
142
+ # "deleted"=>false,
143
+ # "dependencies"=>[],
144
+ # "downgradable"=>true,
145
+ # "enabled"=>false,
146
+ # "hasUpdate"=>false,
147
+ # "longName"=>"LDAP Plugin",
148
+ # "pinned"=>true,
149
+ # "shortName"=>"ldap",
150
+ # "supportsDynamicLoad"=>"MAYBE",
151
+ # "url"=>"https://wiki.jenkins.io/display/JENKINS/LDAP+Plugin",
152
+ # "version"=>"1.5"
153
+ # }
154
+ #
155
+ def get_installed_info(plugin)
156
+ @logger.info "Obtaining the details of plugin: #{plugin}"
157
+ plugins = @client.api_get_request(
158
+ "/pluginManager",
159
+ "depth=1"
160
+ )["plugins"]
161
+ matched_plugin = plugins.select do |a_plugin|
162
+ a_plugin["shortName"] == plugin
163
+ end
164
+ if matched_plugin.empty?
165
+ raise Exceptions::PluginNotFound.new(
166
+ @logger,
167
+ "Plugin '#{plugin}' is not found"
168
+ )
169
+ else
170
+ matched_plugin.first
171
+ end
172
+ end
173
+
174
+ # List the available plugins from jenkins update center along with their
175
+ # version numbers
176
+ #
177
+ # @param filters [Hash] optional filters to filter available plugins.
178
+ #
179
+ # @option filters [Array] :category the category of the plugin to
180
+ # filter
181
+ # @option filters [Array] :dependency the dependency of the plugin to
182
+ # filter
183
+ #
184
+ # @return [Hash<String, String>] available plugins and their versions.
185
+ # returns an empty if no plugins are available.
186
+ #
187
+ # @example Listing available plugins from jenkins
188
+ # >> @client.plugin.list_available
189
+ # => {
190
+ # "accurev" => "0.6.18",
191
+ # "active-directory" => "1.33",
192
+ # "AdaptivePlugin" => "0.1",
193
+ # ...
194
+ # "zubhium" => "0.1.6"
195
+ # }
196
+ #
197
+ # @example Listing available plugins matching a particular category
198
+ # >> pp @client.plugin.list_available(:category => "ui")
199
+ # => {
200
+ # "all-changes"=>"1.3",
201
+ # "bruceschneier"=>"0.1",
202
+ # ...
203
+ # "xfpanel"=>"1.2.2"
204
+ # }
205
+ #
206
+ # @example Listing available plugins matching a particular dependency
207
+ # >> pp @client.plugin.list_available(:dependency => "git")
208
+ # => {
209
+ # "build-failure-analyzer"=>"1.5.0",
210
+ # "buildheroes"=>"0.2",
211
+ # ...
212
+ # "xpdev"=>"1.0"
213
+ # }
214
+ #
215
+ def list_available(filters = {})
216
+ supported_filters = [:category, :dependency]
217
+ filter_plural_map = {
218
+ :dependency => "dependencies",
219
+ :category => "categories"
220
+ }
221
+ unless filters.keys.all? { |filter| supported_filters.include?(filter) }
222
+ raise ArgumentError, "Unsupported filters specified." +
223
+ " Supported filters: #{supported_filters.inspect}"
224
+ end
225
+ # Compute the filters to be passed to the JSON tree parameter
226
+ tree_filters =
227
+ if filters.empty?
228
+ ""
229
+ else
230
+ ",#{filters.keys.map{ |key| filter_plural_map[key] }.join(",")}"
231
+ end
232
+
233
+ availables = @client.api_get_request(
234
+ "/updateCenter/coreSource",
235
+ "tree=availables[name,version#{tree_filters}]"
236
+ )["availables"]
237
+ Hash[availables.map do |plugin|
238
+ if filters.keys.all? do |key|
239
+ !plugin[filter_plural_map[key]].nil? &&
240
+ plugin[filter_plural_map[key]].include?(filters[key])
241
+ end
242
+ [plugin["name"], plugin["version"]]
243
+ end
244
+ end]
245
+ end
246
+
247
+ # Obtains the information about a plugin that is available in the Jenkins
248
+ # update center
249
+ #
250
+ # @param plugin [String] the plugin ID to obtain information for
251
+ #
252
+ # @return [Hash] the details of the given plugin
253
+ #
254
+ # @example Obtaining the details of a plugin available in jenkins
255
+ # >> @client.plugin.get_available_info "status-view"
256
+ # => {
257
+ # "name"=>"status-view",
258
+ # "sourceId"=>"default",
259
+ # "url"=>"https://updates.jenkins.io/download/plugins/status-view/1.0/status-view.hpi",
260
+ # "version"=>"1.0",
261
+ # "categories"=>["ui"],
262
+ # "compatibleSinceVersion"=>nil,
263
+ # "compatibleWithInstalledVersion"=>true,
264
+ # "dependencies"=>{},
265
+ # "excerpt"=>"View type to show jobs filtered by the status of the last completed build.",
266
+ # "installed"=>nil, "neededDependencies"=>[],
267
+ # "requiredCore"=>"1.342",
268
+ # "title"=>"Status View Plugin",
269
+ # "wiki"=>"https://wiki.jenkins.io/display/JENKINS/Status+View+Plugin"
270
+ # }
271
+ #
272
+ def get_available_info(plugin)
273
+ plugins = @client.api_get_request(
274
+ "/updateCenter/coreSource",
275
+ "depth=1"
276
+ )["availables"]
277
+ matched_plugin = plugins.select do |a_plugin|
278
+ a_plugin["name"] == plugin
279
+ end
280
+ if matched_plugin.empty?
281
+ raise Exceptions::PluginNotFound.new(
282
+ @logger,
283
+ "Plugin '#{plugin}' is not found"
284
+ )
285
+ else
286
+ matched_plugin.first
287
+ end
288
+ end
289
+
290
+ # List the available updates for plugins from jenkins update center
291
+ # along with their version numbers
292
+ #
293
+ # @return [Hash<String, String>] available plugin updates and their
294
+ # versions. returns an empty if no plugins are available.
295
+ #
296
+ # @example Listing available plugin updates from jenkins
297
+ # >> @client.plugin.list_updates
298
+ # => {
299
+ # "ldap" => "1.5",
300
+ # "ssh-slaves" => "0.27",
301
+ # "subversion" => "1".50
302
+ # }
303
+ #
304
+ def list_updates
305
+ updates = @client.api_get_request(
306
+ "/updateCenter/coreSource",
307
+ "tree=updates[name,version]"
308
+ )["updates"]
309
+ Hash[updates.map { |plugin| [plugin["name"], plugin["version"]] }]
310
+ end
311
+
312
+ # Installs a specific plugin or list of plugins. This method will install
313
+ # the latest available plugins that jenkins reports. The installation
314
+ # might not take place right away for some plugins and they might require
315
+ # restart of jenkins instances. This method makes a single POST request
316
+ # for the installation of multiple plugins. Updating plugins can be done
317
+ # the same way. When the install action is issued, it gets the latest
318
+ # version of the plugin if the plugin is outdated.
319
+ #
320
+ # @see Client#api_post_request
321
+ # @see #restart_required?
322
+ # @see System#restart
323
+ # @see #uninstall
324
+ #
325
+ # @param plugins [String, Array] a single plugin or a list of plugins to
326
+ # be installed
327
+ #
328
+ # @return [String] the HTTP code from the plugin install POST request
329
+ #
330
+ # @example Installing a plugin and restart jenkins if required
331
+ # >> @client.plugin.install "s3"
332
+ # => "302" # Response code from plugin installation POST
333
+ # >> @client.plugin.restart_required?
334
+ # => true # A restart is required for the installation completion
335
+ # >> @client.system.restart(true)
336
+ # => "302" # A force restart is performed
337
+ #
338
+ def install(plugins)
339
+ # Convert the input argument to an array if it is not already an array
340
+ plugins = [plugins] unless plugins.is_a?(Array)
341
+ @logger.info "Installing plugins: #{plugins.inspect}"
342
+
343
+ # Build the form data to post to jenkins
344
+ form_data = {}
345
+ plugins.each { |plugin| form_data["plugin.#{plugin}.default"] = "on" }
346
+ @client.api_post_request("/pluginManager/install", form_data)
347
+ end
348
+ alias_method :update, :install
349
+
350
+
351
+ # @!method uninstall(plugins)
352
+ #
353
+ # Uninstalls the specified plugin or list of plugins. Only the user
354
+ # installed plugins can be uninstalled. The plugins installed by default
355
+ # by jenkins (also known as bundled plugins) cannot be uninstalled. The
356
+ # call will succeed but the plugins wil still remain in jenkins installed.
357
+ # This method makes a POST request for every plugin requested - so it
358
+ # might lead to some delay if a big list is provided.
359
+ #
360
+ # @see Client#api_post_request
361
+ # @see #restart_required?
362
+ # @see System#restart
363
+ # @see #install
364
+ #
365
+ # @param plugins [String, Array] a single plugin or list of plugins to be
366
+ # uninstalled
367
+ #
368
+ plugin_action_method :uninstall, :doUninstall
369
+
370
+ # @!method downgrade(plugins)
371
+ #
372
+ # Downgrades the specified plugin or list of plugins. This method makes s
373
+ # POST request for every plugin specified - so it might lead to some
374
+ # delay if a big list is provided.
375
+ #
376
+ # @see Client#api_post_request
377
+ # @see #restart_required?
378
+ # @see System#restart
379
+ # @see #install
380
+ #
381
+ # @param [String, Array] a single plugin or list of plugins to be
382
+ # downgraded
383
+ #
384
+ plugin_action_method :downgrade, :downgrade
385
+
386
+ # @!method unpin(plugins)
387
+ #
388
+ # Unpins the specified plugin or list of plugins. This method makes a
389
+ # POST request for every plugin specified - so it might lead to some
390
+ # delay if a big list is provided.
391
+ #
392
+ # @see Client#api_post_request
393
+ # @see #restart_required?
394
+ # @see System#restart
395
+ #
396
+ # @param plugins [String, Array] a single plugin or list of plugins to be
397
+ # uninstalled
398
+ #
399
+ plugin_action_method :unpin, :unpin
400
+
401
+ # @!method enable(plugins)
402
+ #
403
+ # Enables the specified plugin or list of plugins. This method makes a
404
+ # POST request for every plugin specified - so it might lead to some
405
+ # delay if a big list is provided.
406
+ #
407
+ # @see Client#api_post_request
408
+ # @see #restart_required?
409
+ # @see System#restart
410
+ # @see #disable
411
+ #
412
+ # @param plugins [String, Array] a single plugin or list of plugins to be
413
+ # uninstalled
414
+ #
415
+ plugin_action_method :enable, :makeEnabled
416
+
417
+ # @!method disable(plugins)
418
+ #
419
+ # Disables the specified plugin or list of plugins. This method makes a
420
+ # POST request for every plugin specified - so it might lead to some
421
+ # delay if a big list is provided.
422
+ #
423
+ # @see Client#api_post_request
424
+ # @see #restart_required?
425
+ # @see System#restart
426
+ # @see #enable
427
+ #
428
+ # @param plugins [String, Array] a single plugin or list of plugins to be
429
+ # uninstalled
430
+ #
431
+ plugin_action_method :disable, :makeDisabled
432
+
433
+ # Requests the Jenkins plugin manager to check for updates by connecting
434
+ # to the update site.
435
+ #
436
+ # @see #list_updates
437
+ #
438
+ def check_for_updates
439
+ @client.api_post_request("/pluginManager/checkUpdates")
440
+ end
441
+
442
+ # Whether restart required for the completion of plugin
443
+ # installations/uninstallations
444
+ #
445
+ # @see Client#api_get_request
446
+ #
447
+ # @return [Boolean] whether restart is required for the completion for
448
+ # plugin installations/uninstallations.
449
+ #
450
+ def restart_required?
451
+ response = @client.api_get_request(
452
+ "/updateCenter",
453
+ "tree=restartRequiredForCompletion"
454
+ )
455
+ response["restartRequiredForCompletion"] ||
456
+ !list_installed(:deleted => true).empty?
457
+ end
458
+ end
459
+ end
460
+ end
@@ -0,0 +1,11 @@
1
+ module JenkinsApi
2
+ class Client
3
+ module PluginSettings
4
+ class Base
5
+ def configure
6
+ raise InvalidType, 'Object must inherit from JenkinsApi::Client::PluginSettings::Base and override configure method'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,39 @@
1
+ require 'forwardable'
2
+
3
+ module JenkinsApi
4
+ class Client
5
+ module PluginSettings
6
+ class Collection
7
+ extend Forwardable
8
+
9
+ def_delegator :@plugin_settings, :size
10
+
11
+ def initialize(*plugin_settings)
12
+ raise JenkinsApi::Client::PluginSettings::InvalidType unless plugin_settings.all? { |p| p.is_a?(JenkinsApi::Client::PluginSettings::Base) }
13
+ @plugin_settings = plugin_settings
14
+ end
15
+
16
+ def add(plugin)
17
+ raise JenkinsApi::Client::PluginSettings::InvalidType unless plugin.is_a?(JenkinsApi::Client::PluginSettings::Base)
18
+ tap do |x|
19
+ if @plugin_settings.none? { |p| p.class == plugin.class }
20
+ @plugin_settings << plugin
21
+ end
22
+ end
23
+ end
24
+
25
+ def remove(plugin)
26
+ tap do |x|
27
+ @plugin_settings.delete_if { |p| p.class == plugin.class }
28
+ end
29
+ end
30
+
31
+ def configure(xml_doc)
32
+ xml_doc.tap do |x|
33
+ @plugin_settings.each { |p| p.configure(x) }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,53 @@
1
+ module JenkinsApi
2
+ class Client
3
+ module PluginSettings
4
+ class Hipchat < Base
5
+
6
+ # @option params [String] :room
7
+ # id of the room
8
+ # @option params [Boolean] :start_notification (false)
9
+ # whether to notify room when build starts
10
+ # @option params [Boolean] :notify_success (false)
11
+ # whether to notify room when build succeeds
12
+ # @option params [Boolean] :notify_aborted (false)
13
+ # whether to notify room when build aborts
14
+ # @option params [Boolean] :notify_not_built (false)
15
+ # whether to notify room when job could not be build
16
+ # @option params [String] :notify_unstable
17
+ # whether to notify room when job becomes unstable
18
+ # @option params [String] :notify_failure
19
+ # whether to notify room when job fails
20
+ # @option params [String] :notify_back_to_normal
21
+ # whether to notify room when job becomes stable
22
+ #
23
+ def initialize(params={})
24
+ @params = params
25
+ end
26
+
27
+ # Create or Update a job with params given as a hash instead of the xml
28
+ # This gives some flexibility for creating/updating simple jobs so the
29
+ # user doesn't have to learn about handling xml.
30
+ #
31
+ # @param xml_doc [Nokogiri::XML::Document] xml document to be updated with the plugin configuration
32
+ #
33
+ # @return [Nokogiri::XML::Document]
34
+ def configure(xml_doc)
35
+ xml_doc.tap do |doc|
36
+ Nokogiri::XML::Builder.with(doc.at('properties')) do |properties|
37
+ properties.send('jenkins.plugins.hipchat.HipChatNotifier_-HipChatJobProperty') do |x|
38
+ x.room @params.fetch(:room) { '' }
39
+ x.startNotification @params.fetch(:start_notification) { false }
40
+ x.notifySuccess @params.fetch(:notify_success) { false }
41
+ x.notifyAborted @params.fetch(:notify_aborted) { false }
42
+ x.notifyNotBuilt @params.fetch(:notify_not_built) { false }
43
+ x.notifyUnstable @params.fetch(:notify_unstable) { false }
44
+ x.notifyFailure @params.fetch(:notify_failure) { false }
45
+ x.notifyBackToNormal @params.fetch(:notify_back_to_normal) { false }
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,35 @@
1
+ module JenkinsApi
2
+ class Client
3
+ module PluginSettings
4
+ class WorkspaceCleanup < Base
5
+
6
+ # @option params [Boolean] :delete_dirs (false)
7
+ # whether to also apply pattern on directories
8
+ # @option params [String] :cleanup_parameters
9
+ # @option params [String] :external_delete
10
+ def initialize(params={})
11
+ @params = params
12
+ end
13
+
14
+ # Create or Update a job with params given as a hash instead of the xml
15
+ # This gives some flexibility for creating/updating simple jobs so the
16
+ # user doesn't have to learn about handling xml.
17
+ #
18
+ # @param xml_doc [Nokogiri::XML::Document] xml document to be updated with the plugin configuration
19
+ #
20
+ # @return [Nokogiri::XML::Document]
21
+ def configure(xml_doc)
22
+ xml_doc.tap do |doc|
23
+ Nokogiri::XML::Builder.with(doc.at('buildWrappers')) do |build_wrappers|
24
+ build_wrappers.send('hudson.plugins.ws__cleanup.PreBuildCleanup') do |x|
25
+ x.deleteDirs @params.fetch(:delete_dirs) { false }
26
+ x.cleanupParameter @params.fetch(:cleanup_parameter) { '' }
27
+ x.externalDelete @params.fetch(:external_delete) { '' }
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,67 @@
1
+ #
2
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
3
+ # of this software and associated documentation files (the "Software"), to deal
4
+ # in the Software without restriction, including without limitation the rights
5
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6
+ # copies of the Software, and to permit persons to whom the Software is
7
+ # furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in
10
+ # all copies or substantial portions of the Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18
+ # THE SOFTWARE.
19
+ #
20
+
21
+ require 'jenkins_api_client2/urihelper'
22
+
23
+ module JenkinsApi
24
+ class Client
25
+ # This class communicates with Jenkins API at the root address to obtain details
26
+ # on the page displayed to users on the Jenkins' 'homepage,' and other
27
+ # data items such as quietingDown
28
+ class Root
29
+ include JenkinsApi::UriHelper
30
+
31
+ # Initializes a new root object
32
+ #
33
+ # @param client [Client] the client object
34
+ #
35
+ # @return [Root] the root object
36
+ #
37
+ def initialize(client)
38
+ @client = client
39
+ @logger = @client.logger
40
+ end
41
+
42
+ # Return a string representation of the object
43
+ #
44
+ def to_s
45
+ "#<JenkinsApi::Client::Root>"
46
+ end
47
+
48
+ # Check if Jenkins is in shutdown mode
49
+ #
50
+ # @return [Boolean] true if server in shutdown mode
51
+ #
52
+ def quieting_down?
53
+ response_json = @client.api_get_request('', 'tree=quietingDown')
54
+ response_json['quietingDown']
55
+ end
56
+
57
+ # Get message displayed to users on the homepage
58
+ #
59
+ # @return [String] description - message displayed to users
60
+ #
61
+ def description
62
+ response_json = @client.api_get_request('', 'tree=description')
63
+ response_json['description']
64
+ end
65
+ end
66
+ end
67
+ end