ruby-jss 0.7.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby-jss might be problematic. Click here for more details.

Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +29 -22
  3. data/README.md +66 -86
  4. data/bin/jamfHelperBackgrounder +148 -0
  5. data/bin/netseg-update +0 -1
  6. data/lib/jss.rb +20 -9
  7. data/lib/jss/api_connection.rb +369 -295
  8. data/lib/jss/api_object.rb +651 -418
  9. data/lib/jss/api_object/account.rb +69 -77
  10. data/lib/jss/api_object/advanced_search.rb +201 -236
  11. data/lib/jss/api_object/advanced_search/advanced_computer_search.rb +42 -42
  12. data/lib/jss/api_object/advanced_search/advanced_mobile_device_search.rb +33 -43
  13. data/lib/jss/api_object/advanced_search/advanced_user_search.rb +33 -43
  14. data/lib/jss/api_object/building.rb +39 -52
  15. data/lib/jss/api_object/categorizable.rb +221 -0
  16. data/lib/jss/api_object/category.rb +81 -89
  17. data/lib/jss/api_object/computer.rb +486 -525
  18. data/lib/jss/api_object/computer_invitation.rb +73 -86
  19. data/lib/jss/api_object/criteriable.rb +6 -7
  20. data/lib/jss/api_object/ebook.rb +21 -0
  21. data/lib/jss/api_object/extendable.rb +6 -8
  22. data/lib/jss/api_object/group.rb +0 -3
  23. data/lib/jss/api_object/locatable.rb +19 -20
  24. data/lib/jss/api_object/mac_application.rb +21 -0
  25. data/lib/jss/api_object/mobile_device.rb +30 -21
  26. data/lib/jss/api_object/mobile_device_application.rb +447 -0
  27. data/lib/jss/api_object/mobile_device_configuration_profile.rb +21 -0
  28. data/lib/jss/api_object/osx_configuration_profile.rb +0 -3
  29. data/lib/jss/api_object/package.rb +21 -34
  30. data/lib/jss/api_object/peripheral.rb +16 -18
  31. data/lib/jss/api_object/policy.rb +5 -83
  32. data/lib/jss/api_object/purchasable.rb +11 -13
  33. data/lib/jss/api_object/scopable.rb +11 -12
  34. data/lib/jss/api_object/script.rb +3 -17
  35. data/lib/jss/api_object/self_servable.rb +419 -205
  36. data/lib/jss/api_object/self_servable/icon.rb +179 -0
  37. data/lib/jss/api_object/updatable.rb +35 -34
  38. data/lib/jss/api_object/uploadable.rb +72 -70
  39. data/lib/jss/api_object/user.rb +6 -7
  40. data/lib/jss/api_object/vppable.rb +117 -0
  41. data/lib/jss/client.rb +264 -225
  42. data/lib/jss/db_connection.rb +7 -5
  43. data/lib/jss/exceptions.rb +50 -42
  44. data/lib/jss/ruby_extensions.rb +8 -7
  45. data/lib/jss/ruby_extensions/object.rb +19 -0
  46. data/lib/jss/utility.rb +82 -40
  47. data/lib/jss/version.rb +1 -1
  48. metadata +37 -68
  49. data/bin/jss-webhook-server +0 -3
  50. data/lib/jss/webhooks.rb +0 -53
  51. data/lib/jss/webhooks/README.md +0 -269
  52. data/lib/jss/webhooks/configuration.rb +0 -213
  53. data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation-executable +0 -91
  54. data/lib/jss/webhooks/data/sample_handlers/RestAPIOperation.rb +0 -45
  55. data/lib/jss/webhooks/data/sample_jsons/ComputerAdded.json +0 -27
  56. data/lib/jss/webhooks/data/sample_jsons/ComputerCheckIn.json +0 -27
  57. data/lib/jss/webhooks/data/sample_jsons/ComputerInventoryCompleted.json +0 -27
  58. data/lib/jss/webhooks/data/sample_jsons/ComputerPolicyFinished.json +0 -27
  59. data/lib/jss/webhooks/data/sample_jsons/ComputerPushCapabilityChanged.json +0 -27
  60. data/lib/jss/webhooks/data/sample_jsons/JSSShutdown.json +0 -14
  61. data/lib/jss/webhooks/data/sample_jsons/JSSStartup.json +0 -14
  62. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceCheckIn.json +0 -26
  63. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceCommandCompleted.json +0 -26
  64. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceEnrolled.json +0 -26
  65. data/lib/jss/webhooks/data/sample_jsons/MobileDevicePushSent.json +0 -26
  66. data/lib/jss/webhooks/data/sample_jsons/MobileDeviceUnEnrolled.json +0 -26
  67. data/lib/jss/webhooks/data/sample_jsons/PatchSoftwareTitleUpdated.json +0 -14
  68. data/lib/jss/webhooks/data/sample_jsons/PushSent.json +0 -11
  69. data/lib/jss/webhooks/data/sample_jsons/RestAPIOperation.json +0 -15
  70. data/lib/jss/webhooks/data/sample_jsons/SCEPChallenge.json +0 -10
  71. data/lib/jss/webhooks/data/sample_jsons/SmartGroupComputerMembershipChange.json +0 -13
  72. data/lib/jss/webhooks/data/sample_jsons/SmartGroupMobileDeviceMembershipChange.json +0 -13
  73. data/lib/jss/webhooks/event.rb +0 -139
  74. data/lib/jss/webhooks/event/computer_added.rb +0 -38
  75. data/lib/jss/webhooks/event/computer_check_in.rb +0 -38
  76. data/lib/jss/webhooks/event/computer_inventory_completed.rb +0 -38
  77. data/lib/jss/webhooks/event/computer_policy_finished.rb +0 -38
  78. data/lib/jss/webhooks/event/computer_push_capability_changed.rb +0 -38
  79. data/lib/jss/webhooks/event/handlers.rb +0 -192
  80. data/lib/jss/webhooks/event/jss_shutdown.rb +0 -38
  81. data/lib/jss/webhooks/event/jss_startup.rb +0 -38
  82. data/lib/jss/webhooks/event/mobile_device_check_in.rb +0 -38
  83. data/lib/jss/webhooks/event/mobile_device_command_completed.rb +0 -38
  84. data/lib/jss/webhooks/event/mobile_device_enrolled.rb +0 -38
  85. data/lib/jss/webhooks/event/mobile_device_push_sent.rb +0 -38
  86. data/lib/jss/webhooks/event/mobile_device_unenrolled.rb +0 -38
  87. data/lib/jss/webhooks/event/patch_software_title_updated.rb +0 -38
  88. data/lib/jss/webhooks/event/push_sent.rb +0 -38
  89. data/lib/jss/webhooks/event/rest_api_operation.rb +0 -38
  90. data/lib/jss/webhooks/event/scep_challenge.rb +0 -38
  91. data/lib/jss/webhooks/event/smart_group_computer_membership_change.rb +0 -38
  92. data/lib/jss/webhooks/event/smart_group_mobile_device_membership_change.rb +0 -38
  93. data/lib/jss/webhooks/event/webhook.rb +0 -40
  94. data/lib/jss/webhooks/event_objects.rb +0 -112
  95. data/lib/jss/webhooks/event_objects/computer.rb +0 -49
  96. data/lib/jss/webhooks/event_objects/jss.rb +0 -36
  97. data/lib/jss/webhooks/event_objects/mobile_device.rb +0 -48
  98. data/lib/jss/webhooks/event_objects/patch_software_title_update.rb +0 -38
  99. data/lib/jss/webhooks/event_objects/push.rb +0 -33
  100. data/lib/jss/webhooks/event_objects/rest_api_operation.rb +0 -37
  101. data/lib/jss/webhooks/event_objects/scep_challenge.rb +0 -32
  102. data/lib/jss/webhooks/event_objects/smart_group.rb +0 -35
  103. data/lib/jss/webhooks/server_app.rb +0 -37
  104. data/lib/jss/webhooks/server_app/routes.rb +0 -27
  105. data/lib/jss/webhooks/server_app/routes/handle_webhook_event.rb +0 -39
  106. data/lib/jss/webhooks/server_app/routes/home.rb +0 -37
  107. data/lib/jss/webhooks/server_app/self_signed_cert.rb +0 -65
  108. data/lib/jss/webhooks/server_app/server.rb +0 -60
  109. data/lib/jss/webhooks/version.rb +0 -32
