Browse Source

Fix #52 - Add API versioning (v1)

closed-social-glitch-2
Eugen Rochko 7 years ago
parent
commit
4f9b7432dd
53 changed files with 79 additions and 136 deletions
  1. +5
    -5
      app/assets/javascripts/components/actions/accounts.jsx
  2. +2
    -2
      app/assets/javascripts/components/actions/compose.jsx
  3. +1
    -1
      app/assets/javascripts/components/actions/follow.jsx
  4. +4
    -4
      app/assets/javascripts/components/actions/interactions.jsx
  5. +1
    -1
      app/assets/javascripts/components/actions/statuses.jsx
  6. +2
    -2
      app/assets/javascripts/components/actions/timelines.jsx
  7. +1
    -1
      app/controllers/api/v1/accounts_controller.rb
  8. +1
    -1
      app/controllers/api/v1/apps_controller.rb
  9. +1
    -1
      app/controllers/api/v1/follows_controller.rb
  10. +1
    -1
      app/controllers/api/v1/media_controller.rb
  11. +1
    -1
      app/controllers/api/v1/statuses_controller.rb
  12. +0
    -2
      app/helpers/api/accounts_helper.rb
  13. +0
    -2
      app/helpers/api/apps_helper.rb
  14. +0
    -2
      app/helpers/api/follows_helper.rb
  15. +0
    -2
      app/helpers/api/media_helper.rb
  16. +0
    -2
      app/helpers/api/salmon_helper.rb
  17. +0
    -2
      app/helpers/api/statuses_helper.rb
  18. +0
    -2
      app/helpers/api/subscriptions_helper.rb
  19. +3
    -3
      app/helpers/home_helper.rb
  20. +1
    -1
      app/lib/feed_manager.rb
  21. +0
    -2
      app/views/api/accounts/followers.rabl
  22. +0
    -2
      app/views/api/accounts/following.rabl
  23. +0
    -2
      app/views/api/accounts/relationships.rabl
  24. +0
    -2
      app/views/api/accounts/statuses.rabl
  25. +0
    -2
      app/views/api/follows/show.rabl
  26. +0
    -2
      app/views/api/statuses/home.rabl
  27. +0
    -2
      app/views/api/statuses/mentions.rabl
  28. +2
    -0
      app/views/api/v1/accounts/followers.rabl
  29. +2
    -0
      app/views/api/v1/accounts/following.rabl
  30. +0
    -0
      app/views/api/v1/accounts/relationship.rabl
  31. +2
    -0
      app/views/api/v1/accounts/relationships.rabl
  32. +0
    -0
      app/views/api/v1/accounts/show.rabl
  33. +2
    -0
      app/views/api/v1/accounts/statuses.rabl
  34. +0
    -0
      app/views/api/v1/apps/create.rabl
  35. +2
    -0
      app/views/api/v1/follows/show.rabl
  36. +0
    -0
      app/views/api/v1/media/create.rabl
  37. +2
    -2
      app/views/api/v1/statuses/context.rabl
  38. +2
    -0
      app/views/api/v1/statuses/home.rabl
  39. +2
    -0
      app/views/api/v1/statuses/mentions.rabl
  40. +2
    -2
      app/views/api/v1/statuses/show.rabl
  41. +32
    -30
      config/routes.rb
  42. +1
    -1
      spec/controllers/api/v1/accounts_controller_spec.rb
  43. +1
    -1
      spec/controllers/api/v1/apps_controller_spec.rb
  44. +1
    -1
      spec/controllers/api/v1/follows_controller_spec.rb
  45. +1
    -1
      spec/controllers/api/v1/media_controller_spec.rb
  46. +1
    -1
      spec/controllers/api/v1/statuses_controller_spec.rb
  47. +0
    -5
      spec/helpers/api/accounts_helper_spec.rb
  48. +0
    -15
      spec/helpers/api/apps_helper_spec.rb
  49. +0
    -5
      spec/helpers/api/follows_helper_spec.rb
  50. +0
    -5
      spec/helpers/api/media_helper_spec.rb
  51. +0
    -5
      spec/helpers/api/salmon_helper_spec.rb
  52. +0
    -5
      spec/helpers/api/statuses_helper_spec.rb
  53. +0
    -5
      spec/helpers/api/subscriptions_helper_spec.rb

+ 5
- 5
app/assets/javascripts/components/actions/accounts.jsx View File

@ -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));

+ 2
- 2
app/assets/javascripts/components/actions/compose.jsx View File

@ -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));
}

+ 1
- 1
app/assets/javascripts/components/actions/follow.jsx View File

@ -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));

+ 4
- 4
app/assets/javascripts/components/actions/interactions.jsx View File

@ -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 => {
//

+ 1
- 1
app/assets/javascripts/components/actions/statuses.jsx View File

@ -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));

+ 2
- 2
app/assets/javascripts/components/actions/timelines.jsx View File

@ -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));

app/controllers/api/accounts_controller.rb → app/controllers/api/v1/accounts_controller.rb View File

