Module: Jamf::Purchasable

Included in:
Computer, MobileDevice, Peripheral
Defined in:
lib/jamf/api/classic/api_objects/purchasable.rb

Overview

A mix-in module for handling purchasing data for objects in the JSS.

The JSS objects that have purchasing data all have basically the same data, a simple hash with these keys:

  • :applecare_id => String,

  • :is_leased => Boolean,

  • :is_purchased => Boolean,

  • :lease_expires => Time,

  • :life_expectancy => Integer,

  • :po_date => Time,

  • :po_number => String,

  • :purchase_price => Float,

  • :purchasing_account => String

  • :purchasing_contact => String,

  • :vendor => String,

  • :warranty_expires => Time

These items become direct attributes of objects where this module is mixed-in.

If the class also is Creatable or Updatable it must include the value of #purchasing_xml in its rest_xml output.

Constant Summary collapse

PURCHASABLE =

Constants

true
SUBSET_PURCH =
"Purchasing"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#applecare_idString

Returns:



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

def applecare_id
  @applecare_id
end

#is_leasedBoolean Also known as: leased?

Returns:

  • (Boolean)


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

def is_leased
  @is_leased
end

#is_purchasedBoolean Also known as: purchased?

Returns:

  • (Boolean)


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

def is_purchased
  @is_purchased
end

#lease_expiresTime

Returns:



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

def lease_expires
  @lease_expires
end

#life_expectancyInteger

Returns:

  • (Integer)


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

def life_expectancy
  @life_expectancy
end

#po_dateTime

Returns:



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

def po_date
  @po_date
end

#po_numberString

Returns:



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

def po_number
  @po_number
end

#purchase_priceFloat

Returns:

  • (Float)


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

def purchase_price
  @purchase_price
end

#purchasing_accountString

Returns:



108
109
110
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 108

def 
  @purchasing_account
end

#purchasing_contactString

Returns:



111
112
113
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 111

def purchasing_contact
  @purchasing_contact
end

#vendorString

Returns:



114
115
116
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 114

def vendor
  @vendor
end

#warranty_expiresTime

Returns:



117
118
119
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 117

def warranty_expires
  @warranty_expires
end

Instance Method Details

#has_purchasing?Boolean

Returns does this item have any purchasing info?.

Returns:

  • (Boolean)

    does this item have any purchasing info?



218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 218

def has_purchasing?
  @applecare_id or \
  @is_leased or \
  @is_purchased or \
  @lease_expires or \
  @life_expectancy or \
  @po_date or \
  @po_number or \
  @purchase_price or \
  @purchasing_account or \
  @purchasing_contact or \
  @vendor or \
  @warranty_expires
end

#parse_purchasingObject

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.

Call this during initialization of objects that have a Purchasing subset and the purchasing attribute will be populated from @init_data



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 265

def parse_purchasing
  return unless @init_data[:purchasing]

  @purchasing = @init_data[:purchasing]

  @lease_expires = JSS.epoch_to_time  @purchasing[:lease_expires_epoch]
  @po_date = JSS.epoch_to_time  @purchasing[:po_date_epoch]
  @warranty_expires = JSS.epoch_to_time  @purchasing[:warranty_expires_epoch]

  @applecare_id = @purchasing[:applecare_id]
  @is_leased = @purchasing[:is_leased]
  @is_purchased = @purchasing[:is_purchased]
  @life_expectancy = @purchasing[:life_expectancy]
  @po_number = @purchasing[:po_number]
  @purchase_price = @purchasing[:purchase_price].to_f if @purchasing[:purchase_price]
  @purchasing_account = @purchasing[:purchasing_account]
  @purchasing_contact = @purchasing[:purchasing_contact]
  @vendor = @purchasing[:vendor]
end

#purchasingHash<String>

All the purchasing 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:



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 240

def purchasing
  {
    :applecare_id => @applecare_id,
    :is_leased => @is_leased,
    :is_purchased => @is_purchased,
    :lease_expires => @lease_expires,
    :life_expectancy => @life_expectancy,
    :po_date => @po_date,
    :po_number => @po_number,
    :purchase_price => @purchase_price,
    :purchasing_account => @purchasing_account,
    :purchasing_contact => @purchasing_contact,
    :vendor => @vendor,
    :warranty_expires => @warranty_expires,
  }
end

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

Returns A <purchasing> element to be included in the rest_xml of objects that mix-in this module.

Returns:

  • (REXML::Element)

    A <purchasing> element to be included in the rest_xml of objects that mix-in this module.



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 291

def purchasing_xml
  purch = REXML::Element.new('purchasing')

  purch.add_element('applecare_id').text = @applecare_id
  purch.add_element('is_leased').text = @is_leased
  purch.add_element('is_purchased').text = @is_purchased.to_s
  purch.add_element('lease_expires_epoch').text = @lease_expires ? @lease_expires.to_jss_epoch : nil
  # Note, life expectancy can't be an empty xml element, it must be zero if emtpy.
  purch.add_element('life_expectancy').text = @life_expectancy ? @life_expectancy : 0
  purch.add_element('po_date_epoch').text = @po_date ? @po_date.to_jss_epoch : nil
  purch.add_element('po_number').text = @po_number
  purch.add_element('purchase_price').text = @purchase_price
  purch.add_element('purchasing_account').text = @purchasing_account
  purch.add_element('purchasing_contact').text = @purchasing_contact
  purch.add_element('vendor').text = @vendor
  purch.add_element('warranty_expires_epoch').text = @warranty_expires ? @warranty_expires.to_jss_epoch : nil
  return purch
end