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

Instance Method Summary collapse

Instance Attribute Details

#buildingString

Returns:



84
85
86
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 84

def building
  @building
end

#departmentString

Returns:



87
88
89
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 87

def department
  @department
end

#email_addressString

Returns:



90
91
92
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 90

def email_address
  @email_address
end

#phoneString

Returns:



93
94
95
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 93

def phone
  @phone
end

#positionString

Returns:



96
97
98
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 96

def position
  @position
end

#real_nameString

Returns:



99
100
101
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 99

def real_name
  @real_name
end

#roomString

Returns:



102
103
104
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 102

def room
  @room
end

#usernameString Also known as: user

Returns:



105
106
107
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 105

def username
  @username
end

Instance Method Details

#clear_locationvoid

This method returns an undefined value.

Clear all location data



245
246
247
248
249
250
251
252
253
254
255
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 245

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?.

Returns:

  • (Boolean)

    Does this item have location data?



229
230
231
232
233
234
235
236
237
238
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 229

def has_location?
  @username or \
  @real_name or \
  @email_address or \
  @position or \
  @phone or \
  @department or \
  @building or \
  @room
end

#locationHash<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.

Returns:



140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 140

def location
  {
    :building => @building,
    :department => @department,
    :email_address => @email_address,
    :phone => @phone,
    :position => @position,
    :real_name => @real_name,
    :room => @room,
    :username => @username
  }
end

#location_xmlREXML::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

Returns:

  • (REXML::Element)


271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 271

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_locationvoid

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



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 120

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