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:



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

def building
  @building
end

#departmentString

Returns:



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

def department
  @department
end

#email_addressString

Returns:



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

def email_address
  @email_address
end

#phoneString

Returns:



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

def phone
  @phone
end

#positionString

Returns:



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

def position
  @position
end

#real_nameString

Returns:



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

def real_name
  @real_name
end

#roomString

Returns:



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

def room
  @room
end

#usernameString Also known as: user

Returns:



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

def username
  @username
end

Instance Method Details

#clear_locationvoid

This method returns an undefined value.

Clear all location data



258
259
260
261
262
263
264
265
266
267
268
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 258

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?



242
243
244
245
246
247
248
249
250
251
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 242

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:



137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 137

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)


282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/jamf/api/classic/api_objects/locatable.rb', line 282

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_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



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

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