Module: Jamf::JPAPIResource

Included in:
CollectionResource
Defined in:
lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

API_SOURCE =

which API do APIObjects come from? The classic equivalent is in Jamf::APIObject

:jamf_pro
NEW_CALLERS =

These methods are allowed to call .new

['fetch', 'create', 'all', 'cached_all', 'block in all', 'block in cached_all'].freeze
RSRC_PREVIEW_VERSION =

The resource version for previewing new features

'preview'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cnxJamf::Connection (readonly)

Returns the API connection thru which we deal with this resource.

Returns:

  • (Jamf::Connection)

    the API connection thru which we deal with this resource.



88
89
90
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 88

def cnx
  @cnx
end

#get_pathString (readonly)

Returns The path for fetching this thing from the JPAPI

this gets set in the constructor in the CollectionResource or SingletonResource mixins.

Returns:

  • (String)

    The path for fetching this thing from the JPAPI

    this gets set in the constructor in the CollectionResource or SingletonResource mixins



94
95
96
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 94

def get_path
  @get_path
end

#update_pathString (readonly)

Returns The path for updating this thing from the JPAPI

this gets set in the constructor in the CollectionResource or SingletonResource mixins

We use ‘update_path’ because some items are updated via a PUT_PATH and others via a PATCH_PATH. When this gets set, it will contain the appropriate one.

Returns:

  • (String)

    The path for updating this thing from the JPAPI

    this gets set in the constructor in the CollectionResource or SingletonResource mixins

    We use ‘update_path’ because some items are updated via a PUT_PATH and others via a PATCH_PATH. When this gets set, it will contain the appropriate one.



104
105
106
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 104

def update_path
  @update_path
end

Class Method Details

.included(includer) ⇒ Object

when this module is included, also extend our Class Methods



34
35
36
37
38
39
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 34

def self.included(includer)
  # TODO: only allow being directly mixed in to CollectionResource and
  # SingletonResource modules.
  Jamf.load_msg "--> #{includer} is including Jamf::JPAPIResource"
  includer.extend(ClassMethods)
end

Instance Method Details

#initialize(**data) ⇒ Object

constructor



109
110
111
112
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 109

def initialize(**data)
  @cnx = data.delete :cnx
  super(**data)
end

#pretty_print_instance_variablesArray

Remove large cached items from the instance_variables used to create pretty-print (pp) output.

Returns:

  • (Array)

    the desired instance_variables



123
124
125
126
127
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 123

def pretty_print_instance_variables
  vars = super.sort
  vars.delete :@cnx
  vars
end

#saveObject

TODO: error handling



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 130

def save
  raise Jamf::UnsupportedError, "#{self.class} objects cannot be changed" unless self.class.mutable?

  if exist?
    return unless unsaved_changes?

    update_in_jamf
  else
    create_in_jamf
  end

  clear_unsaved_changes

  @id || :saved
end