module Jamf::Purchasable

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:

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.

Constants

PURCHASABLE

Constants

SUBSET_PURCH

Attributes

applecare_id[R]

@return [String]

is_leased[R]

@return [Boolean]

is_purchased[R]

@return [Boolean]

lease_expires[R]

@return [Time]

leased?[R]

@return [Boolean]

life_expectancy[R]

@return [Integer]

po_date[R]

@return [Time]

po_number[R]

@return [String]

purchase_price[R]

@return [Float]

purchased?[R]

@return [Boolean]

purchasing_account[R]

@return [String]

purchasing_contact[R]

@return [String]

vendor[R]

@return [String]

warranty_expires[R]

@return [Time]

Public Instance Methods

applecare_id=(new_val) click to toggle source

@return [void]

    # File lib/jamf/api/classic/api_objects/purchasable.rb
128 def applecare_id= (new_val)
129   return nil if @applecare_id == new_val
130   @applecare_id = new_val
131   @need_to_update = true
132 end
has_purchasing?() click to toggle source

@return [Boolean] does this item have any purchasing info?

    # File lib/jamf/api/classic/api_objects/purchasable.rb
218 def has_purchasing?
219   @applecare_id or \
220   @is_leased or \
221   @is_purchased or \
222   @lease_expires or \
223   @life_expectancy or \
224   @po_date or \
225   @po_number or \
226   @purchase_price or \
227   @purchasing_account or \
228   @purchasing_contact or \
229   @vendor or \
230   @warranty_expires
231 end
is_leased=(new_val) click to toggle source

@return [void]

    # File lib/jamf/api/classic/api_objects/purchasable.rb
135 def is_leased= (new_val)
136   return nil if @is_leased == new_val
137   @is_leased = new_val
138   @need_to_update = true
139 end
is_purchased=(new_val) click to toggle source

@return [void]

    # File lib/jamf/api/classic/api_objects/purchasable.rb
150 def is_purchased= (new_val)
151   return nil if @is_purchased == new_val
152   @is_purchased = new_val
153   @need_to_update = true
154 end
lease_expires=(date) click to toggle source

@return [void]

    # File lib/jamf/api/classic/api_objects/purchasable.rb
142 def lease_expires= (date)
143   parsed_date = Jamf.parse_time date
144   return nil if @lease_expires == parsed_date
145   @lease_expires = parsed_date
146   @need_to_update = true
147 end
life_expectancy=(new_val) click to toggle source

@return [void]

    # File lib/jamf/api/classic/api_objects/purchasable.rb
164 def life_expectancy= (new_val)
165   return nil if @life_expectancy == new_val
166   @life_expectancy = new_val
167   @need_to_update = true
168 end
parse_purchasing() click to toggle source

@api private

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

    # File lib/jamf/api/classic/api_objects/purchasable.rb
265 def parse_purchasing
266   return unless @init_data[:purchasing]
267 
268   @purchasing = @init_data[:purchasing]
269 
270   @lease_expires = JSS.epoch_to_time  @purchasing[:lease_expires_epoch]
271   @po_date = JSS.epoch_to_time  @purchasing[:po_date_epoch]
272   @warranty_expires = JSS.epoch_to_time  @purchasing[:warranty_expires_epoch]
273 
274   @applecare_id = @purchasing[:applecare_id]
275   @is_leased = @purchasing[:is_leased]
276   @is_purchased = @purchasing[:is_purchased]
277   @life_expectancy = @purchasing[:life_expectancy]
278   @po_number = @purchasing[:po_number]
279   @purchase_price = @purchasing[:purchase_price].to_f if @purchasing[:purchase_price]
280   @purchasing_account = @purchasing[:purchasing_account]
281   @purchasing_contact = @purchasing[:purchasing_contact]
282   @vendor = @purchasing[:vendor]
283 end
po_date=(date) click to toggle source

@return [void]

    # File lib/jamf/api/classic/api_objects/purchasable.rb
