Browse Source

Add API for getting info about authenticated user: /api/v1/accounts/verify_credentials

closed-social-glitch-2
Eugen Rochko 7 years ago
parent
commit
6d7290f47c
3 changed files with 17 additions and 4 deletions
  1. +6
    -1
      app/controllers/api/v1/accounts_controller.rb
  2. +4
    -3
      config/routes.rb
  3. +7
    -0
      spec/controllers/api/v1/accounts_controller_spec.rb

+ 6
- 1
app/controllers/api/v1/accounts_controller.rb View File

@ -1,11 +1,16 @@
class Api::V1::AccountsController < ApiController class Api::V1::AccountsController < ApiController
before_action :doorkeeper_authorize! before_action :doorkeeper_authorize!
before_action :set_account
before_action :set_account, except: :verify_credentials
respond_to :json respond_to :json
def show def show
end end
def verify_credentials
@account = current_user.account
render action: :show
end
def following def following
@following = @account.following @following = @account.following
end end

+ 4
- 3
config/routes.rb View File

@ -29,7 +29,7 @@ Rails.application.routes.draw do
resource :settings, only: [:show, :update] resource :settings, only: [:show, :update]
resources :media, only: [:show] resources :media, only: [:show]
namespace :api do namespace :api do
# PubSubHubbub # PubSubHubbub
resources :subscriptions, only: [:show] resources :subscriptions, only: [:show]
@ -59,10 +59,11 @@ Rails.application.routes.draw do
resources :follows, only: [:create] resources :follows, only: [:create]
resources :media, only: [:create] resources :media, only: [:create]
resources :apps, only: [:create] resources :apps, only: [:create]
resources :accounts, only: [:show] do resources :accounts, only: [:show] do
collection do collection do
get :relationships get :relationships
get :verify_credentials
end end
member do member do
@ -78,7 +79,7 @@ Rails.application.routes.draw do
end end
get :about, to: 'about#index' get :about, to: 'about#index'
root 'home#index' root 'home#index'
match '*unmatched_route', via: :all, to: 'application#raise_not_found' match '*unmatched_route', via: :all, to: 'application#raise_not_found'

+ 7
- 0
spec/controllers/api/v1/accounts_controller_spec.rb View File

@ -18,6 +18,13 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
end end
end end
describe 'GET #verify_credentials' do
it 'returns http success' do
get :verify_credentials
expect(response).to have_http_status(:success)
end
end
describe 'GET #statuses' do describe 'GET #statuses' do
it 'returns http success' do it 'returns http success' do
get :statuses, params: { id: user.account.id } get :statuses, params: { id: user.account.id }

Loading…
Cancel
Save