Module: JSS::Purchasable

Included in:
Computer, MobileDevice, Peripheral
Defined in:
lib/jss/api_object/purchasable.rb,
lib/jss.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.

Classes mixing in this module must call #parse_purchasing in their initialization method in order to populate the attributes from @init_data.

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:



86
87
88
# File 'lib/jss/api_object/purchasable.rb', line 86

def applecare_id
  @applecare_id
end

#is_leasedBoolean Also known as: leased?

Returns:

  • (Boolean)


89
90
91
# File 'lib/jss/api_object/purchasable.rb', line 89

def is_leased
  @is_leased
end

#is_purchasedBoolean Also known as: purchased?

Returns:

  • (Boolean)


95
96
97
# File 'lib/jss/api_object/purchasable.rb', line 95

def is_purchased
  @is_purchased
end

#lease_expiresTime

Returns:



92
93
94
# File 'lib/jss/api_object/purchasable.rb', line 92

def lease_expires
  @lease_expires
end

#life_expectancyInteger

Returns:

  • (Integer)


101
102
103
# File 'lib/jss/api_object/purchasable.rb', line 101

def life_expectancy
  @life_expectancy
end

#po_dateTime

Returns:



107
108
109
# File 'lib/jss/api_object/purchasable.rb', line 107

def po_date
  @po_date
end

#po_numberString

Returns:



104
105
106
# File 'lib/jss/api_object/purchasable.rb', line 104

def po_number
  @po_number
end

#purchase_priceFloat

Returns:

  • (Float)


98
99
100
# File 'lib/jss/api_object/purchasable.rb', line 98

def purchase_price
  @purchase_price
end

#purchasing_accountString

Returns:



110
111
112
# File 'lib/jss/api_object/purchasable.rb', line 110

def 
  
end

#purchasing_contactString

Returns:



113
114
115
# File 'lib/jss/api_object/purchasable.rb', line 113

def purchasing_contact
  @purchasing_contact
end

#vendorString

Returns:



116
117
118
# File 'lib/jss/api_object/purchasable.rb', line 116

def vendor
  @vendor
end

#warranty_expiresTime

Returns:



119
120
121
# File 'lib/jss/api_object/purchasable.rb', line 119

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?



220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/jss/api_object/purchasable.rb', line 220

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



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/jss/api_object/purchasable.rb', line 267

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[: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:



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/jss/api_object/purchasable.rb', line 242

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



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/jss/api_object/purchasable.rb', line 293

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