178 def po_date= (date)
179   parsed_date = Jamf.parse_time date
180   return nil if @po_date == parsed_date
181   @po_date = parsed_date
182   @need_to_update = true
183 end
po_number=(new_val) click to toggle source

@return [void]

    # File lib/jamf/api/classic/api_objects/purchasable.rb
171 def po_number= (new_val)
172   return nil if @po_number == new_val
173   @po_number = new_val
174   @need_to_update = true
175 end
purchase_price=(new_val) click to toggle source

@return [void]

    # File lib/jamf/api/classic/api_objects/purchasable.rb
157 def purchase_price= (new_val)
158   return nil if @purchase_price == new_val
159   @purchase_price = new_val
160   @need_to_update = true
161 end
purchasing() click to toggle source

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.

@return [Hash<String>] the location data

    # File lib/jamf/api/classic/api_objects/purchasable.rb
240 def purchasing
241   {
242     :applecare_id => @applecare_id,
243     :is_leased => @is_leased,
244     :is_purchased => @is_purchased,
245     :lease_expires => @lease_expires,
246     :life_expectancy => @life_expectancy,
247     :po_date => @po_date,
248     :po_number => @po_number,
249     :purchase_price => @purchase_price,
250     :purchasing_account => @purchasing_account,
251     :purchasing_contact => @purchasing_contact,
252     :vendor => @vendor,
253     :warranty_expires => @warranty_expires,
254   }
255 end
purchasing_account=(new_val) click to toggle source

@return [void]

    # File lib/jamf/api/classic/api_objects/purchasable.rb
186 def purchasing_account= (new_val)
187   return nil if @purchasing_account == new_val
188   @purchasing_account = new_val
189   @need_to_update = true
190 end
purchasing_contact=(new_val) click to toggle source

@return [void]

    # File lib/jamf/api/classic/api_objects/purchasable.rb
193 def purchasing_contact= (new_val)
194   return nil if @purchasing_contact == new_val
195   @purchasing_contact = new_val
196   @need_to_update = true
197 end
purchasing_xml() click to toggle source

@api private

@return [REXML::Element] A <purchasing> element to be

included in the rest_xml of objects that mix-in this module.
    # File lib/jamf/api/classic/api_objects/purchasable.rb
291 def purchasing_xml
292   purch = REXML::Element.new('purchasing')
293 
294   purch.add_element('applecare_id').text = @applecare_id
295   purch.add_element('is_leased').text = @is_leased
296   purch.add_element('is_purchased').text = @is_purchased.to_s
297   purch.add_element('lease_expires_epoch').text = @lease_expires ? @lease_expires.to_jss_epoch : nil
298   # Note, life expectancy can't be an empty xml element, it must be zero if emtpy.
299   purch.add_element('life_expectancy').text = @life_expectancy ? @life_expectancy : 0
300   purch.add_element('po_date_epoch').text = @po_date ? @po_date.to_jss_epoch : nil
301   purch.add_element('po_number').text = @po_number
302   purch.add_element('purchase_price').text = @purchase_price
303   purch.add_element('purchasing_account').text = @purchasing_account
304   purch.add_element('purchasing_contact').text = @purchasing_contact
305   purch.add_element('vendor').text = @vendor
306   purch.add_element('warranty_expires_epoch').text = @warranty_expires ? @warranty_expires.to_jss_epoch : nil
307   return purch
308 end
vendor=(new_val) click to toggle source

@return [void]

    # File lib/jamf/api/classic/api_objects/purchasable.rb
200 def vendor= (new_val)
201   return nil if @vendor == new_val
202   @vendor = new_val
203   @need_to_update = true
204 end
warranty_expires=(date) click to toggle source

@return [void]

    # File lib/jamf/api/classic/api_objects/purchasable.rb
207 def warranty_expires= (date)
208   parsed_date = Jamf.parse_time date
209   return nil if @warranty_expires == parsed_date
210   @warranty_expires = parsed_date
211   @need_to_update = true
212 end