Class: Mdm::CommandsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/mdm/commands_controller.rb', line 17

def create
  @commands = create_commands(devices)
  @commands.each { |command|
    command.device.notify
  }
  render json: @commands
rescue NoMethodError
  render json: { error: 'wrong command' }, status: :bad_request
rescue ArgumentError
  render json: { error: 'bad arguments' }, status: :bad_request
rescue ActiveRecord::RecordNotFound
  render nothing: true, status: :not_found
end

#indexObject



6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/mdm/commands_controller.rb', line 6

def index
  render json: { commands: case params[:filter]
                           when 'completed'
                             Command.completed
                           when 'pending'
                             Command.pending
                           else
                            Command.all
                           end }
end