class SimpleMDM::AppGroup

Public Class Methods

all() click to toggle source
# File lib/simplemdm/app_group.rb, line 10
def self.all
  hash, code = fetch("app_groups")

  hash['data'].collect { |d| build d }
end
find(id) click to toggle source
# File lib/simplemdm/app_group.rb, line 16
def self.find(id)
  hash, code = fetch("app_groups/#{id}")

  build hash['data']
end

Public Instance Methods

add_app(app) click to toggle source
# File lib/simplemdm/app_group.rb, line 67
def add_app(app)
  raise "You must save this app group before changing associations" if new?
  raise "The object you provided is not an app" unless app.kind_of?(SimpleMDM::App)
  raise "You must save the app before associating it" if app.id.nil?

  hash, code = fetch("app_groups/#{self.id}/apps/#{app.id}", :post)

  if code == 204
    self['app_ids'] = self['app_ids'] | [app.id]
    true
  else
    false
  end
end
add_device(device) click to toggle source
# File lib/simplemdm/app_group.rb, line 127
def add_device(device)
  raise "You must save this app group before changing associations." if new?
  raise "The object you provided is not a device" unless device.kind_of?(SimpleMDM::Device)
  raise "You must save the device before associating it" if device.id.nil?

  hash, code = fetch("app_groups/#{self.id}/devices/#{device.id}", :post)

  if code == 204
    self['device_ids'] = self['device_ids'] | [device.id]
    true
  else
    false
  end
end
add_device_group(device_group) click to toggle source
# File lib/simplemdm/app_group.rb, line 97
def add_device_group(device_group)
  raise "You must save this app group before changing associations." if new?
  raise "The object you provided is not a device group" unless device_group.kind_of?(SimpleMDM::DeviceGroup)
  raise "You must save the device_group before associating it" if device_group.id.nil?

  hash, code = fetch("app_groups/#{self.id}/device_groups/#{device_group.id}", :post)

  if code == 204
    self['device_group_ids'] = self['device_group_ids'] | [device_group.id]
    true
  else
    false
  end
end
auto_deploy=(val) click to toggle source
# File lib/simplemdm/app_group.rb, line 51
def auto_deploy=(val)
  if val != self.auto_deploy
    @dirty = true
  end

  self['auto_deploy'] = val
end
build(hash = nil) click to toggle source
Calls superclass method
# File lib/simplemdm/app_group.rb, line 4
def build(hash = nil)
  @dirty = false

  super
end
destroy() click to toggle source
# File lib/simplemdm/app_group.rb, line 59
def destroy
  raise "You cannot delete an app group that hasn't been created yet" if new?

  hash, code = fetch("app_groups/#{self.id}", :delete)

  code == 204
end
name=(val) click to toggle source
# File lib/simplemdm/app_group.rb, line 43
def name=(val)
  if val != self.name
    @dirty = true
  end

  self['name'] = val
end
push_apps() click to toggle source
# File lib/simplemdm/app_group.rb, line 157
def push_apps
  raise "You cannot push apps for an app group that hasn't been created yet" if new?

  hash, code = fetch("app_groups/#{self.id}/push_apps", :post)

  code == 202
end
remove_app(app) click to toggle source
# File lib/simplemdm/app_group.rb, line 82
def remove_app(app)
  raise "You must save this app group before changing associations." if new?
  raise "The object you provided is not an app" unless app.kind_of?(SimpleMDM::App)
  raise "The app you provided doesn't exist" if app.id.nil?

  hash, code = fetch("app_groups/#{self.id}/apps/#{app.id}", :delete)

  if code == 204
    self['app_ids'].delete(app.id)
    true
  else
    false
  end
end
remove_device(device) click to toggle source
# File lib/simplemdm/app_group.rb, line 142
def remove_device(device)
  raise "You must save this app group before changing associations" if new?
  raise "The object you provided is not a device" unless device.kind_of?(SimpleMDM::Device)
  raise "The device you provided doesn't exist" if device.id.nil?

  hash, code = fetch("app_groups/#{self.id}/devices/#{device.id}", :delete)

  if code == 204
    self['device_ids'].delete(device.id)
    true
  else
    false
  end
end
remove_device_group(device_group) click to toggle source
# File lib/simplemdm/app_group.rb, line 112
def remove_device_group(device_group)
  raise "You must save this app group before changing associations" if new?
  raise "The object you provided is not a device group" unless device_group.kind_of?(SimpleMDM::DeviceGroup)
  raise "The device group you provided doesn't exist" if device_group.id.nil?

  hash, code = fetch("app_groups/#{self.id}/device_groups/#{device_group.id}", :delete)

  if code == 204
    self['device_group_ids'].delete(device_group.id)
    true
  else
    false
  end
end
save() click to toggle source
# File lib/simplemdm/app_group.rb, line 22
def save
  if @dirty || new?
    params = {}
    params[:name]        = self.name unless self.name.nil?
    params[:auto_deploy] = self.auto_deploy unless self.auto_deploy.nil?

    if new?
      hash, code = fetch("app_groups", :post, params)

      self.id = hash['data']['id']
      self.merge!(hash['data']['attributes'])
    else
      fetch("app_groups/#{self.id}", :patch, params)
    end

    @dirty = false
  end

  self
end