@ -1,4 +1,4 @@
class Api::AccountsController < ApiController
class Api::V1::AccountsController < ApiController
before_action :doorkeeper_authorize!
before_action :set_account
respond_to :json

app/controllers/api/apps_controller.rb → app/controllers/api/v1/apps_controller.rb View File

@ -1,4 +1,4 @@
class Api::AppsController < ApplicationController
class Api::V1::AppsController < ApplicationController
respond_to :json
def create

app/controllers/api/follows_controller.rb → app/controllers/api/v1/follows_controller.rb View File

@ -1,4 +1,4 @@
class Api::FollowsController < ApiController
class Api::V1::FollowsController < ApiController
before_action :doorkeeper_authorize!
respond_to :json

app/controllers/api/media_controller.rb → app/controllers/api/v1/media_controller.rb View File

@ -1,4 +1,4 @@
class Api::MediaController < ApiController
class Api::V1::MediaController < ApiController
before_action :doorkeeper_authorize!
respond_to :json

app/controllers/api/statuses_controller.rb → app/controllers/api/v1/statuses_controller.rb View File

@ -1,4 +1,4 @@
class Api::StatusesController < ApiController
class Api::V1::StatusesController < ApiController
before_action :doorkeeper_authorize!
respond_to :json

+ 0
- 2
app/helpers/api/accounts_helper.rb View File

@ -1,2 +0,0 @@
module Api::AccountsHelper
end

+ 0
- 2
app/helpers/api/apps_helper.rb View File

@ -1,2 +0,0 @@
module Api::AppsHelper
end

+ 0
- 2
app/helpers/api/follows_helper.rb View File

@ -1,2 +0,0 @@
module Api::FollowsHelper
end

+ 0
- 2
app/helpers/api/media_helper.rb View File

@ -1,2 +0,0 @@
module Api::MediaHelper
end

+ 0
- 2
app/helpers/api/salmon_helper.rb View File

@ -1,2 +0,0 @@
module Api::SalmonHelper
end

+ 0
- 2
app/helpers/api/statuses_helper.rb View File

@ -1,2 +0,0 @@
module Api::StatusesHelper
end

+ 0
- 2
app/helpers/api/subscriptions_helper.rb View File

@ -1,2 +0,0 @@
module Api::SubscriptionsHelper
end

+ 3
- 3
app/helpers/home_helper.rb View File

@ -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

+ 1
- 1
app/lib/feed_manager.rb View File

@ -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

+ 0
- 2
app/views/api/accounts/followers.rabl View File

@ -1,2 +0,0 @@
collection @followers
extends('api/accounts/show')

+ 0
- 2
app/views/api/accounts/following.rabl View File

@ -1,2 +0,0 @@
collection @following
extends('api/accounts/show')

+ 0
- 2
app/views/api/accounts/relationships.rabl View File

@ -1,2 +0,0 @@
collection @accounts
extends 'api/accounts/relationship'

+ 0
- 2
app/views/api/accounts/statuses.rabl View File

@ -1,2 +0,0 @@
collection @statuses
extends('api/statuses/show')

+ 0
- 2
app/views/api/follows/show.rabl View File

@ -1,2 +0,0 @@
object @account
extends('api/accounts/show')

+ 0
- 2
app/views/api/statuses/home.rabl View File

@ -1,2 +0,0 @@
collection @statuses
extends('api/statuses/show')

+ 0
- 2
app/views/api/statuses/mentions.rabl View File

@ -1,2 +0,0 @@
collection @statuses
extends('api/statuses/show')

+ 2
- 0
app/views/api/v1/accounts/followers.rabl View File

@ -0,0 +1,2 @@
collection @followers
extends('api/v1/accounts/show')

+ 2
- 0
app/views/api/v1/accounts/following.rabl View File

@ -0,0 +1,2 @@
collection @following
extends('api/v1/accounts/show')

app/views/api/accounts/relationship.rabl → app/views/api/v1/accounts/relationship.rabl View File


+ 2
- 0
app/views/api/v1/accounts/relationships.rabl View File

@ -0,0 +1,2 @@
collection @accounts
extends 'api/v1/accounts/relationship'

app/views/api/accounts/show.rabl → app/views/api/v1/accounts/show.rabl View File


+ 2
- 0
app/views/api/v1/accounts/statuses.rabl View File

@ -0,0 +1,2 @@
collection @statuses
extends('api/v1/statuses/show')

app/views/api/apps/create.rabl → app/views/api/v1/apps/create.rabl View File


+ 2
- 0
app/views/api/v1/follows/show.rabl View File

@ -0,0 +1,2 @@
object @account
extends('api/v1/accounts/show')

app/views/api/media/create.rabl → app/views/api/v1/media/create.rabl View File


app/views/api/statuses/context.rabl → app/views/api/v1/statuses/context.rabl View File

