Class: WitchDoctor::VirusScansController

Inherits:
ApplicationController show all
Defined in:
app/controllers/witch_doctor/virus_scans_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/witch_doctor/virus_scans_controller.rb', line 9

def index
  authenticate! do
    @virus_scans = VirusScan
      .not_scanned
      .limit(WitchDoctor.virus_scan_limit)


    respond_to do |format|
      format.json do
        render WitchDoctor.controller_object_hash_generator.call(@virus_scans)
      end
      format.html do
        json_406 = { title: "Not Acceptable",
                     detail: 'needs to be JSON request',
                     status: '406' }
        render json: { errors: [json_406] }, status: 406
      end
    end
  end
end

#updateObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/witch_doctor/virus_scans_controller.rb', line 30

def update
  authenticate! do
    respond_to do |format|
      format.json do
        begin
          @virus_scan = VirusScan.where(scan_result: nil).find params[:id]
          @virus_scan.update_attributes virus_scan_params# as: :scan_update
          if @virus_scan.errors.any?
            json_400 = { title: "Bad Request",
                         detail: @virus_scan.errors.first.join(' '),
                         status: '400' }
            render json: { errors: [json_400] }, status: 400
          else
            render WitchDoctor.controller_object_hash_generator.call(@virus_scan.reload)
          end
        rescue ActionController::ParameterMissing => e
          json_406 = { title: "Not Acceptable",
                       detail: e.to_s,
                       status: '406' }
          render json: { errors: [json_406] }, status: 406
        rescue ActiveRecord::RecordNotFound => e
          json_404 = { title: "Not Found",
                       detail: 'Record not found or already scanned',
                       status:'404' }
          render json: { errors: [json_404] }, status: 404
        end
      end
      format.html do
        err_json = { title: 'Not Acceptable',
                     detail: 'needs to be JSON request',
                     status: '406' }
        render json: { errors: [err_json] }, status: 406
      end
    end
  end
end