@@ -26,133 +26,125 @@
26
26
  ###
27
27
  module JSS
28
28
 
29
- #####################################
30
- ### Module Variables
29
+ # Module Variables
31
30
  #####################################
32
31
 
33
- #####################################
34
- ### Module Methods
32
+ # Module Methods
35
33
  #####################################
36
34
 
37
- #####################################
38
- ### Classes
35
+ # Classes
39
36
  #####################################
40
37
 
41
- ###
42
- ### A User in the JSS.
43
- ###
44
- ### @see JSS::APIObject
45
- ###
38
+ # A User or group in the JSS.
39
+ #
40
+ # @see JSS::APIObject
41
+ #
46
42
  class Account < JSS::APIObject
47
43
 
48
- ### Note: This class is not fully extended and since the resource
49
- ### is different than the rest, methods like JSS::Account.all do not work
44
+ # Note: This class is not fully extended and since the resource
45
+ # is different than the rest, methods like JSS::Account.all do not work
50
46
 
51
- #####################################
52
- ### Mix-Ins
47
+ # Mix-Ins
53
48
  #####################################
54
49
 
50
+ # Class Constants
55
51
  #####################################
56
- ### Class Methods
52
+
53
+ # The base for REST resources of this class
54
+ RSRC_BASE = 'accounts'.freeze
55
+
56
+ # the hash key used for the JSON list output of all objects in the JSS
57
+ RSRC_LIST_KEY = :accounts
58
+
59
+ # The hash key used for the JSON object output.
60
+ # It's also used in various error messages
61
+ RSRC_OBJECT_KEY = :account
62
+
63
+ # these keys, as well as :id and :name, can be used to look up objects of this class in the JSS
64
+ OTHER_LOOKUP_KEYS = [:userid, :username, :groupid, :groupname].freeze
65
+
66
+ # Class Methods
57
67
  #####################################
