Help on adding an /api route to my foreman plugin

Hi All,
I've been working on getting my foreman plugin, cert_reaper, finished and
have been asked to add a single API route to allow callers to clear puppet
certificates based on certificate name.

The source for my plugin can be found at:

<goog_557621292>

https://github.com/dscoular/cert-reaper/

I was thinking that this should just utilise an HTTP DELETE method, the
path to the API's route and a puppet certificate name e.g.

DELETE /api/v2/certs/theagent.example.com

I had hoped this would just entail adding a line to my plugin's
config/routes.rb file and implementing the action in an api controller,
however it seems a bit more complex than that.

I've tried to strip back to as basic as possible just to see if I could get
something to fire my API action but I'm getting nowhere.

Could someone please give me a nudge in the right direction?

Here are my existing routes:

config/routes.rb

Rails.application.routes.draw do
get 'clear_cert', to: 'cert_reaper/hosts#clear_cert'
get 'multiple_clear_cert', to: 'cert_reaper/hosts#multiple_clear_cert'
post 'submit_multiple_clear_cert',
delete 'certs', to: 'cert_reaper/api/v2/certs#destroy'
end

The "delete" line just ignores the /api/… path and certname parameter I
had wanted and tries to make "DELETE /certs" fire my destroy() method,
which I've implemented in the following:

app/controllers/api/v2/certs_controller.rb

module Api
module v2
class CertsController < ::Api::v2::BaseController

  resource_description do
    resource_id &#39;certs&#39;
    api_version &#39;v2&#39;
    api_base_url &#39;/api&#39;
  end

  api :DELETE, &#39;/certs/:certname/&#39;, _(&#39;Clear a puppet certificate.&#39;)
  param :certname, :required =&gt; true, String, desc: &#39;Full name of the 

user'

  def destroy
    render :json =&gt; { :error =&gt; _(&#39;Destroy got called with 

"#{params['certname']}".' }, :status => :precondition_failed
end
end
end
end

However when I try to make an HTTP DELETE request against /certs/ using
postman I get the following error:

Routing Error
uninitialized constant CertReaper::Api

Rails.root: /home/vagrant/foreman

My guess is that my route's action module isn't being loaded or recognised.

Obviously I'm pretty confused (I'm a ruby/rails/foreman newbie), so any
kind words of wisdom nudging me in the right direction would be hugely
appreciated.

Cheers,

Doug

··· to: 'cert_reaper/hosts#submit_multiple_clear_cert'