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
- #applecare_id ⇒ String
- #is_leased ⇒ Boolean (also: #leased?)
- #is_purchased ⇒ Boolean (also: #purchased?)
- #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
Instance Method Summary collapse
-
#has_purchasing? ⇒ Boolean
Does this item have any purchasing info?.
-
#parse_purchasing ⇒ Object
private
Call this during initialization of objects that have a Purchasing subset and the purchasing attribute will be populated from @init_data.
-
#purchasing ⇒ Hash<String>
All the purchasing data in a Hash, as it comes from the API.
-
#purchasing_xml ⇒ REXML::Element
private
A <purchasing> element to be included in the rest_xml of objects that mix-in this module.
Instance Attribute Details
#applecare_id ⇒ String
66 67 68 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 66 def applecare_id @applecare_id end |
#is_leased ⇒ Boolean Also known as: leased?
69 70 71 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 69 def is_leased @is_leased end |
#is_purchased ⇒ Boolean Also known as: purchased?
75 76 77 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 75 def is_purchased @is_purchased end |
#lease_expires ⇒ Time
72 73 74 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 72 def lease_expires @lease_expires end |
#life_expectancy ⇒ Integer
81 82 83 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 81 def life_expectancy @life_expectancy end |
#po_date ⇒ Time
87 88 89 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 87 def po_date @po_date end |
#po_number ⇒ String
84 85 86 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 84 def po_number @po_number end |
#purchase_price ⇒ Float
78 79 80 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 78 def purchase_price @purchase_price end |
#purchasing_account ⇒ String
90 91 92 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 90 def purchasing_account @purchasing_account end |
#purchasing_contact ⇒ String
93 94 95 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 93 def purchasing_contact @purchasing_contact end |
#vendor ⇒ String
96 97 98 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 96 def vendor @vendor end |
#warranty_expires ⇒ Time
99 100 101 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 99 def warranty_expires @warranty_expires end |
Instance Method Details
#has_purchasing? ⇒ Boolean
Returns does this item have any purchasing info?.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 207 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_purchasing ⇒ Object
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
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 254 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 |
#purchasing ⇒ Hash<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.
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 229 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_xml ⇒ REXML::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.
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/jamf/api/classic/api_objects/purchasable.rb', line 280 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 || 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 purch end |