Class: Jamf::Peripheral
- Includes:
- Creatable, Locatable, Purchasable, Sitable, Updatable, Uploadable
- Defined in:
- lib/jamf/api/classic/api_objects/peripheral.rb
Overview
A peripheral in the JSS
Constant Summary collapse
- RSRC_BASE =
The base for REST resources of this class
"peripherals"
- RSRC_LIST_KEY =
the hash key used for the JSON list output of all objects in the JSS
:peripherals
- RSRC_OBJECT_KEY =
The hash key used for the JSON object output. It’s also used in various error messages
:peripheral
- OBJECT_HISTORY_OBJECT_TYPE =
the object type for this object in the object history table. See APIObject#add_object_history_entry
8
- SITE_SUBSET =
Where is the Site data in the API JSON?
:general
Instance Attribute Summary collapse
- #applecare_id ⇒ String included from Purchasable
-
#bar_code_1 ⇒ String
(also: #barcode_1, #barcode1)
The “bar code 1” value.
-
#bar_code_2 ⇒ String
(also: #barcode_2, #barcode2)
The “bar code 2” value.
- #building ⇒ String included from Locatable
-
#computer_id ⇒ Integer
readonly
The id number of the computer to which this periph is connected.
- #department ⇒ String included from Locatable
- #email_address ⇒ String included from Locatable
- #is_leased ⇒ Boolean (also: #leased?) included from Purchasable
- #is_purchased ⇒ Boolean (also: #purchased?) included from Purchasable
- #lease_expires ⇒ Time included from Purchasable
- #life_expectancy ⇒ Integer included from Purchasable
-
#need_to_update ⇒ Boolean
included
from Updatable
readonly
Do we have unsaved changes?.
- #phone ⇒ String included from Locatable
- #po_date ⇒ Time included from Purchasable
- #po_number ⇒ String included from Purchasable
- #position ⇒ String included from Locatable
- #purchase_price ⇒ Float included from Purchasable
- #purchasing_account ⇒ String included from Purchasable
- #purchasing_contact ⇒ String included from Purchasable
- #real_name ⇒ String included from Locatable
- #room ⇒ String included from Locatable
-
#type ⇒ String
readonly
The type of peripheral.
- #username ⇒ String (also: #user) included from Locatable
- #vendor ⇒ String included from Purchasable
- #warranty_expires ⇒ Time included from Purchasable
Instance Method Summary collapse
-
#associate(computer) ⇒ void
(also: #assign_to)
Associate this peripheral with a computer.
-
#clear_location ⇒ void
included
from Locatable
Clear all location data.
-
#clone(new_name, api: nil, cnx: nil) ⇒ APIObject
included
from Creatable
make a clone of this API object, with a new name.
-
#create ⇒ Object
reset the restrsrc after creation.
-
#disassociate ⇒ void
(also: #unassign)
Disassociate this peripheral from any computer.
-
#fields ⇒ Hash
The field values of the peripheral Each key is the fields name, as a String and the value is the fields value, also as a String.
-
#has_location? ⇒ Boolean
included
from Locatable
Does this item have location data?.
-
#has_purchasing? ⇒ Boolean
included
from Purchasable
Does this item have any purchasing info?.
-
#initialize(**args) ⇒ Peripheral
constructor
A new instance of Peripheral.
-
#location ⇒ Hash<String>
included
from Locatable
All the location data in a Hash, as it comes from the API.
-
#location_xml ⇒ REXML::Element
included
from Locatable
private
Return a REXML <location> element to be included in the rest_xml of objects that have a Location subset.
-
#name=(newname) ⇒ Object
periphs don’t have names.
-
#parse_location ⇒ void
included
from Locatable
Call this during initialization of objects that have a Location subset and the location attributes will be populated (as primary attributes) from @init_data.
-
#parse_purchasing ⇒ Object
included
from Purchasable
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>
included
from Purchasable
All the purchasing data in a Hash, as it comes from the API.
-
#purchasing_xml ⇒ REXML::Element
included
from Purchasable
private
A <purchasing> element to be included in the rest_xml of objects that mix-in this module.
-
#set_field(field, value) ⇒ void
Set the value of a field.
-
#site=(new_site) ⇒ void
included
from Sitable
Change the site of this object.
-
#site_assigned? ⇒ Boolean
included
from Sitable
Does this object have a site assigned?.
-
#site_id ⇒ Integer
included
from Sitable
The id of the site for this object.
-
#site_name ⇒ String
(also: #site)
included
from Sitable
The name of the site for this object.
-
#site_object ⇒ Jamf::Site
included
from Sitable
The Jamf::Site instance for this object’s site.
-
#unset_site ⇒ void
included
from Sitable
Set the site to nothing.
-
#upload(type, local_file, force_ipa_upload: false) ⇒ Boolean
included
from Uploadable
instance method wrapper for class method.
Constructor Details
#initialize(**args) ⇒ Peripheral
Returns a new instance of Peripheral.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/jamf/api/classic/api_objects/peripheral.rb', line 118 def initialize(**args) ### periphs don't really have names, and the JSS module list method for ### periphs gives the computer_id as the name, so give it a temp ### name of "-1", which shouldn't ever exist in the JSS args[:name] ||= "-1" super if args[:id] == :new raise Jamf::InvalidDataError, "New Peripherals must have a :type, which must be one of those defined in the JSS." unless args[:type] @type = args[:type] raise Jamf::InvalidDataError, "No peripheral type '#{@type}' in the JSS" unless Jamf::PeripheralType.all_names(:refresh, cnx: @cnx).include? @type @fields = {} @rest_rsrc = 'peripherals/id/-1' @site = "None" return end @type = @init_data[:general][:type] @site = Jamf::APIObject.get_name(@init_data[:general][:site]) @bar_code_1 = @init_data[:general][:bar_code_1] @bar_code_2 = @init_data[:general][:bar_code_2] @computer_id = @init_data[:general][:computer_id] ### fill in the fields @fields = {} @init_data[:general][:fields].each{|f| @fields[f[:name]] = f[:value] } ### get the field defs for this PeriphType, omitting the leading nil @field_defs ||= Jamf::PeripheralType.fetch(:name => @type).fields.compact end |
Instance Attribute Details
#applecare_id ⇒ String Originally defined in module Purchasable
#bar_code_1 ⇒ String Also known as: barcode_1, barcode1
Returns the “bar code 1” value.
101 102 103 |
# File 'lib/jamf/api/classic/api_objects/peripheral.rb', line 101 def @bar_code_1 end |
#bar_code_2 ⇒ String Also known as: barcode_2, barcode2
Returns the “bar code 2” value.
105 106 107 |
# File 'lib/jamf/api/classic/api_objects/peripheral.rb', line 105 def @bar_code_2 end |
#computer_id ⇒ Integer (readonly)
Returns the id number of the computer to which this periph is connected.
109 110 111 |
# File 'lib/jamf/api/classic/api_objects/peripheral.rb', line 109 def computer_id @computer_id end |
#is_leased ⇒ Boolean Also known as: leased? Originally defined in module Purchasable
#is_purchased ⇒ Boolean Also known as: purchased? Originally defined in module Purchasable
#lease_expires ⇒ Time Originally defined in module Purchasable
#life_expectancy ⇒ Integer Originally defined in module Purchasable
#need_to_update ⇒ Boolean (readonly) Originally defined in module Updatable
Returns do we have unsaved changes?.
#po_date ⇒ Time Originally defined in module Purchasable
#po_number ⇒ String Originally defined in module Purchasable
#purchase_price ⇒ Float Originally defined in module Purchasable
#purchasing_account ⇒ String Originally defined in module Purchasable
#purchasing_contact ⇒ String Originally defined in module Purchasable
#type ⇒ String (readonly)
Returns the type of peripheral.
98 99 100 |
# File 'lib/jamf/api/classic/api_objects/peripheral.rb', line 98 def type @type end |
#vendor ⇒ String Originally defined in module Purchasable
#warranty_expires ⇒ Time Originally defined in module Purchasable
Instance Method Details
#associate(computer) ⇒ void Also known as: assign_to
This method returns an undefined value.
Associate this peripheral with a computer.
230 231 232 233 234 235 236 237 238 239 |
# File 'lib/jamf/api/classic/api_objects/peripheral.rb', line 230 def associate(computer) if computer =~ /^d+$/ raise Jamf::NoSuchItemError, "No computer in the JSS with id #{computer}" unless Jamf::Computer.all_ids(cnx: @cnx).include? computer @computer_id = computer else raise Jamf::NoSuchItemError, "No computer in the JSS with name #{computer}" unless Jamf::Computer.all_names(cnx: @cnx).include? computer @computer_id = Jamf::Computer.map_all_ids_to(:name, cnx: @cnx).invert[computer] end @need_to_update = true end |
#clear_location ⇒ void Originally defined in module Locatable
This method returns an undefined value.
Clear all location data
#clone(new_name, api: nil, cnx: nil) ⇒ APIObject Originally defined in module Creatable
make a clone of this API object, with a new name. The class must be creatable
#create ⇒ Object
reset the restrsrc after creation
159 160 161 162 163 |
# File 'lib/jamf/api/classic/api_objects/peripheral.rb', line 159 def create super @rest_rsrc = "peripherals/id/#{@id}" @id end |
#disassociate ⇒ void Also known as: unassign
This method returns an undefined value.
Disassociate this peripheral from any computer.
This seems to have no effect in the JSS, the computer/user/location data always shows the most recent.
250 251 252 253 |
# File 'lib/jamf/api/classic/api_objects/peripheral.rb', line 250 def disassociate @computer_id = nil @need_to_update = true end |
#fields ⇒ Hash
Returns the field values of the peripheral Each key is the fields name, as a String and the value is the fields value, also as a String.
178 179 180 |
# File 'lib/jamf/api/classic/api_objects/peripheral.rb', line 178 def fields @fields end |
#has_location? ⇒ Boolean Originally defined in module Locatable
Returns Does this item have location data?.
#has_purchasing? ⇒ Boolean Originally defined in module Purchasable
Returns does this item have any purchasing info?.
#location ⇒ Hash<String> Originally defined in module Locatable
All the location 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.
#location_xml ⇒ REXML::Element Originally defined in module Locatable
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.
Return a REXML <location> element to be included in the rest_xml of objects that have a Location subset
#name=(newname) ⇒ Object
periphs don’t have names
168 169 170 |
# File 'lib/jamf/api/classic/api_objects/peripheral.rb', line 168 def name= (newname) raise Jamf::UnsupportedError, "Peripherals don't have names." end |
#parse_location ⇒ void Originally defined in module Locatable
This method returns an undefined value.
Call this during initialization of objects that have a Location subset and the location attributes will be populated (as primary attributes) from @init_data
#parse_purchasing ⇒ Object Originally defined in module Purchasable
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
#purchasing ⇒ Hash<String> Originally defined in module Purchasable
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.
#purchasing_xml ⇒ REXML::Element Originally defined in module Purchasable
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.
#set_field(field, value) ⇒ void
This method returns an undefined value.
Set the value of a field. It will be checked to ensure validity.
191 192 193 194 195 |
# File 'lib/jamf/api/classic/api_objects/peripheral.rb', line 191 def set_field(field, value) check_field(field, value) @fields[field] = value @need_to_update = true end |
#site=(new_site) ⇒ void Originally defined in module Sitable
This method returns an undefined value.
Change the site of this object. Any of the NON_SITES values will unset the site
#site_assigned? ⇒ Boolean Originally defined in module Sitable
Does this object have a site assigned?
#site_id ⇒ Integer Originally defined in module Sitable
The id of the site for this object.
#site_name ⇒ String Also known as: site Originally defined in module Sitable
The name of the site for this object. For backward compatibility, this is aliased to just ‘site’
#site_object ⇒ Jamf::Site Originally defined in module Sitable
The Jamf::Site instance for this object’s site
#unset_site ⇒ void Originally defined in module Sitable
This method returns an undefined value.
Set the site to nothing
#upload(type, local_file, force_ipa_upload: false) ⇒ Boolean Originally defined in module Uploadable
instance method wrapper for class method
Upload a file to the JSS to be stored with this instance of the class mixing in the Uploadable module