Class: JSS::Peripheral

Inherits:
APIObject show all
Includes:
Creatable, Locatable, Purchasable, Sitable, Updatable, Uploadable
Defined in:
lib/jss/api_object/peripheral.rb,
lib/jss.rb

Overview

A peripheral in the JSS

See Also:

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 ]
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

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Peripheral

Returns a new instance of Peripheral

See Also:


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_object/peripheral.rb', line 121

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, api: @api).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.fetch(:name => @type).fields.compact


end

Instance Attribute Details

#applecare_idString Originally defined in module Purchasable

Returns:

#bar_code_1String Also known as: barcode_1, barcode1

Returns the “bar code 1” value

Returns:

  • (String)

    the “bar code 1” value


104
105
106
# File 'lib/jss/api_object/peripheral.rb', line 104

def bar_code_1
  @bar_code_1
end

#bar_code_2String Also known as: barcode_2, barcode2

Returns the “bar code 2” value

Returns:

  • (String)

    the “bar code 2” value


108
109
110
# File 'lib/jss/api_object/peripheral.rb', line 108

def bar_code_2
  @bar_code_2
end

#buildingString Originally defined in module Locatable

Returns:

#computer_idInteger (readonly)

Returns the id number of the computer to which this periph is connected

Returns:

  • (Integer)

    the id number of the computer to which this periph is connected


112
113
114
# File 'lib/jss/api_object/peripheral.rb', line 112

def computer_id
  @computer_id
end

#departmentString Originally defined in module Locatable

Returns:

#email_addressString Originally defined in module Locatable

Returns:

#is_leasedBoolean Also known as: leased? Originally defined in module Purchasable

Returns:

  • (Boolean)

#is_purchasedBoolean Also known as: purchased? Originally defined in module Purchasable

Returns:

  • (Boolean)

#lease_expiresTime Originally defined in module Purchasable

Returns:

#life_expectancyInteger Originally defined in module Purchasable

Returns:

  • (Integer)

#need_to_updateBoolean (readonly) Originally defined in module Updatable

Returns do we have unsaved changes?

Returns:

  • (Boolean)

    do we have unsaved changes?

#phoneString Originally defined in module Locatable

Returns:

#po_dateTime Originally defined in module Purchasable

Returns:

#po_numberString Originally defined in module Purchasable

Returns:

#positionString Originally defined in module Locatable

Returns:

#purchase_priceFloat Originally defined in module Purchasable

Returns:

  • (Float)

#purchasing_accountString Originally defined in module Purchasable

Returns:

#purchasing_contactString Originally defined in module Purchasable

Returns:

#real_nameString Originally defined in module Locatable

Returns:

#roomString Originally defined in module Locatable

Returns:

#typeString (readonly)

Returns the type of peripheral

Returns:

  • (String)

    the type of peripheral


101
102
103
# File 'lib/jss/api_object/peripheral.rb', line 101

def type
  @type
end

#usernameString Also known as: user Originally defined in module Locatable

Returns:

#vendorString Originally defined in module Purchasable

Returns:

#warranty_expiresTime Originally defined in module Purchasable

Returns:

Instance Method Details

#associate(computer) ⇒ void Also known as: assign_to

This method returns an undefined value.

Associate this peripheral with a computer.

Parameters:

  • computer (String, Integer)

    the name or id of a computer in the JSS


233
234
235
236
237
238
239
240
241
242
# File 'lib/jss/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(api: @api).include? computer
    @computer_id = computer
  else
    raise JSS::NoSuchItemError, "No computer in the JSS with name #{computer}" unless JSS::Computer.all_names(api: @api).include? computer
    @computer_id = JSS::Computer.map_all_ids_to(:name, api: @api).invert[computer]
  end
  @need_to_update = true
end

#clear_locationvoid Originally defined in module Locatable

This method returns an undefined value.

Clear all location data

#clone(new_name, api: nil) ⇒ APIObject Originally defined in module Creatable

make a clone of this API object, with a new name. The class must be creatable

Parameters:

  • name (String)

    the name for the new object

  • api (JSS::APIConnection)

    the API in which to create the object Defaults to the API used to instantiate this object

Returns:

  • (APIObject)

    An uncreated clone of this APIObject with the given name

Raises:

#createObject

reset the restrsrc after creation

See Also:


162
163
164
165
166
# File 'lib/jss/api_object/peripheral.rb', line 162

def create
  super
  @rest_rsrc = "peripherals/id/#{@id}"
  @id
end

#disassociatevoid 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_object/peripheral.rb', line 253

def disassociate
  @computer_id = nil
  @need_to_update = true
end

#fieldsHash

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

Returns:

  • (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


181
182
183
# File 'lib/jss/api_object/peripheral.rb', line 181

def fields
  @fields
end

#has_location?Boolean Originally defined in module Locatable

Returns Does this item have location data?

Returns:

  • (Boolean)

    Does this item have location data?

#has_purchasing?Boolean Originally defined in module Purchasable

Returns does this item have any purchasing info?

Returns:

  • (Boolean)

    does this item have any purchasing info?

#locationHash<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.

Returns:

#location_xmlREXML::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

Returns:

  • (REXML::Element)

#name=(newname) ⇒ Object

periphs don't have names


171
172
173
# File 'lib/jss/api_object/peripheral.rb', line 171

def name= (newname)
  raise JSS::UnsupportedError, "Peripherals don't have names."
end

#parse_locationvoid 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_purchasingObject 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

#purchasingHash<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.

Returns:

#purchasing_xmlREXML::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.

Returns:

  • (REXML::Element)

    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.

Parameters:

  • field (String)

    the field to set

  • value (String)

    the new value for the field


194
195
196
197
198
# File 'lib/jss/api_object/peripheral.rb', line 194

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

Parameters:

  • new_site (Integer, String)

    The new site

Raises:

#site_assigned?Boolean Originally defined in module Sitable

Does this object have a site assigned?

Returns:

  • (Boolean)

    Does this object have a site assigned?

#site_idInteger Originally defined in module Sitable

The id of the site for this object.

Returns:

  • (Integer)

    The id of the site for this object.

#site_nameString 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'

Returns:

  • (String)

    The name of the site for this object.

#site_objectJSS::Site Originally defined in module Sitable

The JSS::Site instance for this object's site

Returns:

  • (JSS::Site)

    The JSS::Site instance for this object's site

#unset_sitevoid Originally defined in module Sitable

This method returns an undefined value.

Set the site to nothing

#updateBoolean Originally defined in module Updatable

Save changes to the JSS

Returns:

  • (Boolean)

    success

Raises:

#upload(type, local_file) ⇒ String Originally defined in module Uploadable

Upload a file to the JSS via the REST Resource of the object to which this module is mixed in.

Parameters:

  • type (Symbol)

    the type of upload happening. Must be one of the keys defined in the class's UPLOAD_TYPES Hash.

  • local_file (String, Pathname)

    String or Pathname pointing to the locally-readable file to be uploaded.

Returns:

  • (String)

    The xml response from the server.

Raises: