Class: Jamf::MobileDevice

Inherits:
CollectionResource show all
Extended by:
UnCreatable, UnDeletable
Includes:
Extendable, Locatable, Referable
Defined in:
lib/jamf/api/resources/collection_resources/mobile_device.rb

Overview

A mobile device in the JSS

Constant Summary collapse

IOS =

Class Constants

'ios'.freeze
APPLETV =
'appleTv'.freeze
ANDROID =
'android'.freeze
UNKNOWN =
'unknown'.freeze
IPHONE =
'iPhone'.freeze
IPOD =
'iPod'.freeze
IPAD =
'iPad'.freeze
TYPES =

The enum for the ‘type’ attribute

[
  IOS,
  APPLETV,
  ANDROID,
  UNKNOWN
].freeze
APPLE_TYPES =
[IOS, APPLETV].freeze
RSRC_PATH =
'/inventory/obj/mobileDevice'.freeze
UPDATE_RESOURCE =

This has a non-std update resource we POST to /inventory/obj/mobileDevice/#id/update instad of the normal PUT to /inventory/obj/mobileDevice/#id

{ method: :post, path_suffix: 'update' }.freeze
OBJECT_MODEL =
{

  # @!attribute [r] id
  #   @return [Integer]
  id: {
    class: :integer,
    identifier: :primary,
    readonly: true
  },

  # @!attribute name
  #   @param [String]
  #   @return [String]
  name: {
    class: :string
  },

  # @!attribute [r] serialNumber
  #   @return [String]
  serialNumber: {
    class: :string,
    identifier: true,
    readonly: true
  },

  # @!attribute [r] wifiMacAddress
  #   @return [String]
  wifiMacAddress: {
    class: :string,
    identifier: true,
    readonly: true
  },

  # @!attribute [r] udid
  #   @return [String]
  udid: {
    class: :string,
    identifier: true,
    readonly: true
  },

  # @!attribute [r] phoneNumber
  #   @return [String]
  phoneNumber: {
    class: :string,
    identifier: true,
    readonly: true
  },

  # @!attribute [r] model
  #   @return [String]
  model: {
    class: :string,
    readonly: true
  },

  # @!attribute [r] modelIdentifier
  #   @return [String]
  modelIdentifier: {
    class: :string,
    readonly: true
  },

  # @!attribute username
  #   Has custom setter, is part of Location in Details
  #   @param [String]
  #   @return [String]
  username: {
    class: :string,
    readonly: true
  },

  # TODO: Will jamf give us isManaged or isSupervised?
  # in the non-detail data?
  # @!attribute [r] isManaged
  #   @return [Boolean]
  # isManaged: {
  #   class: :boolean,
  #   readonly: true
  # },

  # @!attribute [r] type
  #   @return [Symbol]
  type: {
    class: :string,
    readonly: true,
    enum: Jamf::MobileDevice::TYPES
  }

}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Jamf::JSONObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object

catches the attributes in the details



292
293
294
295
296
297
298
299
300
# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 292

def method_missing(meth, *args, &block)
  if details.respond_to? meth
    details.send meth, *args, &block
  elsif type_details.respond_to? meth
    type_details.send meth, *args, &block
  else
    super
  end
end

Instance Attribute Details

#idInteger (readonly)

Returns:

  • (Integer)


# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 78

#isManagedBoolean (readonly)

Returns:

  • (Boolean)


# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 148

#modelString (readonly)

Returns:



# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 125

#modelIdentifierString (readonly)

Returns:



# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 132

#nameString

Parameters:

Returns:



# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 86

#phoneNumberString (readonly)

Returns:



# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 117

#serialNumberString (readonly)

Returns:



# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 93

#typeSymbol (readonly)

Returns:

  • (Symbol)


# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 157

#udidString (readonly)

Returns:



# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 109

#usernameString

Has custom setter, is part of Location in Details

Parameters:

Returns:



# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 139

#wifiMacAddressString (readonly)

Returns:



# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 101

Class Method Details

.all_androids(refresh: false, cnx: Jamf.cnx) ⇒ Array<Hash>

Returns the list of all Androids.

Returns:



216
217
218
# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 216

def self.all_androids(refresh: false, cnx: Jamf.cnx)
  all(refresh, cnx: cnx).select { |d| d[:type] == ANDROID }
end

.all_appleTvs(refresh: false, cnx: Jamf.cnx) ⇒ Array<Hash>

Returns the list of all AppleTVs.

Returns:



211
212
213
# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 211

def self.all_appleTvs(refresh: false, cnx: Jamf.cnx)
  all(refresh, cnx: cnx).select { |d| d[:type] == APPLETV }
end

.all_ipads(refresh: false, cnx: Jamf.cnx) ⇒ Array<Hash>