58
68
 
59
- ### @return [Array<Hash>] all JSS account users
69
+ # @return [Array<Hash>] all JSS account users
60
70
  def self.all_users(refresh = false)
61
- self.all(refresh)[:users]
71
+ all(refresh)[:users]
62
72
  end
63
73
 
64
- ### @return [Array<Hash>] all JSS account user ids
74
+ # @return [Array<Hash>] all JSS account user ids
65
75
  def self.all_user_ids(refresh = false)
66
- self.all(refresh)[:users].map{|i| i[:id]}
76
+ all(refresh)[:users].map { |i| i[:id] }
67
77
  end
68
78
 
69
- ### @return [Array<Hash>] all JSS account user names
79
+ # @return [Array<Hash>] all JSS account user names
70
80
  def self.all_user_names(refresh = false)
71
- self.all(refresh)[:users].map{|i| i[:name]}
81
+ all(refresh)[:users].map { |i| i[:name] }
72
82
  end
73
83
 
74
- ### @return [Array<Hash>] all JSS account groups
84
+ # @return [Array<Hash>] all JSS account groups
75
85
  def self.all_groups(refresh = false)
76
- self.all(refresh)[:groups]
86
+ all(refresh)[:groups]
77
87
  end
78
88
 
79
- ### @return [Array<Hash>] all JSS account group ids
89
+ # @return [Array<Hash>] all JSS account group ids
80
90
  def self.all_group_ids(refresh = false)
81
- self.all(refresh)[:groups].map{|i| i[:id]}
91
+ all(refresh)[:groups].map { |i| i[:id] }
82
92
  end
83
93
 
84
- ### @return [Array<Hash>] all JSS account group names
94
+ # @return [Array<Hash>] all JSS account group names
85
95
  def self.all_group_names(refresh = false)
86
- self.all(refresh)[:groups].map{|i| i[:name]}
96
+ all(refresh)[:groups].map { |i| i[:name] }
87
97
  end
88
98
 
99
+ # Attributes
89
100
  #####################################
90
- ### Class Constants
91
- #####################################
92
-
93
- ### The base for REST resources of this class
94
- RSRC_BASE = "accounts"
95
-
96
- ### the hash key used for the JSON list output of all objects in the JSS
97
- RSRC_LIST_KEY = :accounts
98
-
99
- ### The hash key used for the JSON object output.
100
- ### It's also used in various error messages
101
- RSRC_OBJECT_KEY = :account
102
101
 
103
- #####################################
104
- ### Attributes
105
- #####################################
106
-
107
- ### @return [String] The user's full name
102
+ # @return [String] The user's full name
108
103
  attr_reader :full_name
109
104
 
110
- ### @return [String] The user's email address
105
+ # @return [String] The user's email address
111
106
  attr_reader :email
112
107
 
113
- ### @return [String] The user's access level
108
+ # @return [String] The user's access level
114
109
  attr_reader :access_level
115
110
 
116
- ### @return [String] The user's privilege set
111
+ # @return [String] The user's privilege set
117
112
  attr_reader :privilege_set
118
113
 
119
- ### @return [Hash]
120
- ###
121
- ### Info about the privileges assigned to the user
122
- ###
123
- ### Note: these arrays may be empty, they always exist
124
- ###
125
- ### The Hash keys are:
126
- ### * :jss_objects => An array of jss_object privileges
127
- ### * :jss_settings => An array of jss_settings privileges
128
- ### * :jss_actions => An array of jss_actions privileges
129
- ### * :recon => An array of Casper Recon privileges
130
- ### * :casper_admin => An array of Casper Admin privileges
131
- ### * :casper_remote => An array of Casper Remote privileges
132
- ### * :casper_imaging => An array of Casper Imaging privileges
114
+ # @return [Hash]
115
+ #
116
+ # Info about the privileges assigned to the user
117
+ #
118
+ # Note: these arrays may be empty, they always exist
119
+ #
120
+ # The Hash keys are:
121
+ # * :jss_objects => An array of jss_object privileges
122
+ # * :jss_settings => An array of jss_settings privileges
123
+ # * :jss_actions => An array of jss_actions privileges
124
+ # * :recon => An array of Casper Recon privileges
125
+ # * :casper_admin => An array of Casper Admin privileges
126
+ # * :casper_remote => An array of Casper Remote privileges
127
+ # * :casper_imaging => An array of Casper Imaging privileges
133
128
  attr_reader :privileges
134
129
 
135
- #####################################
136
- ### Constructor
130
+ # Constructor
137
131
  #####################################
138
132
 
139
- ###
140
- ### See JSS::APIObject#initialize
141
- ###
142
- def initialize (args = {})
143
- super args, [:userid, :username, :groupid, :groupname]
133
+ # See JSS::APIObject#initialize
134
+ #
135
+ def initialize(args = {})
136
+ super args
144
137
 
