Module: Legion::API::Routes::ExtensionCatalog

Defined in:
lib/legion/api/catalog.rb

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/legion/api/catalog.rb', line 7

def self.registered(app)
  app.get '/api/catalog' do
    entries = Legion::Extensions::Catalog.all.map do |name, entry|
      build_catalog_manifest(name, entry)
    end
    json_response(entries)
  end

  app.get '/api/catalog/:name' do
    name = params[:name]
    entry = Legion::Extensions::Catalog.entry(name)
    unless entry
      halt 404, { 'Content-Type' => 'application/json' },
           Legion::JSON.dump({ error: { code: 'not_found', message: "Extension #{name} not found" } })
    end

    json_response(build_catalog_manifest(name, entry))
  end
end