Method: Jamf::APIObject.get_name
- Defined in:
- lib/jamf/api/classic/base_classes/api_object.rb
.get_name(a_thing) ⇒ String
Some API objects contain references to other API objects. Usually those references are a Hash containing the :id and :name of the target. Sometimes, however the reference is just the name of the target.
A Script has a property :category, which comes from the API as a String, the name of the category for that script. e.g. “GoodStuff”
A Policy also has a property :category, but it comes from the API as a Hash with both the name and id, e.g. {:id => 8, :name => “GoodStuff”}
When that reference is to a single thing (like the category to which something belongs) APIObject subclasses usually store only the name, and use the name when returning data to the API.
When an object references a list of related objects (like the computers assigned to a user) that list will be and Array of Hashes as above, with both the :id and :name
This method is just a handy way to extract the name regardless of how it comes from the API. Most APIObject subclasses use it in their #initialize method
908 909 910 911 912 913 914 915 916 917 |
# File 'lib/jamf/api/classic/base_classes/api_object.rb', line 908 def self.get_name(a_thing) case a_thing when String a_thing when Hash a_thing[:name] when nil nil end end |