145
138
  # check to see if a user has been specified, haven't built groups yet
146
139
  is_user = [:userid, :username].any? { |key| args.keys.include? key }
147
140
 
148
- if is_user
149
- @user_name = @init_data[:name]
150
- @full_name = @init_data[:full_name]
151
- @email = @init_data[:email]
152
- @access_level = @init_data[:access_level]
153
- @privilege_set = @init_data[:privilege_set]
154
- @privileges = @init_data[:privileges]
155
- end
141
+ return unless is_user
142
+ @user_name = @init_data[:name]
143
+ @full_name = @init_data[:full_name]
144
+ @email = @init_data[:email]
145
+ @access_level = @init_data[:access_level]
146
+ @privilege_set = @init_data[:privilege_set]
147
+ @privileges = @init_data[:privileges]
156
148
 
157
149
  end # initialize
158
150
 
@@ -1,188 +1,171 @@
1
1
  ### Copyright 2017 Pixar
2
2
 
3
- ###
3
+ ###
4
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
5
5
  ### with the following modification; you may not use this file except in
6
6
  ### compliance with the Apache License and the following modification to it:
7
7
  ### Section 6. Trademarks. is deleted and replaced with:
8
- ###
8
+ ###
9
9
  ### 6. Trademarks. This License does not grant permission to use the trade
10
10
  ### names, trademarks, service marks, or product names of the Licensor
11
11
  ### and its affiliates, except as required to comply with Section 4(c) of
12
12
  ### the License and to reproduce the content of the NOTICE file.
13
- ###
13
+ ###
14
14
  ### You may obtain a copy of the Apache License at
15
- ###
15
+ ###
16
16
  ### http://www.apache.org/licenses/LICENSE-2.0
17
- ###
17
+ ###
18
18
  ### Unless required by applicable law or agreed to in writing, software
19
19
  ### distributed under the Apache License with the above modification is
20
20
  ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
21
  ### KIND, either express or implied. See the Apache License for the specific
22
22
  ### language governing permissions and limitations under the Apache License.
23
- ###
23
+ ###
24
24
  ###
25
25
 
26
26
  ###
27
27
  module JSS
28
28
 
29
- #####################################
30
- ### Module Variables
29
+ # Module Variables
31
30
  #####################################
32
31
 
33
- #####################################
34
- ### Module Methods
32
+ # Module Methods
35
33
  #####################################
36
34
 
37
- #####################################
38
- ### Classes
35
+ # Classes
39
36
  #####################################
40
37
 
41
- ###
42
- ### A Parent class for Advanced Computer, MobileDevice, and User searchs
43
- ###
44
- ### Subclasses must define:
45
- ### * the constant RESULT_CLASS which is the JSS Module class of
46
- ### the item returned by the search, e.g. JSS::Computer
47
- ### * the constant RESULT_ID_FIELDS, which is an Array of Symbols
48
- ### that come from the API in the search_results along with the
49
- ### symbolized display fields.
50
- ### E.g. for AdvancedComputerSearches, :id, :name, and :udid are present along with
51
- ### whatever display fields have been defined.
52
- ###
53
- ###
54
- ### @see JSS::AdvancedComputerSearch
55
- ### @see JSS::AdvancedMobileDeviceSearch
56
- ### @see JSS::AdvancedUserSearch
57
- ### @see JSS::APIObject
58
- ###
38
+ #
39
+ # A Parent class for Advanced Computer, MobileDevice, and User searchs
40
+ #
41
+ # Subclasses must define:
42
+ # * the constant RESULT_CLASS which is the JSS Module class of
43
+ # the item returned by the search, e.g. JSS::Computer
44
+ # * the constant RESULT_ID_FIELDS, which is an Array of Symbols
45
+ # that come from the API in the search_results along with the
46
+ # symbolized display fields.
47
+ # E.g. for AdvancedComputerSearches, :id, :name, and :udid are present along with
48
+ # whatever display fields have been defined.
49
+ #
50
+ #
51
+ # @see JSS::AdvancedComputerSearch
52
+ # @see JSS::AdvancedMobileDeviceSearch
53
+ # @see JSS::AdvancedUserSearch
54
+ # @see JSS::APIObject
55
+ #
59
56
  class AdvancedSearch < JSS::APIObject
60
57
 
61
- #####################################
62
- ### Mix-Ins
58
+ # Mix-Ins
63
59
  #####################################
64
60
  include JSS::Creatable
65
61
  include JSS::Updatable
66
62
  include JSS::Criteriable
67
63
 
68
- #####################################
69
- ### Class Constants
64
+ # Class Constants
70
65
  #####################################
71
66
 
72
- EXPORT_FORMATS = [:csv, :tab, :xml]
67
+ EXPORT_FORMATS = [:csv, :tab, :xml].freeze
73
68
 
69
+ # Attributes
74
70
  #####################################
75
- ### Attributes
76
- #####################################
77
-
78
71
 
