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',
  'block in page'
].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.



84
85
86
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 84

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



90
91
92
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 90

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.



100
101
102
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 100

def update_path
  @update_path
end

Class Method Details

.included(includer) ⇒ Object

when this module is included, also extend our Class Methods



16
17
18
19
20
21
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 16

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



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

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



118
119
120
121
122
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 118

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

#saveObject

TODO: error handling



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/jamf/api/jamf_pro/mixins/jpapi_resource.rb', line 125

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