module Jamf::Locatable
A mix-in module for handling location/user data for objects in the JSS
.
The JSS
objects that have location data return it in a :location subset, which all have basically the same data,a simple hash with these keys:
-
:building =>
String
, -
:department =>
String
, -
:email_address =>
String
, -
:phone =>
String
-
:position =>
String
-
:real_name =>
String
, -
:room =>
String
, -
:username =>
String
Including this module in an {APIObject} subclass will give it attributes matching those keys.
If the subclass is creatable or updatable, calling {#location_xml} returns a REXML element representing the location subset, to be included with the rest_xml output of the subclass.
Constants
- LOCATABLE
Attributes
@return [String]
@return [String]
@return [String]
@return [String]
@return [String]
@return [String]
@return [String]
@return [String]
@return [String]
Public Instance Methods
# File lib/jamf/api/classic/api_objects/locatable.rb 156 def building=(new_val) 157 return nil if @building == new_val 158 159 new_val = new_val.to_s.strip 160 unless new_val.empty? or Jamf::Building.all_names(cnx: @cnx).include? new_val 161 raise Jamf::NoSuchItemError, 162 "No building named #{new_val} exists in the JSS" 163 end 164 165 @building = new_val 166 @need_to_update = true 167 end
Clear all location data
@return [void]
# File lib/jamf/api/classic/api_objects/locatable.rb 258 def clear_location 259 @username = '' 260 @real_name = '' 261 @email_address = '' 262 @position = '' 263 @phone = '' 264 @department = '' 265 @building = '' 266 @room = '' 267 @need_to_update = true 268 end
# File lib/jamf/api/classic/api_objects/locatable.rb 170 def department=(new_val) 171 return nil if @department == new_val 172 173 new_val = new_val.to_s.strip 174 unless new_val.empty? or Jamf::Department.all_names(cnx: @cnx).include? new_val 175 raise Jamf::NoSuchItemError, 176 "No department named #{new_val} exists in the JSS" 177 end 178 179 @department = new_val 180 @need_to_update = true 181 end
# File lib/jamf/api/classic/api_objects/locatable.rb 184 def email_address=(new_val) 185 return nil if @email_address == new_val 186 187 new_val = new_val.to_s.strip 188 raise Jamf::InvalidDataError, 'Invalid Email Address' unless new_val.empty? or new_val =~ /^[^\s@]+@[^\s@]+$/ 189 190 @email_address = new_val 191 @need_to_update = true 192 end
@return [Boolean] Does this item have location data?
# File lib/jamf/api/classic/api_objects/locatable.rb 242 def has_location? 243 @username or \ 244 @real_name or \ 245 @email_address or \ 246 @position or \ 247 @phone or \ 248 @department or \ 249 @building or \ 250 @room 251 end
All the location data in a Hash
, as it comes from the API.
The reason it isn’t stored this way is to prevent editing of the hash directly.
@return [Hash<String>] the location data
# File lib/jamf/api/classic/api_objects/locatable.rb 137 def location 138 { 139 building: @building, 140 department: @department, 141 email_address: @email_address, 142 phone: @phone, 143 position: @position, 144 real_name: @real_name, 145 room: @room, 146 username: @username 147 } 148 end
@api private
Return a REXML <location> element to be included in the rest_xml of objects that have a Location subset
@return [REXML::Element]
# File lib/jamf/api/classic/api_objects/locatable.rb 282 def location_xml 283 location = REXML::Element.new('location') 284 location.add_element('building').text = @building 285 location.add_element('department').text = @department 286 location.add_element('email_address').text = @email_address 287 location.add_element('position').text = @position 288 location.add_element('phone').text = @phone 289 location.add_element('real_name').text = @real_name 290 location.add_element('room').text = @room 291 location.add_element('username').text = @username 292 location 293 end
Call this during initialization of objects that have a Location subset and the location attributes will be populated (as primary attributes) from @init_data
@return [void]
# File lib/jamf/api/classic/api_objects/locatable.rb 118 def parse_location 119 @init_data[:location] ||= {} 120 @building = @init_data[:location][:building] 121 @department = @init_data[:location][:department] 122 @email_address = @init_data[:location][:email_address] 123 @phone = @init_data[:location][:phone] 124 @position = @init_data[:location][:position] 125 @real_name = @init_data[:location][:real_name] 126 @room = @init_data[:location][:room] 127 @username = @init_data[:location][:username] 128 end
# File lib/jamf/api/classic/api_objects/locatable.rb 204 def phone=(new_val) 205 return nil if @phone == new_val 206 207 new_val = new_val.to_s.strip 208 @phone = new_val 209 @need_to_update = true 210 end
# File lib/jamf/api/classic/api_objects/locatable.rb 195 def position=(new_val) 196 return nil if @position == new_val 197 198 new_val = new_val.to_s.strip 199 @position = new_val 200 @need_to_update = true 201 end
# File lib/jamf/api/classic/api_objects/locatable.rb 213 def real_name=(new_val) 214 return nil if @real_name == new_val 215 216 new_val = new_val.to_s.strip 217 @real_name = new_val 218 @need_to_update = true 219 end
# File lib/jamf/api/classic/api_objects/locatable.rb 222 def room=(new_val) 223 return nil if @room == new_val 224 225 new_val = new_val.to_s.strip 226 @room = new_val 227 @need_to_update = true 228 end
# File lib/jamf/api/classic/api_objects/locatable.rb 231 def username=(new_val) 232 return nil if @username == new_val 233 234 new_val = new_val.to_s.strip 235 @username = new_val 236 @need_to_update = true 237 end