@ -2,12 +2,12 @@ object false
node :ancestors do
@ancestors.map do |status|
partial('api/statuses/show', object: status)
partial('api/v1/statuses/show', object: status)
end
end
node :descendants do
@descendants.map do |status|
partial('api/statuses/show', object: status)
partial('api/v1/statuses/show', object: status)
end
end

+ 2
- 0
app/views/api/v1/statuses/home.rabl View File

@ -0,0 +1,2 @@
collection @statuses
extends('api/v1/statuses/show')

+ 2
- 0
app/views/api/v1/statuses/mentions.rabl View File

@ -0,0 +1,2 @@
collection @statuses
extends('api/v1/statuses/show')

app/views/api/statuses/show.rabl → app/views/api/v1/statuses/show.rabl View File

@ -10,11 +10,11 @@ node(:favourited) { |status| current_account.favourited?(status) }
node(:reblogged) { |status| current_account.reblogged?(status) }
child :reblog => :reblog do
extends('api/statuses/show')
extends('api/v1/statuses/show')
end
child :account do
extends('api/accounts/show')
extends('api/v1/accounts/show')
end
child :media_attachments, object_root: false do

+ 32
- 30
config/routes.rb View File

@ -39,38 +39,40 @@ Rails.application.routes.draw do
post '/salmon/:id', to: 'salmon#update', as: :salmon
# JSON / REST API
resources :statuses, only: [:create, :show, :destroy] do
collection do
get :home
get :mentions
namespace :v1 do
resources :statuses, only: [:create, :show, :destroy] do
collection do
get :home
get :mentions
end
member do
get :context
post :reblog
post :unreblog
post :favourite
post :unfavourite
end
end
member do
get :context
post :reblog
post :unreblog
post :favourite
post :unfavourite
end
end
resources :follows, only: [:create]
resources :media, only: [:create]
resources :apps, only: [:create]
resources :accounts, only: [:show] do
collection do
get :relationships
end
member do
get :statuses
get :followers
get :following
post :follow
post :unfollow
resources :follows, only: [:create]
resources :media, only: [:create]
resources :apps, only: [:create]
resources :accounts, only: [:show] do
collection do
get :relationships
end
member do
get :statuses
get :followers
get :following
post :follow
post :unfollow
end
end
end
end

spec/controllers/api/accounts_controller_spec.rb → spec/controllers/api/v1/accounts_controller_spec.rb View File

@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Api::AccountsController, type: :controller do
RSpec.describe Api::V1::AccountsController, type: :controller do
render_views
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }

spec/controllers/api/apps_controller_spec.rb → spec/controllers/api/v1/apps_controller_spec.rb View File

@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Api::AppsController, type: :controller do
RSpec.describe Api::V1::AppsController, type: :controller do
render_views
describe 'POST #create' do

spec/controllers/api/follows_controller_spec.rb → spec/controllers/api/v1/follows_controller_spec.rb View File

@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Api::FollowsController, type: :controller do
RSpec.describe Api::V1::FollowsController, type: :controller do
render_views
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }

spec/controllers/api/media_controller_spec.rb → spec/controllers/api/v1/media_controller_spec.rb View File

@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Api::MediaController, type: :controller do
RSpec.describe Api::V1::MediaController, type: :controller do
render_views
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }

spec/controllers/api/statuses_controller_spec.rb → spec/controllers/api/v1/statuses_controller_spec.rb View File

@ -1,6 +1,6 @@
require 'rails_helper'
RSpec.describe Api::StatusesController, type: :controller do
RSpec.describe Api::V1::StatusesController, type: :controller do
render_views
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }

+ 0
- 5
spec/helpers/api/accounts_helper_spec.rb View File

@ -1,5 +0,0 @@
require 'rails_helper'
RSpec.describe Api::AccountsHelper, type: :helper do
end

+ 0
- 15
spec/helpers/api/apps_helper_spec.rb View File

@ -1,15 +0,0 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the Api::AppsHelper. For example:
#
# describe Api::AppsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe Api::AppsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

+ 0
- 5
spec/helpers/api/follows_helper_spec.rb View File

@ -1,5 +0,0 @@
require 'rails_helper'
RSpec.describe Api::FollowsHelper, type: :helper do
end

+ 0
- 5
spec/helpers/api/media_helper_spec.rb View File

@ -1,5 +0,0 @@
require 'rails_helper'
RSpec.describe Api::MediaHelper, type: :helper do
end

+ 0
- 5
spec/helpers/api/salmon_helper_spec.rb View File

@ -1,5 +0,0 @@
require 'rails_helper'
RSpec.describe Api::SalmonHelper, type: :helper do
end

+ 0
- 5
spec/helpers/api/statuses_helper_spec.rb View File

@ -1,5 +0,0 @@
require 'rails_helper'
RSpec.describe Api::StatusesHelper, type: :helper do
end

+ 0
- 5
spec/helpers/api/subscriptions_helper_spec.rb View File

@ -1,5 +0,0 @@
require 'rails_helper'
RSpec.describe Api::SubscriptionsHelper, type: :helper do
end

Loading…
Cancel
Save