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
- #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
86 87 88 |
# File 'lib/jss/api_object/purchasable.rb', line 86 def applecare_id @applecare_id end |
#is_leased ⇒ Boolean Also known as: leased?
89 90 91 |
# File 'lib/jss/api_object/purchasable.rb', line 89 def is_leased @is_leased end |
#is_purchased ⇒ Boolean Also known as: purchased?
95 96 97 |
# File 'lib/jss/api_object/purchasable.rb', line 95 def is_purchased @is_purchased end |
#lease_expires ⇒ Time
92 93 94 |
# File 'lib/jss/api_object/purchasable.rb', line 92 def lease_expires @lease_expires end |
#life_expectancy ⇒ Integer
101 102 103 |
# File 'lib/jss/api_object/purchasable.rb', line 101 def life_expectancy @life_expectancy end |
#po_date ⇒ Time
107 108 109 |
# File 'lib/jss/api_object/purchasable.rb', line 107 def po_date @po_date end |
#po_number ⇒ String
104 105 106 |
# File 'lib/jss/api_object/purchasable.rb', line 104 def po_number @po_number end |
#purchase_price ⇒ Float
98 99 100 |
# File 'lib/jss/api_object/purchasable.rb', line 98 def purchase_price @purchase_price end |
#purchasing_account ⇒ String
110 111 112 |
# File 'lib/jss/api_object/purchasable.rb', line 110 def purchasing_account @purchasing_account end |
#purchasing_contact ⇒ String
113 114 115 |
# File 'lib/jss/api_object/purchasable.rb', line 113 def purchasing_contact @purchasing_contact end |
#vendor ⇒ String
116 117 118 |
# File 'lib/jss/api_object/purchasable.rb', line 116 def vendor @vendor end |
#warranty_expires ⇒ Time
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?.
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 \ @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
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_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.
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_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.
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 = @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 |