Class: JSS::Peripheral
- Includes:
- Creatable, Locatable, Purchasable, Updatable, Uploadable
- Defined in:
- lib/jss-api/api_object/peripheral.rb,
lib/jss-api.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- VALID_DATA_KEYS =
these keys, as well as :id and :name, are present in valid API JSON data for this class
[:type, :bar_code_1, :computer_id ]
Constants included from Uploadable
Uploadable::UPLOAD_RSRC_PREFIX
Constants included from Locatable
Constants included from Purchasable
JSS::Purchasable::PURCHASABLE, JSS::Purchasable::SUBSET_PURCH
Constants included from Updatable
Constants included from Creatable
Constants inherited from APIObject
APIObject::DEFAULT_LOOKUP_KEYS, APIObject::REQUIRED_DATA_KEYS
Instance Attribute Summary collapse
-
#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.
-
#computer_id ⇒ Integer
readonly
The id number of the computer to which this periph is connected.
-
#type ⇒ String
readonly
The type of peripheral.
Attributes included from Locatable
#building, #department, #email_address, #phone, #position, #real_name, #room, #username
Attributes included from Purchasable
#applecare_id, #is_leased, #is_purchased, #lease_expires, #life_expectancy, #po_date, #po_number, #purchase_price, #purchasing_account, #purchasing_contact, #vendor, #warranty_expires
Attributes included from Updatable
Attributes inherited from APIObject
#id, #in_jss, #name, #rest_rsrc
Instance Method Summary collapse
-
#associate(computer) ⇒ void
(also: #assign_to)
Associate this peripheral with a computer.
-
#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.
-
#initialize(args = {}) ⇒ Peripheral
constructor
A new instance of Peripheral.
-
#name=(newname) ⇒ Object
periphs don’t have names.
-
#set_field(field, value) ⇒ void
Set the value of a field.
Methods included from Uploadable
Methods included from Locatable
#has_location?, #location, #location_xml, #parse_location
Methods included from Purchasable
#has_purchasing?, #parse_purchasing, #purchasing, #purchasing_xml
Methods included from Updatable
Methods inherited from APIObject
all, all_ids, all_names, #delete, get_name, map_all_ids_to, #save, xml_list
Constructor Details
#initialize(args = {}) ⇒ Peripheral
Returns a new instance of Peripheral.
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 152 153 154 |
# File 'lib/jss-api/api_object/peripheral.rb', line 119 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 JSS::InvalidDataError, "New Peripherals must have a :type, which must be one of those defined in the JSS." unless args[:type] @type = args[:type] raise JSS::InvalidDataError, "No peripheral type '#{@type}' in the JSS" unless JSS::PeripheralType.all_names(:refresh).include? @type @fields = {} @rest_rsrc = 'peripherals/id/-1' @site = "None" return end @type = @init_data[:general][:type] @site = JSS::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 ||= JSS::PeripheralType.new(:name => @type).fields.compact parse_location parse_purchasing end |
Instance Attribute Details
#bar_code_1 ⇒ String Also known as: barcode_1, barcode1
Returns the “bar code 1” value.
102 103 104 |
# File 'lib/jss-api/api_object/peripheral.rb', line 102 def @bar_code_1 end |
#bar_code_2 ⇒ String Also known as: barcode_2, barcode2
Returns the “bar code 2” value.
106 107 108 |
# File 'lib/jss-api/api_object/peripheral.rb', line 106 def @bar_code_2 end |
#computer_id ⇒ Integer (readonly)
Returns the id number of the computer to which this periph is connected.
110 111 112 |
# File 'lib/jss-api/api_object/peripheral.rb', line 110 def computer_id @computer_id end |
#type ⇒ String (readonly)
Returns the type of peripheral.
99 100 101 |
# File 'lib/jss-api/api_object/peripheral.rb', line 99 def type @type end |
Instance Method Details
#associate(computer) ⇒ void Also known as: assign_to
This method returns an undefined value.
Associate this peripheral with a computer.
233 234 235 236 237 238 239 240 241 242 |
# File 'lib/jss-api/api_object/peripheral.rb', line 233 def associate(computer) if computer =~ /^d+$/ raise JSS::NoSuchItemError, "No computer in the JSS with id #{computer}" unless JSS::Computer.all_ids.include? computer @computer_id = computer else raise JSS::NoSuchItemError, "No computer in the JSS with name #{computer}" unless JSS::Computer.all_names.include? computer @computer_id = JSS::Computer.map_all_ids_to(:name).invert[computer] end @need_to_update = true end |
#create ⇒ Object
reset the restrsrc after creation
162 163 164 165 166 |
# File 'lib/jss-api/api_object/peripheral.rb', line 162 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.
253 254 255 256 |
# File 'lib/jss-api/api_object/peripheral.rb', line 253 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.
181 182 183 |
# File 'lib/jss-api/api_object/peripheral.rb', line 181 def fields @fields end |
#name=(newname) ⇒ Object
periphs don’t have names
171 172 173 |
# File 'lib/jss-api/api_object/peripheral.rb', line 171 def name= (newname) raise JSS::UnsupportedError, "Peripherals don't have names." end |
#set_field(field, value) ⇒ void
This method returns an undefined value.
Set the value of a field. It will be checked to ensure validity.
194 195 196 197 198 |
# File 'lib/jss-api/api_object/peripheral.rb', line 194 def set_field(field, value) check_field(field, value) @fields[field] = value @need_to_update = true end |