Module: JSS::Locatable
- Included in:
- Computer, MobileDevice, Peripheral
- Defined in:
- lib/jss/api_object/locatable.rb,
lib/jss.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, which are populated by calling #parse_location in the subclass’s constructor after calling super.
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
85 86 87 |
# File 'lib/jss/api_object/locatable.rb', line 85 def building @building end |
#department ⇒ String
88 89 90 |
# File 'lib/jss/api_object/locatable.rb', line 88 def department @department end |
#email_address ⇒ String
91 92 93 |
# File 'lib/jss/api_object/locatable.rb', line 91 def email_address @email_address end |
#position ⇒ String
97 98 99 |
# File 'lib/jss/api_object/locatable.rb', line 97 def position @position end |
#real_name ⇒ String
100 101 102 |
# File 'lib/jss/api_object/locatable.rb', line 100 def real_name @real_name end |
#username ⇒ String Also known as: user
106 107 108 |
# File 'lib/jss/api_object/locatable.rb', line 106 def username @username end |
Instance Method Details
#clear_location ⇒ void
This method returns an undefined value.
Clear all location data
246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/jss/api_object/locatable.rb', line 246 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?.
230 231 232 233 234 235 236 237 238 239 |
# File 'lib/jss/api_object/locatable.rb', line 230 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.
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/jss/api_object/locatable.rb', line 141 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
272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/jss/api_object/locatable.rb', line 272 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 return 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
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/jss/api_object/locatable.rb', line 121 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 |