Class: Mdm::ServerController

Inherits:
ApplicationController show all
Defined in:
app/controllers/mdm/server_controller.rb

Instance Method Summary collapse

Instance Method Details

#serverObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/mdm/server_controller.rb', line 4

def server
  # Device is waiting for command
  if params[:Status] == Command::Status::IDLE
    return render nothing: true if device.commands.pending.empty?
    return render text: device.commands.pending.first.payload
  end

  # Device is updating command
  command.update(status: params[:Status])

  if command.complete?
    payload = Plist::parse_xml(command.payload).with_indifferent_access
    # Use data from `DeviceInformation` request to update the device locally
    if payload[:Command][:RequestType] == 'DeviceInformation'
      device.refresh!(params[:QueryResponses])
    end
  end
  
  render nothing: true
end