From f02150468b3f3798463d3983eeb6de13cfab9a26 Mon Sep 17 00:00:00 2001 From: Surinna Curtis Date: Sat, 23 Sep 2017 20:50:46 +0000 Subject: [PATCH] Expose an /api/v1/extensions endpoint. We don't have any extensions listed or link this in the "endpoints" field on actors yet. The endpoint also doesn't currently provide a way to expose any additional metadata about an extension beyond its URL (in part because the SWICG proposal currently doesn't include that). We can add extensions to the endpoint's response by calling Mastodon::Extension::register with the extension URL. --- app/controllers/api/v1/extensions_controller.rb | 8 ++++++++ config/routes.rb | 2 ++ lib/mastodon/extensions.rb | 17 +++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 app/controllers/api/v1/extensions_controller.rb create mode 100644 lib/mastodon/extensions.rb diff --git a/app/controllers/api/v1/extensions_controller.rb b/app/controllers/api/v1/extensions_controller.rb new file mode 100644 index 0000000000..15e57f945b --- /dev/null +++ b/app/controllers/api/v1/extensions_controller.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true +require 'mastodon/extension' + +class Api::V1::ExtensionsController < Api::BaseController + def index + render json: Mastodon::Extension.all + end +end diff --git a/config/routes.rb b/config/routes.rb index dc93fc6fe6..c0a1fccf0b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -238,6 +238,8 @@ Rails.application.routes.draw do post :unmute end end + + resources :extensions, only: :list end namespace :web do diff --git a/lib/mastodon/extensions.rb b/lib/mastodon/extensions.rb new file mode 100644 index 0000000000..974c8286ba --- /dev/null +++ b/lib/mastodon/extensions.rb @@ -0,0 +1,17 @@ +class Mastodon::Extension + @@extensions = [] + + def self.register url + @extensions << Extension.new(url) + end + + def self.all + @extensions + end + + def initialize url + @url = url + end + + attr_reader :url +end