79
- ###
80
- ### @return [Array<Hash>] the results of the search
81
- ###
82
- ### Each Hash is one object that matches the criteria.
83
- ### Within each hash there are variable keys, but always at least
84
- ### the keys defined in each subclasses RESULT_ID_FIELDS
85
- ###
86
- ### The other keys correspond to the {AdvancedSearch#display_fields} defined for this
87
- ### Advanced Search.
88
- ###
72
+ #
73
+ # @return [Array<Hash>] the results of the search
74
+ #
75
+ # Each Hash is one object that matches the criteria.
76
+ # Within each hash there are variable keys, but always at least
77
+ # the keys defined in each subclasses RESULT_ID_FIELDS
78
+ #
79
+ # The other keys correspond to the {AdvancedSearch#display_fields} defined for this
80
+ # Advanced Search.
81
+ #
89
82
  attr_reader :search_results
90
83
 
91
- ### @return [Array<Symbol>]
92
- ###
93
- ### The search result Hash keys for the {#display_fields} of the search
94
- ###
95
- ### The field names in {#display_fields} are strings matching how the field is labeled
96
- ### in the web UI (including the names of Extension Attributes). They have to be that way
97
- ### when submitting them to the API, and thats mostly what {#display_fields} and related
98
- ### methods are for.
99
- ###
100
- ### However, when those names come back as the Hash Keys of the {#search_results}
101
- ### they (inconsistently) have spaces and/or dashes converted to underscores, and,
102
- ### the JSON module converts the keys to Symbols, so they don't match the {#display_fields}.
103
- ###
104
- ### For example, the display field "Last Check-in" might come back as any of these Symbols:
105
- ### - :"Last Check-in"
106
- ### - :Last_Check_in
107
- ### - :"Last_Check-in"
108
- ###
109
- ### Also, the data returned in the {#search_results} contains more keys than just the
110
- ### {#display_fields} - namely it comes with some standard identifiers for each found item.
111
- ### such as JSS id number and name.
112
- ###
113
- ### {#result_display_keys} will hold just the Hash keys corresponding to the
114
- ### {#display_fields} by taking the keys from the first result Hash, and removing the
115
- ### identifier keys as listed in each subclass's RESULT_ID_FIELDS constant.
116
- ###
84
+ # @return [Array<Symbol>]
85
+ #
86
+ # The search result Hash keys for the {#display_fields} of the search
87
+ #
88
+ # The field names in {#display_fields} are strings matching how the field is labeled
89
+ # in the web UI (including the names of Extension Attributes). They have to be that way
90
+ # when submitting them to the API, and thats mostly what {#display_fields} and related
91
+ # methods are for.
92
+ #
93
+ # However, when those names come back as the Hash Keys of the {#search_results}
94
+ # they (inconsistently) have spaces and/or dashes converted to underscores, and,
95
+ # the JSON module converts the keys to Symbols, so they don't match the {#display_fields}.
96
+ #
97
+ # For example, the display field "Last Check-in" might come back as any of these Symbols:
98
+ # - :"Last Check-in"
99
+ # - :Last_Check_in
100
+ # - :"Last_Check-in"
101
+ #
102
+ # Also, the data returned in the {#search_results} contains more keys than just the
103
+ # {#display_fields} - namely it comes with some standard identifiers for each found item.
104
+ # such as JSS id number and name.
105
+ #
106
+ # {#result_display_keys} will hold just the Hash keys corresponding to the
107
+ # {#display_fields} by taking the keys from the first result Hash, and removing the
108
+ # identifier keys as listed in each subclass's RESULT_ID_FIELDS constant.
109
+ #
117
110
  attr_reader :result_display_keys
118
111
 
119
- ### @return [String] the name of the site for this search
112
+ # @return [String] the name of the site for this search
120
113
  attr_reader :site
121
114
 
122
- ### @return [String] the SQL query generated by the JSS based on the critera
115
+ # @return [String] the SQL query generated by the JSS based on the critera
123
116
  attr_reader :sql_text
124
117
 
125
- #####################################
126
- ### Constructor
118
+ # Constructor
127
119
  #####################################
128
120
 
129
- ###
130
- ### @see APIObject#initialize
131
- ###
121
+ #
122
+ # @see APIObject#initialize
123
+ #
132
124
  def initialize(args = {})
133
-
134
125
  super args
135
126
 
136
- ### @init_data now has the raw data
137
- ### so fill in our attributes or set defaults
127
+ # @init_data now has the raw data
128
+ # so fill in our attributes or set defaults
138
129
 
139
130
  @sql_text = @init_data[:sql_text]
140
131
  @site = JSS::APIObject.get_name(@init_data[:site])
141
132
 
133
+ @display_fields = @init_data[:display_fields] ? @init_data[:display_fields].map { |f| f[:name] } : []
142
134
 
143
-
144
- @display_fields = @init_data[:display_fields] ? @init_data[:display_fields].map{|f| f[:name]} : []
145
-
146
- @search_results = @init_data[self.class::RESULT_CLASS::RSRC_LIST_KEY]
135
+ @search_results = @init_data[self.class::RESULT_CLASS::RSRC_LIST_KEY]
147
136
  @search_results ||= []
