From 4f9b7432dd4d323ac6cc4efceeae2efaffe62e7d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 27 Sep 2016 16:58:23 +0200 Subject: Fix #52 - Add API versioning (v1) --- .../javascripts/components/actions/accounts.jsx | 10 ++-- .../javascripts/components/actions/compose.jsx | 4 +- .../javascripts/components/actions/follow.jsx | 2 +- .../components/actions/interactions.jsx | 8 ++-- .../javascripts/components/actions/statuses.jsx | 2 +- .../javascripts/components/actions/timelines.jsx | 4 +- app/controllers/api/accounts_controller.rb | 52 --------------------- app/controllers/api/apps_controller.rb | 13 ------ app/controllers/api/follows_controller.rb | 13 ------ app/controllers/api/media_controller.rb | 8 ---- app/controllers/api/statuses_controller.rb | 54 ---------------------- app/controllers/api/v1/accounts_controller.rb | 52 +++++++++++++++++++++ app/controllers/api/v1/apps_controller.rb | 13 ++++++ app/controllers/api/v1/follows_controller.rb | 13 ++++++ app/controllers/api/v1/media_controller.rb | 8 ++++ app/controllers/api/v1/statuses_controller.rb | 54 ++++++++++++++++++++++ app/helpers/api/accounts_helper.rb | 2 - app/helpers/api/apps_helper.rb | 2 - app/helpers/api/follows_helper.rb | 2 - app/helpers/api/media_helper.rb | 2 - app/helpers/api/salmon_helper.rb | 2 - app/helpers/api/statuses_helper.rb | 2 - app/helpers/api/subscriptions_helper.rb | 2 - app/helpers/home_helper.rb | 6 +-- app/lib/feed_manager.rb | 2 +- app/views/api/accounts/followers.rabl | 2 - app/views/api/accounts/following.rabl | 2 - app/views/api/accounts/relationship.rabl | 5 -- app/views/api/accounts/relationships.rabl | 2 - app/views/api/accounts/show.rabl | 10 ---- app/views/api/accounts/statuses.rabl | 2 - app/views/api/apps/create.rabl | 4 -- app/views/api/follows/show.rabl | 2 - app/views/api/media/create.rabl | 5 -- app/views/api/statuses/context.rabl | 13 ------ app/views/api/statuses/home.rabl | 2 - app/views/api/statuses/mentions.rabl | 2 - app/views/api/statuses/show.rabl | 31 ------------- app/views/api/v1/accounts/followers.rabl | 2 + app/views/api/v1/accounts/following.rabl | 2 + app/views/api/v1/accounts/relationship.rabl | 5 ++ app/views/api/v1/accounts/relationships.rabl | 2 + app/views/api/v1/accounts/show.rabl | 10 ++++ app/views/api/v1/accounts/statuses.rabl | 2 + app/views/api/v1/apps/create.rabl | 4 ++ app/views/api/v1/follows/show.rabl | 2 + app/views/api/v1/media/create.rabl | 5 ++ app/views/api/v1/statuses/context.rabl | 13 ++++++ app/views/api/v1/statuses/home.rabl | 2 + app/views/api/v1/statuses/mentions.rabl | 2 + app/views/api/v1/statuses/show.rabl | 31 +++++++++++++ 51 files changed, 241 insertions(+), 255 deletions(-) delete mode 100644 app/controllers/api/accounts_controller.rb delete mode 100644 app/controllers/api/apps_controller.rb delete mode 100644 app/controllers/api/follows_controller.rb delete mode 100644 app/controllers/api/media_controller.rb delete mode 100644 app/controllers/api/statuses_controller.rb create mode 100644 app/controllers/api/v1/accounts_controller.rb create mode 100644 app/controllers/api/v1/apps_controller.rb create mode 100644 app/controllers/api/v1/follows_controller.rb create mode 100644 app/controllers/api/v1/media_controller.rb create mode 100644 app/controllers/api/v1/statuses_controller.rb delete mode 100644 app/helpers/api/accounts_helper.rb delete mode 100644 app/helpers/api/apps_helper.rb delete mode 100644 app/helpers/api/follows_helper.rb delete mode 100644 app/helpers/api/media_helper.rb delete mode 100644 app/helpers/api/salmon_helper.rb delete mode 100644 app/helpers/api/statuses_helper.rb delete mode 100644 app/helpers/api/subscriptions_helper.rb delete mode 100644 app/views/api/accounts/followers.rabl delete mode 100644 app/views/api/accounts/following.rabl delete mode 100644 app/views/api/accounts/relationship.rabl delete mode 100644 app/views/api/accounts/relationships.rabl delete mode 100644 app/views/api/accounts/show.rabl delete mode 100644 app/views/api/accounts/statuses.rabl delete mode 100644 app/views/api/apps/create.rabl delete mode 100644 app/views/api/follows/show.rabl delete mode 100644 app/views/api/media/create.rabl delete mode 100644 app/views/api/statuses/context.rabl delete mode 100644 app/views/api/statuses/home.rabl delete mode 100644 app/views/api/statuses/mentions.rabl delete mode 100644 app/views/api/statuses/show.rabl create mode 100644 app/views/api/v1/accounts/followers.rabl create mode 100644 app/views/api/v1/accounts/following.rabl create mode 100644 app/views/api/v1/accounts/relationship.rabl create mode 100644 app/views/api/v1/accounts/relationships.rabl create mode 100644 app/views/api/v1/accounts/show.rabl create mode 100644 app/views/api/v1/accounts/statuses.rabl create mode 100644 app/views/api/v1/apps/create.rabl create mode 100644 app/views/api/v1/follows/show.rabl create mode 100644 app/views/api/v1/media/create.rabl create mode 100644 app/views/api/v1/statuses/context.rabl create mode 100644 app/views/api/v1/statuses/home.rabl create mode 100644 app/views/api/v1/statuses/mentions.rabl create mode 100644 app/views/api/v1/statuses/show.rabl (limited to 'app') diff --git a/app/assets/javascripts/components/actions/accounts.jsx b/app/assets/javascripts/components/actions/accounts.jsx index b4183bbee..c4aa2d80c 100644 --- a/app/assets/javascripts/components/actions/accounts.jsx +++ b/app/assets/javascripts/components/actions/accounts.jsx @@ -36,7 +36,7 @@ export function fetchAccount(id) { dispatch(fetchAccountRequest(id)); - axios.all([boundApi.get(`/api/accounts/${id}`), boundApi.get(`/api/accounts/relationships?id=${id}`)]).then(values => { + axios.all([boundApi.get(`/api/v1/accounts/${id}`), boundApi.get(`/api/v1/accounts/relationships?id=${id}`)]).then(values => { dispatch(fetchAccountSuccess(values[0].data, values[1].data[0])); }).catch(error => { dispatch(fetchAccountFail(id, error)); @@ -48,7 +48,7 @@ export function fetchAccountTimeline(id) { return (dispatch, getState) => { dispatch(fetchAccountTimelineRequest(id)); - api(getState).get(`/api/accounts/${id}/statuses`).then(response => { + api(getState).get(`/api/v1/accounts/${id}/statuses`).then(response => { dispatch(fetchAccountTimelineSuccess(id, response.data)); }).catch(error => { dispatch(fetchAccountTimelineFail(id, error)); @@ -62,7 +62,7 @@ export function expandAccountTimeline(id) { dispatch(expandAccountTimelineRequest(id)); - api(getState).get(`/api/accounts/${id}/statuses?max_id=${lastId}`).then(response => { + api(getState).get(`/api/v1/accounts/${id}/statuses?max_id=${lastId}`).then(response => { dispatch(expandAccountTimelineSuccess(id, response.data)); }).catch(error => { dispatch(expandAccountTimelineFail(id, error)); @@ -97,7 +97,7 @@ export function followAccount(id) { return (dispatch, getState) => { dispatch(followAccountRequest(id)); - api(getState).post(`/api/accounts/${id}/follow`).then(response => { + api(getState).post(`/api/v1/accounts/${id}/follow`).then(response => { dispatch(followAccountSuccess(response.data)); }).catch(error => { dispatch(followAccountFail(error)); @@ -109,7 +109,7 @@ export function unfollowAccount(id) { return (dispatch, getState) => { dispatch(unfollowAccountRequest(id)); - api(getState).post(`/api/accounts/${id}/unfollow`).then(response => { + api(getState).post(`/api/v1/accounts/${id}/unfollow`).then(response => { dispatch(unfollowAccountSuccess(response.data)); }).catch(error => { dispatch(unfollowAccountFail(error)); diff --git a/app/assets/javascripts/components/actions/compose.jsx b/app/assets/javascripts/components/actions/compose.jsx index b4d0b06a2..402c59dc6 100644 --- a/app/assets/javascripts/components/actions/compose.jsx +++ b/app/assets/javascripts/components/actions/compose.jsx @@ -36,7 +36,7 @@ export function submitCompose() { return function (dispatch, getState) { dispatch(submitComposeRequest()); - api(getState).post('/api/statuses', { + api(getState).post('/api/v1/statuses', { status: getState().getIn(['compose', 'text'], ''), in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null), media_ids: getState().getIn(['compose', 'media_attachments']).map(item => item.get('id')) @@ -75,7 +75,7 @@ export function uploadCompose(files) { let data = new FormData(); data.append('file', files[0]); - api(getState).post('/api/media', data, { + api(getState).post('/api/v1/media', data, { onUploadProgress: function (e) { dispatch(uploadComposeProgress(e.loaded, e.total)); } diff --git a/app/assets/javascripts/components/actions/follow.jsx b/app/assets/javascripts/components/actions/follow.jsx index f747a3190..8eb440789 100644 --- a/app/assets/javascripts/components/actions/follow.jsx +++ b/app/assets/javascripts/components/actions/follow.jsx @@ -16,7 +16,7 @@ export function submitFollow(router) { return function (dispatch, getState) { dispatch(submitFollowRequest()); - api(getState).post('/api/follows', { + api(getState).post('/api/v1/follows', { uri: getState().getIn(['follow', 'text']) }).then(function (response) { dispatch(submitFollowSuccess(response.data)); diff --git a/app/assets/javascripts/components/actions/interactions.jsx b/app/assets/javascripts/components/actions/interactions.jsx index 3b3e2a6b6..8ce0c7561 100644 --- a/app/assets/javascripts/components/actions/interactions.jsx +++ b/app/assets/javascripts/components/actions/interactions.jsx @@ -12,7 +12,7 @@ export function reblog(status) { return function (dispatch, getState) { dispatch(reblogRequest(status)); - api(getState).post(`/api/statuses/${status.get('id')}/reblog`).then(function (response) { + api(getState).post(`/api/v1/statuses/${status.get('id')}/reblog`).then(function (response) { // The reblog API method returns a new status wrapped around the original. In this case we are only // interested in how the original is modified, hence passing it skipping the wrapper dispatch(reblogSuccess(status, response.data.reblog)); @@ -24,7 +24,7 @@ export function reblog(status) { export function unreblog(status) { return (dispatch, getState) => { - api(getState).post(`/api/statuses/${status.get('id')}/unreblog`).then(response => { + api(getState).post(`/api/v1/statuses/${status.get('id')}/unreblog`).then(response => { // }).catch(error => { // @@ -59,7 +59,7 @@ export function favourite(status) { return function (dispatch, getState) { dispatch(favouriteRequest(status)); - api(getState).post(`/api/statuses/${status.get('id')}/favourite`).then(function (response) { + api(getState).post(`/api/v1/statuses/${status.get('id')}/favourite`).then(function (response) { dispatch(favouriteSuccess(status, response.data)); }).catch(function (error) { dispatch(favouriteFail(status, error)); @@ -69,7 +69,7 @@ export function favourite(status) { export function unfavourite(status) { return (dispatch, getState) => { - api(getState).post(`/api/statuses/${status.get('id')}/unfavourite`).then(response => { + api(getState).post(`/api/v1/statuses/${status.get('id')}/unfavourite`).then(response => { // }).catch(error => { // diff --git a/app/assets/javascripts/components/actions/statuses.jsx b/app/assets/javascripts/components/actions/statuses.jsx index 1dcf300c4..9b757fceb 100644 --- a/app/assets/javascripts/components/actions/statuses.jsx +++ b/app/assets/javascripts/components/actions/statuses.jsx @@ -18,7 +18,7 @@ export function fetchStatus(id) { dispatch(fetchStatusRequest(id)); - axios.all([boundApi.get(`/api/statuses/${id}`), boundApi.get(`/api/statuses/${id}/context`)]).then(values => { + axios.all([boundApi.get(`/api/v1/statuses/${id}`), boundApi.get(`/api/v1/statuses/${id}/context`)]).then(values => { dispatch(fetchStatusSuccess(values[0].data, values[1].data)); }).catch(error => { dispatch(fetchStatusFail(id, error)); diff --git a/app/assets/javascripts/components/actions/timelines.jsx b/app/assets/javascripts/components/actions/timelines.jsx index 8a05c37fd..f92f758f5 100644 --- a/app/assets/javascripts/components/actions/timelines.jsx +++ b/app/assets/javascripts/components/actions/timelines.jsx @@ -45,7 +45,7 @@ export function refreshTimeline(timeline) { return function (dispatch, getState) { dispatch(refreshTimelineRequest(timeline)); - api(getState).get(`/api/statuses/${timeline}`).then(function (response) { + api(getState).get(`/api/v1/statuses/${timeline}`).then(function (response) { dispatch(refreshTimelineSuccess(timeline, response.data)); }).catch(function (error) { dispatch(refreshTimelineFail(timeline, error)); @@ -67,7 +67,7 @@ export function expandTimeline(timeline) { dispatch(expandTimelineRequest(timeline)); - api(getState).get(`/api/statuses/${timeline}?max_id=${lastId}`).then(response => { + api(getState).get(`/api/v1/statuses/${timeline}?max_id=${lastId}`).then(response => { dispatch(expandTimelineSuccess(timeline, response.data)); }).catch(error => { dispatch(expandTimelineFail(timeline, error)); diff --git a/app/controllers/api/accounts_controller.rb b/app/controllers/api/accounts_controller.rb deleted file mode 100644 index 490c28e75..000000000 --- a/app/controllers/api/accounts_controller.rb +++ /dev/null @@ -1,52 +0,0 @@ -class Api::AccountsController < ApiController - before_action :doorkeeper_authorize! - before_action :set_account - respond_to :json - - def show - end - - def following - @following = @account.following - end - - def followers - @followers = @account.followers - end - - def statuses - @statuses = @account.statuses.with_includes.with_counters.paginate_by_max_id(20, params[:max_id] || nil).to_a - end - - def follow - @follow = FollowService.new.(current_user.account, @account.acct) - set_relationship - render action: :relationship - end - - def unfollow - @unfollow = UnfollowService.new.(current_user.account, @account) - set_relationship - render action: :relationship - end - - def relationships - ids = params[:id].is_a?(Enumerable) ? params[:id].map { |id| id.to_i } : [params[:id].to_i] - @accounts = Account.find(ids) - @following = Account.following_map(ids, current_user.account_id) - @followed_by = Account.followed_by_map(ids, current_user.account_id) - @blocking = {} - end - - private - - def set_account - @account = Account.find(params[:id]) - end - - def set_relationship - @following = Account.following_map([@account.id], current_user.account_id) - @followed_by = Account.followed_by_map([@account.id], current_user.account_id) - @blocking = {} - end -end diff --git a/app/controllers/api/apps_controller.rb b/app/controllers/api/apps_controller.rb deleted file mode 100644 index 629cb2416..000000000 --- a/app/controllers/api/apps_controller.rb +++ /dev/null @@ -1,13 +0,0 @@ -class Api::AppsController < ApplicationController - respond_to :json - - def create - @app = Doorkeeper::Application.create!(app_params) - end - - private - - def app_params - params.permit(:name, :redirect_uri) - end -end diff --git a/app/controllers/api/follows_controller.rb b/app/controllers/api/follows_controller.rb deleted file mode 100644 index dbd44cc54..000000000 --- a/app/controllers/api/follows_controller.rb +++ /dev/null @@ -1,13 +0,0 @@ -class Api::FollowsController < ApiController - before_action :doorkeeper_authorize! - respond_to :json - - def create - if params[:uri].blank? - raise ActiveRecord::RecordNotFound - end - - @account = FollowService.new.(current_user.account, params[:uri]).try(:target_account) - render action: :show - end -end diff --git a/app/controllers/api/media_controller.rb b/app/controllers/api/media_controller.rb deleted file mode 100644 index d5a0a124a..000000000 --- a/app/controllers/api/media_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Api::MediaController < ApiController - before_action :doorkeeper_authorize! - respond_to :json - - def create - @media = MediaAttachment.create!(account: current_user.account, file: params[:file]) - end -end diff --git a/app/controllers/api/statuses_controller.rb b/app/controllers/api/statuses_controller.rb deleted file mode 100644 index 44fb40bae..000000000 --- a/app/controllers/api/statuses_controller.rb +++ /dev/null @@ -1,54 +0,0 @@ -class Api::StatusesController < ApiController - before_action :doorkeeper_authorize! - respond_to :json - - def show - @status = Status.find(params[:id]) - end - - def context - @status = Status.find(params[:id]) - @ancestors = @status.ancestors - @descendants = @status.descendants - end - - def create - @status = PostStatusService.new.(current_user.account, params[:status], params[:in_reply_to_id].blank? ? nil : Status.find(params[:in_reply_to_id]), params[:media_ids]) - render action: :show - end - - def destroy - @status = Status.where(account_id: current_user.account).find(params[:id]) - RemoveStatusService.new.(@status) - render_empty - end - - def reblog - @status = ReblogService.new.(current_user.account, Status.find(params[:id])).reload - render action: :show - end - - def unreblog - RemoveStatusService.new.(Status.where(account_id: current_user.account, reblog_of_id: params[:id]).first!) - @status = Status.find(params[:id]) - render action: :show - end - - def favourite - @status = FavouriteService.new.(current_user.account, Status.find(params[:id])).status.reload - render action: :show - end - - def unfavourite - @status = UnfavouriteService.new.(current_user.account, Status.find(params[:id])).status.reload - render action: :show - end - - def home - @statuses = Feed.new(:home, current_user.account).get(20, params[:max_id]).to_a - end - - def mentions - @statuses = Feed.new(:mentions, current_user.account).get(20, params[:max_id]).to_a - end -end diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb new file mode 100644 index 000000000..23f48782f --- /dev/null +++ b/app/controllers/api/v1/accounts_controller.rb @@ -0,0 +1,52 @@ +class Api::V1::AccountsController < ApiController + before_action :doorkeeper_authorize! + before_action :set_account + respond_to :json + + def show + end + + def following + @following = @account.following + end + + def followers + @followers = @account.followers + end + + def statuses + @statuses = @account.statuses.with_includes.with_counters.paginate_by_max_id(20, params[:max_id] || nil).to_a + end + + def follow + @follow = FollowService.new.(current_user.account, @account.acct) + set_relationship + render action: :relationship + end + + def unfollow + @unfollow = UnfollowService.new.(current_user.account, @account) + set_relationship + render action: :relationship + end + + def relationships + ids = params[:id].is_a?(Enumerable) ? params[:id].map { |id| id.to_i } : [params[:id].to_i] + @accounts = Account.find(ids) + @following = Account.following_map(ids, current_user.account_id) + @followed_by = Account.followed_by_map(ids, current_user.account_id) + @blocking = {} + end + + private + + def set_account + @account = Account.find(params[:id]) + end + + def set_relationship + @following = Account.following_map([@account.id], current_user.account_id) + @followed_by = Account.followed_by_map([@account.id], current_user.account_id) + @blocking = {} + end +end diff --git a/app/controllers/api/v1/apps_controller.rb b/app/controllers/api/v1/apps_controller.rb new file mode 100644 index 000000000..f7a5e0b0a --- /dev/null +++ b/app/controllers/api/v1/apps_controller.rb @@ -0,0 +1,13 @@ +class Api::V1::AppsController < ApplicationController + respond_to :json + + def create + @app = Doorkeeper::Application.create!(app_params) + end + + private + + def app_params + params.permit(:name, :redirect_uri) + end +end diff --git a/app/controllers/api/v1/follows_controller.rb b/app/controllers/api/v1/follows_controller.rb new file mode 100644 index 000000000..de006f671 --- /dev/null +++ b/app/controllers/api/v1/follows_controller.rb @@ -0,0 +1,13 @@ +class Api::V1::FollowsController < ApiController + before_action :doorkeeper_authorize! + respond_to :json + + def create + if params[:uri].blank? + raise ActiveRecord::RecordNotFound + end + + @account = FollowService.new.(current_user.account, params[:uri]).try(:target_account) + render action: :show + end +end diff --git a/app/controllers/api/v1/media_controller.rb b/app/controllers/api/v1/media_controller.rb new file mode 100644 index 000000000..4896534ad --- /dev/null +++ b/app/controllers/api/v1/media_controller.rb @@ -0,0 +1,8 @@ +class Api::V1::MediaController < ApiController + before_action :doorkeeper_authorize! + respond_to :json + + def create + @media = MediaAttachment.create!(account: current_user.account, file: params[:file]) + end +end diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb new file mode 100644 index 000000000..4196852f2 --- /dev/null +++ b/app/controllers/api/v1/statuses_controller.rb @@ -0,0 +1,54 @@ +class Api::V1::StatusesController < ApiController + before_action :doorkeeper_authorize! + respond_to :json + + def show + @status = Status.find(params[:id]) + end + + def context + @status = Status.find(params[:id]) + @ancestors = @status.ancestors + @descendants = @status.descendants + end + + def create + @status = PostStatusService.new.(current_user.account, params[:status], params[:in_reply_to_id].blank? ? nil : Status.find(params[:in_reply_to_id]), params[:media_ids]) + render action: :show + end + + def destroy + @status = Status.where(account_id: current_user.account).find(params[:id]) + RemoveStatusService.new.(@status) + render_empty + end + + def reblog + @status = ReblogService.new.(current_user.account, Status.find(params[:id])).reload + render action: :show + end + + def unreblog + RemoveStatusService.new.(Status.where(account_id: current_user.account, reblog_of_id: params[:id]).first!) + @status = Status.find(params[:id]) + render action: :show + end + + def favourite + @status = FavouriteService.new.(current_user.account, Status.find(params[:id])).status.reload + render action: :show + end + + def unfavourite + @status = UnfavouriteService.new.(current_user.account, Status.find(params[:id])).status.reload + render action: :show + end + + def home + @statuses = Feed.new(:home, current_user.account).get(20, params[:max_id]).to_a + end + + def mentions + @statuses = Feed.new(:mentions, current_user.account).get(20, params[:max_id]).to_a + end +end diff --git a/app/helpers/api/accounts_helper.rb b/app/helpers/api/accounts_helper.rb deleted file mode 100644 index d9a54c7bc..000000000 --- a/app/helpers/api/accounts_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Api::AccountsHelper -end diff --git a/app/helpers/api/apps_helper.rb b/app/helpers/api/apps_helper.rb deleted file mode 100644 index f6b0c6635..000000000 --- a/app/helpers/api/apps_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Api::AppsHelper -end diff --git a/app/helpers/api/follows_helper.rb b/app/helpers/api/follows_helper.rb deleted file mode 100644 index d8022d93c..000000000 --- a/app/helpers/api/follows_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Api::FollowsHelper -end diff --git a/app/helpers/api/media_helper.rb b/app/helpers/api/media_helper.rb deleted file mode 100644 index ecaa91e7b..000000000 --- a/app/helpers/api/media_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Api::MediaHelper -end diff --git a/app/helpers/api/salmon_helper.rb b/app/helpers/api/salmon_helper.rb deleted file mode 100644 index 513c6fb7d..000000000 --- a/app/helpers/api/salmon_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Api::SalmonHelper -end diff --git a/app/helpers/api/statuses_helper.rb b/app/helpers/api/statuses_helper.rb deleted file mode 100644 index 3187f3e3b..000000000 --- a/app/helpers/api/statuses_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Api::StatusesHelper -end diff --git a/app/helpers/api/subscriptions_helper.rb b/app/helpers/api/subscriptions_helper.rb deleted file mode 100644 index 3796aee42..000000000 --- a/app/helpers/api/subscriptions_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module Api::SubscriptionsHelper -end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index d08264e1e..61a4b4dd8 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -3,11 +3,11 @@ module HomeHelper { token: @token, - account: render(file: 'api/accounts/show', locals: { account: current_user.account }, formats: :json), + account: render(file: 'api/v1/accounts/show', locals: { account: current_user.account }, formats: :json), timelines: { - home: render(file: 'api/statuses/home', locals: { statuses: @home }, formats: :json), - mentions: render(file: 'api/statuses/mentions', locals: { statuses: @mentions }, formats: :json) + home: render(file: 'api/v1/statuses/home', locals: { statuses: @home }, formats: :json), + mentions: render(file: 'api/v1/statuses/mentions', locals: { statuses: @mentions }, formats: :json) } } end diff --git a/app/lib/feed_manager.rb b/app/lib/feed_manager.rb index 8e141eb41..c6ba96771 100644 --- a/app/lib/feed_manager.rb +++ b/app/lib/feed_manager.rb @@ -54,6 +54,6 @@ class FeedManager end end - Rabl::Renderer.new('api/statuses/show', status, view_path: 'app/views', format: :json, scope: rabl_scope.new(target_account)).render + Rabl::Renderer.new('api/v1/statuses/show', status, view_path: 'app/views', format: :json, scope: rabl_scope.new(target_account)).render end end diff --git a/app/views/api/accounts/followers.rabl b/app/views/api/accounts/followers.rabl deleted file mode 100644 index 9bb0d9c8f..000000000 --- a/app/views/api/accounts/followers.rabl +++ /dev/null @@ -1,2 +0,0 @@ -collection @followers -extends('api/accounts/show') diff --git a/app/views/api/accounts/following.rabl b/app/views/api/accounts/following.rabl deleted file mode 100644 index 9f2155293..000000000 --- a/app/views/api/accounts/following.rabl +++ /dev/null @@ -1,2 +0,0 @@ -collection @following -extends('api/accounts/show') diff --git a/app/views/api/accounts/relationship.rabl b/app/views/api/accounts/relationship.rabl deleted file mode 100644 index 3e5bf882c..000000000 --- a/app/views/api/accounts/relationship.rabl +++ /dev/null @@ -1,5 +0,0 @@ -object @account -attribute :id -node(:following) { |account| @following[account.id] || false } -node(:followed_by) { |account| @followed_by[account.id] || false } -node(:blocking) { |account| @blocking[account.id] || false } diff --git a/app/views/api/accounts/relationships.rabl b/app/views/api/accounts/relationships.rabl deleted file mode 100644 index 16fdc40d9..000000000 --- a/app/views/api/accounts/relationships.rabl +++ /dev/null @@ -1,2 +0,0 @@ -collection @accounts -extends 'api/accounts/relationship' diff --git a/app/views/api/accounts/show.rabl b/app/views/api/accounts/show.rabl deleted file mode 100644 index 4f6a3ff99..000000000 --- a/app/views/api/accounts/show.rabl +++ /dev/null @@ -1,10 +0,0 @@ -object @account - -attributes :id, :username, :acct, :display_name, :note - -node(:url) { |account| TagManager.instance.url_for(account) } -node(:avatar) { |account| full_asset_url(account.avatar.url(:large, false)) } -node(:header) { |account| full_asset_url(account.header.url(:medium, false)) } -node(:followers_count) { |account| account.followers.count } -node(:following_count) { |account| account.following.count } -node(:statuses_count) { |account| account.statuses.count } diff --git a/app/views/api/accounts/statuses.rabl b/app/views/api/accounts/statuses.rabl deleted file mode 100644 index 12f00dd21..000000000 --- a/app/views/api/accounts/statuses.rabl +++ /dev/null @@ -1,2 +0,0 @@ -collection @statuses -extends('api/statuses/show') diff --git a/app/views/api/apps/create.rabl b/app/views/api/apps/create.rabl deleted file mode 100644 index 1ff6469a4..000000000 --- a/app/views/api/apps/create.rabl +++ /dev/null @@ -1,4 +0,0 @@ -object @app -attributes :id, :redirect_uri -node(:client_id) { |app| app.uid } -node(:client_secret) { |app| app.secret } diff --git a/app/views/api/follows/show.rabl b/app/views/api/follows/show.rabl deleted file mode 100644 index 0f24ddb4d..000000000 --- a/app/views/api/follows/show.rabl +++ /dev/null @@ -1,2 +0,0 @@ -object @account -extends('api/accounts/show') diff --git a/app/views/api/media/create.rabl b/app/views/api/media/create.rabl deleted file mode 100644 index 803a93094..000000000 --- a/app/views/api/media/create.rabl +++ /dev/null @@ -1,5 +0,0 @@ -object @media -attribute :id, :type -node(:url) { |media| full_asset_url(media.file.url) } -node(:preview_url) { |media| full_asset_url(media.file.url(:small)) } -node(:text_url) { |media| medium_url(media) } diff --git a/app/views/api/statuses/context.rabl b/app/views/api/statuses/context.rabl deleted file mode 100644 index 71aff690d..000000000 --- a/app/views/api/statuses/context.rabl +++ /dev/null @@ -1,13 +0,0 @@ -object false - -node :ancestors do - @ancestors.map do |status| - partial('api/statuses/show', object: status) - end -end - -node :descendants do - @descendants.map do |status| - partial('api/statuses/show', object: status) - end -end diff --git a/app/views/api/statuses/home.rabl b/app/views/api/statuses/home.rabl deleted file mode 100644 index 12f00dd21..000000000 --- a/app/views/api/statuses/home.rabl +++ /dev/null @@ -1,2 +0,0 @@ -collection @statuses -extends('api/statuses/show') diff --git a/app/views/api/statuses/mentions.rabl b/app/views/api/statuses/mentions.rabl deleted file mode 100644 index 12f00dd21..000000000 --- a/app/views/api/statuses/mentions.rabl +++ /dev/null @@ -1,2 +0,0 @@ -collection @statuses -extends('api/statuses/show') diff --git a/app/views/api/statuses/show.rabl b/app/views/api/statuses/show.rabl deleted file mode 100644 index f06aa6e74..000000000 --- a/app/views/api/statuses/show.rabl +++ /dev/null @@ -1,31 +0,0 @@ -object @status -attributes :id, :created_at, :in_reply_to_id - -node(:uri) { |status| TagManager.instance.uri_for(status) } -node(:content) { |status| Formatter.instance.format(status) } -node(:url) { |status| TagManager.instance.url_for(status) } -node(:reblogs_count) { |status| status.reblogs_count } -node(:favourites_count) { |status| status.favourites_count } -node(:favourited) { |status| current_account.favourited?(status) } -node(:reblogged) { |status| current_account.reblogged?(status) } - -child :reblog => :reblog do - extends('api/statuses/show') -end - -child :account do - extends('api/accounts/show') -end - -child :media_attachments, object_root: false do - attributes :id, :remote_url, :type - - node(:url) { |media| full_asset_url(media.file.url) } - node(:preview_url) { |media| full_asset_url(media.file.url(:small)) } -end - -child :mentions, object_root: false do - node(:url) { |mention| TagManager.instance.url_for(mention.account) } - node(:acct) { |mention| mention.account.acct } - node(:id) { |mention| mention.account_id } -end diff --git a/app/views/api/v1/accounts/followers.rabl b/app/views/api/v1/accounts/followers.rabl new file mode 100644 index 000000000..c54b0487e --- /dev/null +++ b/app/views/api/v1/accounts/followers.rabl @@ -0,0 +1,2 @@ +collection @followers +extends('api/v1/accounts/show') diff --git a/app/views/api/v1/accounts/following.rabl b/app/views/api/v1/accounts/following.rabl new file mode 100644 index 000000000..87b454ffa --- /dev/null +++ b/app/views/api/v1/accounts/following.rabl @@ -0,0 +1,2 @@ +collection @following +extends('api/v1/accounts/show') diff --git a/app/views/api/v1/accounts/relationship.rabl b/app/views/api/v1/accounts/relationship.rabl new file mode 100644 index 000000000..3e5bf882c --- /dev/null +++ b/app/views/api/v1/accounts/relationship.rabl @@ -0,0 +1,5 @@ +object @account +attribute :id +node(:following) { |account| @following[account.id] || false } +node(:followed_by) { |account| @followed_by[account.id] || false } +node(:blocking) { |account| @blocking[account.id] || false } diff --git a/app/views/api/v1/accounts/relationships.rabl b/app/views/api/v1/accounts/relationships.rabl new file mode 100644 index 000000000..022ea2ac4 --- /dev/null +++ b/app/views/api/v1/accounts/relationships.rabl @@ -0,0 +1,2 @@ +collection @accounts +extends 'api/v1/accounts/relationship' diff --git a/app/views/api/v1/accounts/show.rabl b/app/views/api/v1/accounts/show.rabl new file mode 100644 index 000000000..4f6a3ff99 --- /dev/null +++ b/app/views/api/v1/accounts/show.rabl @@ -0,0 +1,10 @@ +object @account + +attributes :id, :username, :acct, :display_name, :note + +node(:url) { |account| TagManager.instance.url_for(account) } +node(:avatar) { |account| full_asset_url(account.avatar.url(:large, false)) } +node(:header) { |account| full_asset_url(account.header.url(:medium, false)) } +node(:followers_count) { |account| account.followers.count } +node(:following_count) { |account| account.following.count } +node(:statuses_count) { |account| account.statuses.count } diff --git a/app/views/api/v1/accounts/statuses.rabl b/app/views/api/v1/accounts/statuses.rabl new file mode 100644 index 000000000..0a0ed13c5 --- /dev/null +++ b/app/views/api/v1/accounts/statuses.rabl @@ -0,0 +1,2 @@ +collection @statuses +extends('api/v1/statuses/show') diff --git a/app/views/api/v1/apps/create.rabl b/app/views/api/v1/apps/create.rabl new file mode 100644 index 000000000..1ff6469a4 --- /dev/null +++ b/app/views/api/v1/apps/create.rabl @@ -0,0 +1,4 @@ +object @app +attributes :id, :redirect_uri +node(:client_id) { |app| app.uid } +node(:client_secret) { |app| app.secret } diff --git a/app/views/api/v1/follows/show.rabl b/app/views/api/v1/follows/show.rabl new file mode 100644 index 000000000..e07106164 --- /dev/null +++ b/app/views/api/v1/follows/show.rabl @@ -0,0 +1,2 @@ +object @account +extends('api/v1/accounts/show') diff --git a/app/views/api/v1/media/create.rabl b/app/views/api/v1/media/create.rabl new file mode 100644 index 000000000..803a93094 --- /dev/null +++ b/app/views/api/v1/media/create.rabl @@ -0,0 +1,5 @@ +object @media +attribute :id, :type +node(:url) { |media| full_asset_url(media.file.url) } +node(:preview_url) { |media| full_asset_url(media.file.url(:small)) } +node(:text_url) { |media| medium_url(media) } diff --git a/app/views/api/v1/statuses/context.rabl b/app/views/api/v1/statuses/context.rabl new file mode 100644 index 000000000..e9176dc29 --- /dev/null +++ b/app/views/api/v1/statuses/context.rabl @@ -0,0 +1,13 @@ +object false + +node :ancestors do + @ancestors.map do |status| + partial('api/v1/statuses/show', object: status) + end +end + +node :descendants do + @descendants.map do |status| + partial('api/v1/statuses/show', object: status) + end +end diff --git a/app/views/api/v1/statuses/home.rabl b/app/views/api/v1/statuses/home.rabl new file mode 100644 index 000000000..0a0ed13c5 --- /dev/null +++ b/app/views/api/v1/statuses/home.rabl @@ -0,0 +1,2 @@ +collection @statuses +extends('api/v1/statuses/show') diff --git a/app/views/api/v1/statuses/mentions.rabl b/app/views/api/v1/statuses/mentions.rabl new file mode 100644 index 000000000..0a0ed13c5 --- /dev/null +++ b/app/views/api/v1/statuses/mentions.rabl @@ -0,0 +1,2 @@ +collection @statuses +extends('api/v1/statuses/show') diff --git a/app/views/api/v1/statuses/show.rabl b/app/views/api/v1/statuses/show.rabl new file mode 100644 index 000000000..3595bafb4 --- /dev/null +++ b/app/views/api/v1/statuses/show.rabl @@ -0,0 +1,31 @@ +object @status +attributes :id, :created_at, :in_reply_to_id + +node(:uri) { |status| TagManager.instance.uri_for(status) } +node(:content) { |status| Formatter.instance.format(status) } +node(:url) { |status| TagManager.instance.url_for(status) } +node(:reblogs_count) { |status| status.reblogs_count } +node(:favourites_count) { |status| status.favourites_count } +node(:favourited) { |status| current_account.favourited?(status) } +node(:reblogged) { |status| current_account.reblogged?(status) } + +child :reblog => :reblog do + extends('api/v1/statuses/show') +end + +child :account do + extends('api/v1/accounts/show') +end + +child :media_attachments, object_root: false do + attributes :id, :remote_url, :type + + node(:url) { |media| full_asset_url(media.file.url) } + node(:preview_url) { |media| full_asset_url(media.file.url(:small)) } +end + +child :mentions, object_root: false do + node(:url) { |mention| TagManager.instance.url_for(mention.account) } + node(:acct) { |mention| mention.account.acct } + node(:id) { |mention| mention.account_id } +end -- cgit