class Jamf::Icon

An Icon in the JSS, used in Self Service.

At the moment, icons are not API objects, they are collections of data stored in the JSS that might be included in some API object’s Self Service data.

The data available for an icon are:

Icon instances are read-only. To change the icon for a self-servable object, see {SelfServable#icon=}.

NOTE: Since icons are not APIObjects, there’s no way to see a list of them via the API. The Jamf::Icon class methods .all, .all_ids, and .all_names require MySQL database access. See {Jamf::DBConnection}.

This also means, if you use multiple API connections, you’ll have to make sure to connect to the correct MySQL server for the APIConnection you care about.

Attributes

data[R]

@return [String] The raw icon file.

filename[R]

@return [String] the icon’s name in the JSS

NOTE: these are not unique
id[R]

@return [Integer] the icon’s id in the JSS

name[R]

@return [String] the icon’s name in the JSS

NOTE: these are not unique
uri[R]

@return [String] The URI for downloading or previewing the icon from the JSS

Public Class Methods

all(refresh = false) click to toggle source

Return an Array of { id:, name: } Hashes for all icons known to the JSS Since Icon lists aren’t accessible via the API, this method must query the SQL database directly, and will raise an exception if you aren’t connected to the database.

@param refresh re-read the data from the server?

@return [Array<Hash>] The names and ids of all icons known to the JSS

   # File lib/jamf/api/classic/api_objects/icon.rb
67 def self.all(refresh = false)
68   @all_icons = nil if refresh
69   return @all_icons if @all_icons
70   @all_icons = []
71   qry = 'SELECT icon_id, filename FROM icons'
72   res = Jamf::DB_CNX.db.query qry
73   res.each_hash { |icon| @all_icons << { id: icon['icon_id'].to_i, name: icon['filename'] } }
74   @all_icons
75 end
all_ids(refresh = false) click to toggle source

An Array of all icon ids known to the JSS. See {Icon.all}.

@param refresh re-read the data from the server?

@return [Array<Integer>] The ids of all icons known to the JSS

   # File lib/jamf/api/classic/api_objects/icon.rb
84 def self.all_ids(refresh = false)
85   all(refresh).map { |i| i[:id] }
86 end
all_names(refresh = false) click to toggle source

An Array of all icon names known to the JSS. See {Icon.all}. NOTE: Icon names are not unique

@param refresh re-read the data from the server?

@return [Array<Integer>] The names of all icons known to the JSS

   # File lib/jamf/api/classic/api_objects/icon.rb
96 def self.all_names(refresh = false)
97   all(refresh).map { |i| i[:name] }
98 end
new(icon_data) click to toggle source

Set up a new Jamf::Icon instance

@param icon_data The :self_service_icon Hash from the :self_service

Hash of an object's API @init_data

@return [Jamf::Icon] The new object

    # File lib/jamf/api/classic/api_objects/icon.rb
128 def initialize(icon_data)
129   return unless icon_data.is_a? Hash
130   @id = icon_data[:id]
131   @name = icon_data[:filename]
132   @uri = icon_data[:uri]
133   @data = icon_data[:data]
134 
135   # if no :filename, its called :name
136   @name ||= icon_data[:name]
137 
138   # if there's no id, as with MobileDeviceConfigurationProfile
139   # get it from the end of the uri if possible
140   if @uri && !@id
141     @id = Regexp.last_match(1).to_i if @uri =~ /(\d+)$/
142   end
143 
144   # decode the icon data, or grab from
145   # the URI if needed
146   @data = Base64.decode64(@data) if @data
147   begin
148     @data ||= URI.parse(@uri).read if @uri
149   rescue
150     @data = nil
151   end
152 
153 end

Public Instance Methods

pretty_print_instance_variables() click to toggle source

Remove the data object from the instance_variables used to create pretty-print (pp) output.

@return [Array] the desired instance_variables

    # File lib/jamf/api/classic/api_objects/icon.rb
192 def pretty_print_instance_variables
193   vars = instance_variables.sort
194   vars.delete :@data
195   vars
196 end
save(path, overwrite = false) click to toggle source

Save the icon to a file.

@param path[Pathname, String] The path to which the file should be saved. If the path given is an existing directory, the icon’s current filename will be used, if known.

@param overwrite Overwrite the file if it exists? Defaults to false

@return [void]

    # File lib/jamf/api/classic/api_objects/icon.rb
177 def save(path, overwrite = false)
178   path = Pathname.new path
179   path = path + @name if path.directory? && @name
180 
181   raise Jamf::AlreadyExistsError, "The file #{path} already exists" if path.exist? unless overwrite
182   path.delete if path.exist?
183   path.jss_save @data
184 end
show_in_browser() click to toggle source

Open the icon’s URL in the current user’s browser

@return [void]

    # File lib/jamf/api/classic/api_objects/icon.rb
162 def show_in_browser
163   return nil unless @uri
164   system "/usr/bin/open '#{@uri}'"
165 end