148
- if @search_results.empty?
149
- @result_display_keys =[]
150
- else
151
- @result_display_keys = @search_results[0].keys - self.class::RESULT_ID_FIELDS
152
- end
137
+ @result_display_keys = if @search_results.empty?
138
+ []
139
+ else
140
+ @search_results[0].keys - self.class::RESULT_ID_FIELDS
141
+ end
153
142
 
154
143
  # make sure each hash of the search results
155
144
  # has a key matching a standard key.
156
145
  #
157
146
  @search_results.each do |hash|
158
147
  hash.keys.each do |key|
159
- std_key = key.to_s.gsub(/ |-/,"_").to_sym
148
+ std_key = key.to_s.gsub(/ |-/, '_').to_sym
160
149
  next if hash[std_key]
161
150
  hash[std_key] = hash[key]
162
151
  end
163
152
  end
164
-
165
- parse_criteria
166
-
167
-
168
153
  end # init
169
154
 
170
- #####################################
171
- ### Public Instance Methods
155
+ # Public Instance Methods
172
156
  #####################################
173
157
 
174
- ###
175
- ### Create in the JSS
176
- ###
177
- ### If get_results is true, they'll be available in {#search_results}. This might be slow.
178
- ###
179
- ### @param get_results[Boolean] should the results of the search be queried immediately?
180
- ###
181
- ### @return [Integer] the id of the newly created search
182
- ###
158
+ # Create in the JSS
159
+ #
160
+ # If get_results is true, they'll be available in {#search_results}. This might be slow.
161
+ #
162
+ # @param get_results[Boolean] should the results of the search be queried immediately?
163
+ #
164
+ # @return [Integer] the id of the newly created search
165
+ #
183
166
  def create(get_results = false)
184
- raise JSS::InvalidDataError, "JSS::Criteriable::Criteria instance required" unless @criteria.kind_of? JSS::Criteriable::Criteria
185
- raise JSS::InvalidDataError, "display_fields must be an Array." unless @display_fields.kind_of? Array
167
+ raise JSS::InvalidDataError, 'JSS::Criteriable::Criteria instance required' unless @criteria.is_a? JSS::Criteriable::Criteria
168
+ raise JSS::InvalidDataError, 'display_fields must be an Array.' unless @display_fields.is_a? Array
186
169
 
187
170
  orig_timeout = JSS::API.cnx.options[:timeout]
188
171
  JSS::API.timeout = 1800
@@ -191,18 +174,16 @@ module JSS
191
174
  JSS::API.timeout = orig_timeout
192
175
 
193
176
  @id # remember to return the id
194
-
195
177
  end
196
178
 
197
- ###
198
- ### Save any changes
199
- ###
200
- ### If get_results is true, they'll be available in {#search_results}. This might be slow.
201
- ###
202
- ### @param get_results[Boolean] should the results of the search be queried immediately?
203
- ###
204
- ### @return [Integer] the id of the updated search
205
- ###
179
+ # Save any changes
180
+ #
181
+ # If get_results is true, they'll be available in {#search_results}. This might be slow.
182
+ #
183
+ # @param get_results[Boolean] should the results of the search be queried immediately?
184
+ #
185
+ # @return [Integer] the id of the updated search
186
+ #
206
187
  def update(get_results = false)
207
188
  orig_timeout = JSS::API.cnx.options[:timeout]
208
189
  JSS::API.timeout = 1800
@@ -210,24 +191,22 @@ module JSS
210
191
  requery_search_results if get_results
211
192
  JSS::API.timeout = orig_timeout
212
193
 
213
- @id # remember to return the id
194
+ @id # remember to return the id
214
195
  end
215
196
 
216
-
217
- ###
218
- ### Requery the API for the search results.
219
- ###
220
- ### This can be very slow, so temporarily reset the API timeout to 30 minutes
221
- ###
222
- ### @return [Array<Hash>] the new search results
223
- ###
197
+ # Requery the API for the search results.
198
+ #
199
+ # This can be very slow, so temporarily reset the API timeout to 30 minutes
200
+ #
201
+ # @return [Array<Hash>] the new search results
202
+ #
224
203
  def requery_search_results
225
204
  orig_open_timeout = JSS::API.cnx.options[:open_timeout]
226
205
  orig_timeout = JSS::API.cnx.options[:timeout]
227
206
  JSS::API.timeout = 1800
228
207
  JSS::API.open_timeout = 1800
229
208
  begin
230
- requery = self.class.new(:id => @id)
209
+ requery = self.class.new(id: @id)
231
210
  @search_results = requery.search_results
232
211
  @result_display_keys = requery.result_display_keys
233
212
  ensure
@@ -236,66 +215,57 @@ module JSS
236
215
  end
237
216
  end
238
217
 
239
- ###
240
- ### @return [Array<String>] the fields to be returned with the search results
241
- ###
242
- ### The API delivers these as an array of Hashes,
243
- ### where each hash has only one key, :name => the name of the fields/ExtAttrib
244
- ### to display. It should probably not have the underlying Hashes, and just
245
- ### be an array of names. This class converts it to just an Array of field names
246
- ### (Strings) for internal use.
247
- ###
248
- ### These fields are returned in the @search_results
249
- ### data along with :id, :name, and other unique identifiers
250
- ### for each found item. In that data, their names have
251
- ### spaces and dashes converted to underscores, and they are
252
- ### symbolized.
253
- ###
254
- ###
255
- def display_fields
256
- @display_fields
257
- end
258
-
259
- ###
260
- ### Set the list of fields to be retrieved with the
261
- ### search results.
262
- ###
263
- ### @param new_val[Array<String>] the new field names
264
- ###
265
- def display_fields= (new_val)
266
- raise JSS::InvalidDataError, "display_fields must be an Array." unless new_val.kind_of? Array
218
+ # @return [Array<String>] the fields to be returned with the search results
219
+ #
220
+ # The API delivers these as an array of Hashes,
221
+ # where each hash has only one key, :name => the name of the fields/ExtAttrib
222
+ # to display. It should probably not have the underlying Hashes, and just
223
+ # be an array of names. This class converts it to just an Array of field names
224
+ # (Strings) for internal use.
225
+ #
226
+ # These fields are returned in the @search_results
227
+ # data along with :id, :name, and other unique identifiers
228
+ # for each found item. In that data, their names have
229
+ # spaces and dashes converted to underscores, and they are
230
+ # symbolized.
231
+ #
232
+ #
233
+ attr_reader :display_fields
234
+
235
+ # Set the list of fields to be retrieved with the
236
+ # search results.
237
+ #
238
+ # @param new_val[Array<String>] the new field names
239
+ #
240
+ def display_fields=(new_val)
241
+ raise JSS::InvalidDataError, 'display_fields must be an Array.' unless new_val.is_a? Array
267
242
  return if new_val.sort == @display_fields.sort
268
243
  @display_fields = new_val
269
244
  @need_to_update = true
270
245
  end
271
246
 
272
-
273
-
274
- ###
275
- ### @return [Integer] the number of items found by the search
276
- ###
247
+ # @return [Integer] the number of items found by the search
248
+ #
277
249
  def count
278
250
  @search_results.count
279
251
  end
280
252
 
281
- ###
282
- ### Export the display fields of the search results to a file.
283
- ###
284
- ### @param output_file[String,Pathname] The file in which to store the exported results
285
- ###
286
- ### @param format[Symbol] one of :csv, :tab, or :xml, defaults to :csv
287
- ###
288
- ### @param overwrite[Boolean] should the output_file be overwrite if it exists? Defaults to false
289
- ###
290
- ### @return [Pathname] the path to the output file
291
- ###
292
- ### @note This method only exports the display fields defined in this advanced search for
293
- ### the search_result members (computers, mobile_devices, or users)
294
- ### It doesn't currently provide the ability to export subsets of info about those objects, as the
295
- ### Web UI does (e.g. group memberships, applications, receipts, etc)
296
- ###
253
+ # Export the display fields of the search results to a file.
254
+ #
255
+ # @param output_file[String,Pathname] The file in which to store the exported results
256
+ #
257
+ # @param format[Symbol] one of :csv, :tab, or :xml, defaults to :csv
258
+ #
259
+ # @param overwrite[Boolean] should the output_file be overwrite if it exists? Defaults to false
260
+ #
261
+ # @return [Pathname] the path to the output file
262
+ #
263
+ # @note This method only exports the display fields defined in this advanced search for
264
+ # the search_result members (computers, mobile_devices, or users)
265
+ # It doesn't currently provide the ability to export subsets of info about those objects, as the
266
+ # Web UI does (e.g. group memberships, applications, receipts, etc)
267
+ #
297
268
  def export(output_file, format = :csv, overwrite = false)
298
-
299
269
  raise JSS::InvalidDataError, "Export format must be one of: :#{EXPORT_FORMATS.join ', :'}" unless EXPORT_FORMATS.include? format
300
270
 
301
271
  out = Pathname.new output_file
@@ -304,65 +274,61 @@ module JSS
304
274
  raise JSS::AlreadyExistsError, "The output file already exists: #{out}" if out.exist?
305
275
  end
306
276
 
307
-
308
277
  case format
309
- when :csv
310
- require 'csv'
311
- CSV.open(out.to_s, 'wb') do |csv|
312
- csv << @result_display_keys
313
- @search_results.each do |row|
314
- csv << @result_display_keys.map {|key| row[key]}
315
- end # each do row
316
- end #CSV.open
317
-
318
- when :tab
319
- tabbed = @result_display_keys.join("\t") + "\n"
278
+ when :csv
279
+ require 'csv'
280
+ CSV.open(out.to_s, 'wb') do |csv|
281
+ csv << @result_display_keys
320
282
  @search_results.each do |row|
