Module: Jamf::Locatable
- Included in:
- Computer, MobileDevice, Peripheral
- Defined in:
- lib/jamf/api/classic/api_objects/locatable.rb
Overview
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.
Constant Summary collapse
- LOCATABLE =
Constants
true
Instance Attribute Summary collapse
- #building ⇒ String
- #department ⇒ String
- #email_address ⇒ String
- #phone ⇒ String
- #position ⇒ String
- #real_name ⇒ String
- #room ⇒ String
- #username ⇒ String (also: #user)
Instance Method Summary collapse
-
#clear_location ⇒ void
Clear all location data.
-
#has_location? ⇒ Boolean
Does this item have location data?.
-
#location ⇒ Hash<String>
All the location data in a Hash, as it comes from the API.
-
#location_xml ⇒ REXML::Element
private
Return a REXML <location> element to be included in the rest_xml of objects that have a Location subset.
-
#parse_location ⇒ void
Call this during initialization of objects that have a Location subset and the location attributes will be populated (as primary attributes) from @init_data.
Instance Attribute Details
#building ⇒ String
65 66 67 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 65 def building @building end |
#department ⇒ String
68 69 70 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 68 def department @department end |
#email_address ⇒ String
71 72 73 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 71 def email_address @email_address end |
#phone ⇒ String
74 75 76 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 74 def phone @phone end |
#position ⇒ String
77 78 79 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 77 def position @position end |
#real_name ⇒ String
80 81 82 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 80 def real_name @real_name end |
#room ⇒ String
83 84 85 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 83 def room @room end |
#username ⇒ String Also known as: user
86 87 88 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 86 def username @username end |
Instance Method Details
#clear_location ⇒ void
This method returns an undefined value.
Clear all location data
240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 240 def clear_location @username = '' @real_name = '' @email_address = '' @position = '' @phone = '' @department = '' @building = '' @room = '' @need_to_update = true end |
#has_location? ⇒ Boolean
Returns Does this item have location data?.
224 225 226 227 228 229 230 231 232 233 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 224 def has_location? @username or \ @real_name or \ @email_address or \ @position or \ @phone or \ @department or \ @building or \ @room end |
#location ⇒ Hash<String>
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.
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 119 def location { building: @building, department: @department, email_address: @email_address, phone: @phone, position: @position, real_name: @real_name, room: @room, username: @username } end |
#location_xml ⇒ REXML::Element
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a REXML <location> element to be included in the rest_xml of objects that have a Location subset
264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 264 def location_xml location = REXML::Element.new('location') location.add_element('building').text = @building location.add_element('department').text = @department location.add_element('email_address').text = @email_address location.add_element('position').text = @position location.add_element('phone').text = @phone location.add_element('real_name').text = @real_name location.add_element('room').text = @room location.add_element('username').text = @username location end |
#parse_location ⇒ void
This method returns an undefined value.
Call this during initialization of objects that have a Location subset and the location attributes will be populated (as primary attributes) from @init_data
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 100 def parse_location @init_data[:location] ||= {} @building = @init_data[:location][:building] @department = @init_data[:location][:department] @email_address = @init_data[:location][:email_address] @phone = @init_data[:location][:phone] @position = @init_data[:location][:position] @real_name = @init_data[:location][:real_name] @room = @init_data[:location][:room] @username = @init_data[:location][:username] end |