Module: JSS::Purchasable
- Included in:
- Computer, MobileDevice, Peripheral
- Defined in:
- lib/jss-api/api_object/purchasable.rb,
lib/jss-api.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
- #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
85 86 87 |
# File 'lib/jss-api/api_object/purchasable.rb', line 85 def applecare_id @applecare_id end |
#is_leased ⇒ Boolean Also known as: leased?
88 89 90 |
# File 'lib/jss-api/api_object/purchasable.rb', line 88 def is_leased @is_leased end |
#is_purchased ⇒ Boolean Also known as: purchased?
94 95 96 |
# File 'lib/jss-api/api_object/purchasable.rb', line 94 def is_purchased @is_purchased end |
#lease_expires ⇒ Time
91 92 93 |
# File 'lib/jss-api/api_object/purchasable.rb', line 91 def lease_expires @lease_expires end |
#life_expectancy ⇒ Integer
100 101 102 |
# File 'lib/jss-api/api_object/purchasable.rb', line 100 def life_expectancy @life_expectancy end |
#po_date ⇒ Time
106 107 108 |
# File 'lib/jss-api/api_object/purchasable.rb', line 106 def po_date @po_date end |
#po_number ⇒ String
103 104 105 |
# File 'lib/jss-api/api_object/purchasable.rb', line 103 def po_number @po_number end |
#purchase_price ⇒ Float
97 98 99 |
# File 'lib/jss-api/api_object/purchasable.rb', line 97 def purchase_price @purchase_price end |
#purchasing_account ⇒ String
109 110 111 |
# File 'lib/jss-api/api_object/purchasable.rb', line 109 def purchasing_account @purchasing_account end |
#purchasing_contact ⇒ String
112 113 114 |
# File 'lib/jss-api/api_object/purchasable.rb', line 112 def purchasing_contact @purchasing_contact end |
#vendor ⇒ String
115 116 117 |
# File 'lib/jss-api/api_object/purchasable.rb', line 115 def vendor @vendor end |
#warranty_expires ⇒ Time
118 119 120 |
# File 'lib/jss-api/api_object/purchasable.rb', line 118 def warranty_expires @warranty_expires end |
Instance Method Details
#has_purchasing? ⇒ Boolean
Returns does this item have any purchasing info?.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/jss-api/api_object/purchasable.rb', line 219 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
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/jss-api/api_object/purchasable.rb', line 266 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.
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/jss-api/api_object/purchasable.rb', line 241 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.
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/jss-api/api_object/purchasable.rb', line 292 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 |