From 620f70e42c16c324459ca2da52c68f1def8683de Mon Sep 17 00:00:00 2001 From: Kibigo Date: Mon, 27 Feb 2017 04:06:25 -0800 Subject: [PATCH 1/2] Adds site metadata access to the API --- app/controllers/api/v1/site_controller.rb | 8 ++++++++ app/views/api/v1/site/index.rabl | 14 ++++++++++++++ config/routes.rb | 1 + docs/Using-the-API/API.md | 8 ++++++++ 4 files changed, 31 insertions(+) create mode 100644 app/controllers/api/v1/site_controller.rb create mode 100644 app/views/api/v1/site/index.rabl diff --git a/app/controllers/api/v1/site_controller.rb b/app/controllers/api/v1/site_controller.rb new file mode 100644 index 000000000..64ca2dec1 --- /dev/null +++ b/app/controllers/api/v1/site_controller.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class Api::V1::SiteController < ApiController + respond_to :json + + def index + end +end diff --git a/app/views/api/v1/site/index.rabl b/app/views/api/v1/site/index.rabl new file mode 100644 index 000000000..09f78560b --- /dev/null +++ b/app/views/api/v1/site/index.rabl @@ -0,0 +1,14 @@ +object false + +node(:title) {Setting.site_title} + +node(:max_chars) {500} + +node(:links) do + { + t('about.learn_more') => url_for(about_more_url), + t('about.terms') => url_for(terms_url), + t('about.source_code') => "https://github.com/tootsuite/mastodon", + t('about.other_instances') => "https://github.com/tootsuite/mastodon/blob/master/docs/Using-Mastodon/List-of-Mastodon-instances.md", + } +end diff --git a/config/routes.rb b/config/routes.rb index 870d8afd4..4595b4ba3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -129,6 +129,7 @@ Rails.application.routes.draw do resources :blocks, only: [:index] resources :favourites, only: [:index] resources :reports, only: [:index, :create] + resources :site, only: [:index] resources :follow_requests, only: [:index] do member do diff --git a/docs/Using-the-API/API.md b/docs/Using-the-API/API.md index 07c1b25a9..8dcf2a842 100644 --- a/docs/Using-the-API/API.md +++ b/docs/Using-the-API/API.md @@ -19,6 +19,7 @@ API overview - Who reblogged/favourited a status - Following/unfollowing accounts - Blocking/unblocking accounts + - Getting site information - Creating OAuth apps - [Entities](#entities) - Status @@ -207,6 +208,13 @@ Returns the updated relationship to the user. Returns the updated relationship to the user. +### Getting site information + +**GET /api/v1/site** + +Returns an object containing the `title`, character limit (`max_chars`), and an object of `links` for the site. +Does not require authentication. + ### OAuth apps **POST /api/v1/apps** From 6be7bde24378bcb034552248021ea2450bb10524 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 15 Mar 2017 23:12:48 +0100 Subject: [PATCH 2/2] Fix #525 - Add instance information API --- app/controllers/api/v1/instances_controller.rb | 7 +++++++ app/controllers/api/v1/site_controller.rb | 8 -------- app/views/api/v1/instances/show.rabl | 6 ++++++ app/views/api/v1/site/index.rabl | 14 -------------- config/routes.rb | 3 ++- docs/Using-the-API/API.md | 9 ++++----- 6 files changed, 19 insertions(+), 28 deletions(-) create mode 100644 app/controllers/api/v1/instances_controller.rb delete mode 100644 app/controllers/api/v1/site_controller.rb create mode 100644 app/views/api/v1/instances/show.rabl delete mode 100644 app/views/api/v1/site/index.rabl diff --git a/app/controllers/api/v1/instances_controller.rb b/app/controllers/api/v1/instances_controller.rb new file mode 100644 index 000000000..51d92838a --- /dev/null +++ b/app/controllers/api/v1/instances_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Api::V1::InstancesController < ApiController + respond_to :json + + def show; end +end diff --git a/app/controllers/api/v1/site_controller.rb b/app/controllers/api/v1/site_controller.rb deleted file mode 100644 index 64ca2dec1..000000000 --- a/app/controllers/api/v1/site_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -class Api::V1::SiteController < ApiController - respond_to :json - - def index - end -end diff --git a/app/views/api/v1/instances/show.rabl b/app/views/api/v1/instances/show.rabl new file mode 100644 index 000000000..88eb08a9e --- /dev/null +++ b/app/views/api/v1/instances/show.rabl @@ -0,0 +1,6 @@ +object false + +node(:uri) { Rails.configuration.x.local_domain } +node(:title) { Setting.site_title } +node(:description) { Setting.site_description } +node(:email) { Setting.site_contact_email } diff --git a/app/views/api/v1/site/index.rabl b/app/views/api/v1/site/index.rabl deleted file mode 100644 index 09f78560b..000000000 --- a/app/views/api/v1/site/index.rabl +++ /dev/null @@ -1,14 +0,0 @@ -object false - -node(:title) {Setting.site_title} - -node(:max_chars) {500} - -node(:links) do - { - t('about.learn_more') => url_for(about_more_url), - t('about.terms') => url_for(terms_url), - t('about.source_code') => "https://github.com/tootsuite/mastodon", - t('about.other_instances') => "https://github.com/tootsuite/mastodon/blob/master/docs/Using-Mastodon/List-of-Mastodon-instances.md", - } -end diff --git a/config/routes.rb b/config/routes.rb index 1a2e3c19d..ac1d78d64 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -130,7 +130,8 @@ Rails.application.routes.draw do resources :mutes, only: [:index] resources :favourites, only: [:index] resources :reports, only: [:index, :create] - resources :site, only: [:index] + + resource :instance, only: [:show] resources :follow_requests, only: [:index] do member do diff --git a/docs/Using-the-API/API.md b/docs/Using-the-API/API.md index 2c323d559..4db634a60 100644 --- a/docs/Using-the-API/API.md +++ b/docs/Using-the-API/API.md @@ -19,7 +19,7 @@ API overview - Who reblogged/favourited a status - Following/unfollowing accounts - Blocking/unblocking accounts - - Getting site information + - Getting instance information - Creating OAuth apps - [Entities](#entities) - Status @@ -227,12 +227,11 @@ Returns the updated relationship to the user. Returns the updated relationship to the user. -### Getting site information +### Getting instance information -**GET /api/v1/site** +**GET /api/v1/instance** -Returns an object containing the `title`, character limit (`max_chars`), and an object of `links` for the site. -Does not require authentication. +Returns an object containing the `title`, `description`, `email` and `uri` of the instance. Does not require authentication. # Muting and unmuting users