Class: Angarium::Api::EndpointsController

Inherits:
BaseController show all
Defined in:
app/controllers/angarium/api/endpoints_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#angarium_current_user

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/angarium/api/endpoints_controller.rb', line 16

def create
  # The owner comes from the policy's #owner (default: current_user), set
  # before authorize! so policy #create? can gate the target owner.
  endpoint = Angarium::Endpoint.new(endpoint_params)
  endpoint.owner = angarium_policy.owner
  endpoint.status = :unverified if angarium_policy.create_unverified?
  authorize!(endpoint)
  endpoint.save!
  # The signing secret is revealed once, on creation.
  render json: {endpoint: endpoint_json(endpoint, include_secret: true)}, status: :created
end

#destroyObject



34
35
36
37
38
# File 'app/controllers/angarium/api/endpoints_controller.rb', line 34

def destroy
  authorize!(@endpoint)
  @endpoint.destroy!
  head :no_content
end

#enableObject



52
53
54
55
56
# File 'app/controllers/angarium/api/endpoints_controller.rb', line 52

def enable
  authorize!(@endpoint)
  @endpoint.enable!
  render json: {endpoint: endpoint_json(@endpoint)}
end

#indexObject



6
7
8
9
# File 'app/controllers/angarium/api/endpoints_controller.rb', line 6

def index
  authorize!
  render_collection(:endpoints, endpoint_scope.order(created_at: :desc)) { |e| endpoint_json(e) }
end

#pauseObject



46
47
48
49
50
# File 'app/controllers/angarium/api/endpoints_controller.rb', line 46

def pause
  authorize!(@endpoint)
  @endpoint.pause!
  render json: {endpoint: endpoint_json(@endpoint)}
end

#pingObject



64
65
66
67
68
# File 'app/controllers/angarium/api/endpoints_controller.rb', line 64

def ping
  authorize!(@endpoint)
  delivery = @endpoint.ping!
  render json: {delivery: delivery_json(delivery)}, status: :accepted
end

#rotate_secretObject



40
41
42
43
44
# File 'app/controllers/angarium/api/endpoints_controller.rb', line 40

def rotate_secret
  authorize!(@endpoint)
  secret = @endpoint.rotate_secret!
  render json: {endpoint: endpoint_json(@endpoint), signing_secret: secret}
end

#showObject



11
12
13
14
# File 'app/controllers/angarium/api/endpoints_controller.rb', line 11

def show
  authorize!(@endpoint)
  render json: {endpoint: endpoint_json(@endpoint)}
end

#updateObject



28
29
30
31
32
# File 'app/controllers/angarium/api/endpoints_controller.rb', line 28

def update
  authorize!(@endpoint)
  @endpoint.update!(endpoint_params)
  render json: {endpoint: endpoint_json(@endpoint)}
end

#verifyObject



58
59
60
61
62
# File 'app/controllers/angarium/api/endpoints_controller.rb', line 58

def verify
  authorize!(@endpoint)
  @endpoint.verify!
  render json: {endpoint: endpoint_json(@endpoint)}
end