summaryrefslogtreecommitdiff
path: root/lib/api/runners.rb
blob: ef78b09e2963519ce6ecf6302bd681c32ab22a6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module API
  # Runners API
  class Runners < Grape::API
    resource :runners do
      # Get list of all available runners
      #
      # Example Request:
      #   GET /runners
      get do
        authenticate!
        runners = Runner.all

        if runners.present?
          present runners, with: Entities::Runner
        else
          not_found!
        end
      end

      # Register a new runner
      #
      # Note: This is an "internal" API called when setting up
      # runners, so it is authenticated differently.
      #
      # Parameters:
      #   token (required) - The unique token of runner
      #
      # Example Request:
      #   POST /runners/register
      post "register" do
        authenticate_runners!
        required_attributes! [:token]

        runner = Runner.create

        if runner.id
          present runner, with: Entities::Runner
        else
          not_found!
        end
      end
    end
  end
end