321
- tabbed << @result_display_keys.map {|key| row[key]}.join("\t") + "\n"
283
+ csv << @result_display_keys.map { |key| row[key] }
322
284
  end # each do row
323
- out.jss_save tabbed.chomp
324
-
325
- else # :xml
326
- doc = REXML::Document.new '<?xml version="1.0" encoding="ISO-8859-1"?>'
327
- members = doc.add_element self.class::RESULT_CLASS::RSRC_LIST_KEY.to_s
328
- @search_results.each do |row|
329
- member = members.add_element self.class::RESULT_CLASS::RSRC_OBJECT_KEY.to_s
330
- @result_display_keys.each do |field|
331
- member.add_element(field.to_s.gsub(' ',"_")).text = row[field].empty? ? nil : row[field]
332
- end # ech do field
333
- end #each do row
334
- out.jss_save doc.to_s.gsub('><', ">\n<")
285
+ end # CSV.open
286
+
287
+ when :tab
288
+ tabbed = @result_display_keys.join("\t") + "\n"
289
+ @search_results.each do |row|
290
+ tabbed << @result_display_keys.map { |key| row[key] }.join("\t") + "\n"
291
+ end # each do row
292
+ out.jss_save tabbed.chomp
293
+
294
+ else # :xml
295
+ doc = REXML::Document.new '<?xml version="1.0" encoding="ISO-8859-1"?>'
296
+ members = doc.add_element self.class::RESULT_CLASS::RSRC_LIST_KEY.to_s
297
+ @search_results.each do |row|
298
+ member = members.add_element self.class::RESULT_CLASS::RSRC_OBJECT_KEY.to_s
299
+ @result_display_keys.each do |field|
300
+ member.add_element(field.to_s.tr(' ', '_')).text = row[field].empty? ? nil : row[field]
301
+ end # ech do field
302
+ end # each do row
303
+ out.jss_save doc.to_s.gsub('><', ">\n<")
335
304
  end # case
336
305
 
337
- return out
306
+ out
338
307
  end
339
308
 
340
-
341
- #####################################
342
- ### Private Instance Methods
309
+ # Private Instance Methods
343
310
  #####################################
344
311
  private
345
312
 
346
- ###
347
- ### Clean up the inconsistent "Display Field" keys in the search results.
348
- ###
349
- ### Sometimes spaces have been converted to underscores, sometimes not, sometimes both.
350
- ### Same for dashes.
351
- ### E.g :"Last Check-in"/:Last_Check_in/:"Last_Check-in", :Computer_Name, and :"Display Name"/:Display_Name
352
- ###
353
- ### This ensures there's always the fully underscored version.
354
- ###
355
- ### Update an internally used array of the display field names, symbolized, with
356
- ### spaces and dashes converted to underscores. We use these
357
- ### to overcome inconsistencies in how the names come from the API
358
- ###
359
- ### @return [void]
360
- ###
361
- def standardize_display_field_keys
362
- spdash=
363
- us =
364
- @display_field_std_keys = @display_fields.map{|f| f.gsub(/ |-/,"_").to_sym }
365
- end
313
+ # Clean up the inconsistent "Display Field" keys in the search results.
314
+ #
315
+ # Sometimes spaces have been converted to underscores, sometimes not, sometimes both.
316
+ # Same for dashes.
317
+ # E.g :"Last Check-in"/:Last_Check_in/:"Last_Check-in", :Computer_Name, and :"Display Name"/:Display_Name
318
+ #
319
+ # This ensures there's always the fully underscored version.
320
+ #
321
+ # Update an internally used array of the display field names, symbolized, with
322
+ # spaces and dashes converted to underscores. We use these
323
+ # to overcome inconsistencies in how the names come from the API
324
+ #
325
+ # @return [void]
326
+ #
327
+ # def standardize_display_field_keys
328
+ # spdash =
329
+ # us =
330
+ # @display_field_std_keys = @display_fields.map { |f| f.gsub(/ |-/, '_').to_sym }
331
+ # end
366
332
 
367
333
  def rest_xml
368
334
  doc = REXML::Document.new APIConnection::XML_HEADER
@@ -375,16 +341,15 @@ module JSS
375
341
  acs << @criteria.rest_xml
376
342
 
377
343
  df = acs.add_element('display_fields')
378
- @display_fields.each{|f| df.add_element('display_field').add_element('name').text = f }
344
+ @display_fields.each { |f| df.add_element('display_field').add_element('name').text = f }
379
345
 
380
- return doc.to_s
346
+ doc.to_s
381
347
  end # rest xml
382
348
 
383
349
  end # class AdvancedSearch
384
350
 
385
351
  end # module JSS
386
352
 
387
- require "jss/api_object/advanced_search/advanced_computer_search"
388
- require "jss/api_object/advanced_search/advanced_mobile_device_search"
389
- require "jss/api_object/advanced_search/advanced_user_search"
390
-
353
+ require 'jss/api_object/advanced_search/advanced_computer_search'
354
+ require 'jss/api_object/advanced_search/advanced_mobile_device_search'
355
+ require 'jss/api_object/advanced_search/advanced_user_search'