Returns the list of all iPads.

Returns:



206
207
208
# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 206

def self.all_ipads(refresh: false, cnx: Jamf.cnx)
  all(refresh, cnx: cnx).select { |d| d[:model].start_with? IPAD }
end

.all_iphones(refresh: false, cnx: Jamf.cnx) ⇒ Array<Hash>

Returns the list of all iPhones.

Returns:



196
197
198
# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 196

def self.all_iphones(refresh: false, cnx: Jamf.cnx)
  all(refresh, cnx: cnx).select { |d| d[:model].start_with? IPHONE }
end

.all_ipods(refresh: false, cnx: Jamf.cnx) ⇒ Array<Hash>

Returns the list of all iPods.

Returns:



201
202
203
# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 201

def self.all_ipods(refresh: false, cnx: Jamf.cnx)
  all(refresh, cnx: cnx).select { |d| d[:model].start_with? IPOD }
end

.creatable?Boolean Originally defined in module UnCreatable

Returns:

  • (Boolean)

.deletable?Boolean Originally defined in module UnDeletable

Returns:

  • (Boolean)

Instance Method Details

#clear_unsaved_changesObject

clear changes for details as well as top



270
271
272
273
274
# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 270

def clear_unsaved_changes
  @details.clear_unsaved_changes if @details
  ext_attrs_clear_unsaved_changes
  @unsaved_changes = {}
end

#detailsObject

Fetch the details as needed



277
278
279
# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 277

def details
  @details ||= MobileDeviceDetails.fetch @id, @cnx
end

#ext_attr_namesObject Originally defined in module Extendable

#ext_attrsObject Originally defined in module Extendable

The Array of extensionAttributes converted to a Hash of ‘Name’ => value

#ext_attrs_clear_unsaved_changesObject Originally defined in module Extendable

#ext_attrs_to_jamfObject Originally defined in module Extendable

#ext_attrs_to_updateObject Originally defined in module Extendable

#ext_attrs_unsaved_changesObject Originally defined in module Extendable

#ext_attrs_unsaved_changes?Boolean Originally defined in module Extendable

Returns:

  • (Boolean)

#location=(_loc) ⇒ Object Originally defined in module Locatable

#referenceself.class::GenericReference Originally defined in module Referable

Returns A reference to this object.

Returns:

  • (self.class::GenericReference)

    A reference to this object.

#respond_to_missing?(meth) ⇒ Boolean

provides respond_to? for the attributes in the details

Returns:

  • (Boolean)


303
304
305
306
307
308
309
310
311
# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 303

def respond_to_missing?(meth, *)
  if details.respond_to? meth
    true
  elsif type_details.respond_to? meth
    true
  else
    super
  end
end

#set_ext_attr(ea_name, new_val) ⇒ Object Originally defined in module Extendable

#to_jamfObject

This custom method outputs a ‘UpdateMobileDevice’ object model as defined in the API docs



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 232

def to_jamf
  changes = unsaved_changes
  data_to_send = {}

  data_to_send[:name] = changes[:name][:new] if changes[:name]

  data_to_send[:assetTag] = changes[:assetTag][:new] if changes[:assetTag]
  data_to_send[:siteId] = changes[:site][:new].id if changes[:site]
  data_to_send[:location] = details.location.to_jamf if changes[:location]
  data_to_send[:updatedExtensionAttributes] = ext_attrs_to_jamf if ext_attrs_unsaved_changes?

  return data_to_send unless APPLE_TYPES.include? @type

  data_to_send[@type] = { purchasing: details.type_details.purchasing.to_jamf } if changes[:type_changes][:purchasing]

  data_to_send[APPLETV][:airplayPassword] = changes[:type_changes][:airplayPassword][:new] if @type == APPLETV && changes[:type_changes][:airplayPassword]

  data_to_send
end

#type_detailsObject

Return the correct part of the details for the device type



283
284
285
286
287
288
289
# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 283

def type_details
  case @type
  when :ios then details.ios
  when :appleTv then details.appleTv
  when :android then details.android
  end
end

#unsaved_changesObject

TODO - needed? Clean up? merge top-level and details changes and type-specific changes



254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/jamf/api/resources/collection_resources/mobile_device.rb', line 254

def unsaved_changes
  @unsaved_changes ||= {}
  # name is the only thing at the top-level that isn't readonly
  if @details
    changes = details.unsaved_changes
    changes[:name] = @unsaved_changes[:name] if @unsaved_changes[:name]
    changes[:ext_attrs] = ext_attrs_unsaved_changes if ext_attrs_unsaved_changes?
    type_changes = type_details.unsaved_changes
    changes[:type_changes] = type_changes unless type_changes.empty?
  else
    changes = @unsaved_changes
  end
  changes
end

#userObject Originally defined in module Locatable