Move new API from /api/v2 to /api/v0
This commit is contained in:
parent
beae77102d
commit
9de2837a63
14 changed files with 22 additions and 30 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V2::BaseController < ApplicationController
|
class Api::V0::BaseController < ApplicationController
|
||||||
include OpenidConnect::Authentication
|
include OpenidConnect::Authentication
|
||||||
|
|
||||||
before_filter :require_access_token
|
before_filter :require_access_token
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
class Api::V2::UsersController < Api::V2::BaseController
|
class Api::V0::UsersController < Api::V0::BaseController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
render json: user
|
render json: user
|
||||||
2
app/presenters/api/v0/base_presenter.rb
Normal file
2
app/presenters/api/v0/base_presenter.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
class Api::V0::BasePresenter
|
||||||
|
end
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
class Api::V2::BasePresenter
|
|
||||||
end
|
|
||||||
|
|
@ -198,15 +198,7 @@ Diaspora::Application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scope 'api/v0', :controller => :apis do
|
|
||||||
get :me
|
|
||||||
end
|
|
||||||
|
|
||||||
namespace :api do
|
namespace :api do
|
||||||
namespace :v0 do
|
|
||||||
get "/users/:username" => 'users#show', :as => 'user'
|
|
||||||
get "/tags/:name" => 'tags#show', :as => 'tag'
|
|
||||||
end
|
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
resources :tokens, :only => [:create, :destroy]
|
resources :tokens, :only => [:create, :destroy]
|
||||||
end
|
end
|
||||||
|
|
@ -249,7 +241,7 @@ Diaspora::Application.routes.draw do
|
||||||
post 'access_tokens', to: proc { |env| OpenidConnect::TokenEndpoint.new.call(env) }
|
post 'access_tokens', to: proc { |env| OpenidConnect::TokenEndpoint.new.call(env) }
|
||||||
end
|
end
|
||||||
|
|
||||||
api_version(:module => "Api::V2", path: {value: "api/v2"}, default: true) do
|
api_version(module: "Api::V0", path: {value: "api/v0"}, default: true) do
|
||||||
match 'user', to: 'users#show', via: :get
|
match 'user', to: 'users#show', via: :get
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,13 @@ end
|
||||||
|
|
||||||
When /^I use received valid bearer tokens to access user info via URI query parameter$/ do
|
When /^I use received valid bearer tokens to access user info via URI query parameter$/ do
|
||||||
accessTokenJson = JSON.parse(last_response.body)
|
accessTokenJson = JSON.parse(last_response.body)
|
||||||
userInfoEndPointURL = "/api/v2/user/"
|
userInfoEndPointURL = "/api/v0/user/"
|
||||||
userInfoEndPointURLQuery = "?access_token=" + accessTokenJson["access_token"]
|
userInfoEndPointURLQuery = "?access_token=" + accessTokenJson["access_token"]
|
||||||
visit userInfoEndPointURL + userInfoEndPointURLQuery
|
visit userInfoEndPointURL + userInfoEndPointURLQuery
|
||||||
end
|
end
|
||||||
|
|
||||||
When /^I use invalid bearer tokens to access user info via URI query parameter$/ do
|
When /^I use invalid bearer tokens to access user info via URI query parameter$/ do
|
||||||
userInfoEndPointURL = "/api/v2/user/"
|
userInfoEndPointURL = "/api/v0/user/"
|
||||||
userInfoEndPointURLQuery = "?access_token=" + SecureRandom.hex(32)
|
userInfoEndPointURLQuery = "?access_token=" + SecureRandom.hex(32)
|
||||||
visit userInfoEndPointURL + userInfoEndPointURLQuery
|
visit userInfoEndPointURL + userInfoEndPointURLQuery
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en-US">
|
<html lang="en-US">
|
||||||
<head>
|
<head>
|
||||||
<title>Documentation for v2</title>
|
<title>Documentation for v0</title>
|
||||||
<link href="v2/style.css" media="screen" rel="stylesheet" type="text/css">
|
<link href="v2/style.css" media="screen" rel="stylesheet" type="text/css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
<h3>API Operations</h3>
|
<h3>API Operations</h3>
|
||||||
</div>
|
</div>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<h1>Documentation for v2</h1>
|
<h1>Documentation for v0</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
5
spec/controllers/api/v0/base_controller_spec.rb
Normal file
5
spec/controllers/api/v0/base_controller_spec.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Api::V0::BaseController do
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -2,14 +2,14 @@ require 'spec_helper'
|
||||||
|
|
||||||
# TODO: Confirm that the cache-control header in the response is private as according to RFC 6750
|
# TODO: Confirm that the cache-control header in the response is private as according to RFC 6750
|
||||||
# TODO: Check for WWW-Authenticate response header field as according to RFC 6750
|
# TODO: Check for WWW-Authenticate response header field as according to RFC 6750
|
||||||
describe Api::V2::UsersController, type: :request do
|
describe Api::V0::UsersController, type: :request do
|
||||||
describe "#show" do
|
describe "#show" do
|
||||||
let!(:application) { bob.o_auth_applications.create!(client_id: 1, client_secret: "secret") }
|
let!(:application) { bob.o_auth_applications.create!(client_id: 1, client_secret: "secret") }
|
||||||
let!(:token) { application.tokens.create!.bearer_token.to_s }
|
let!(:token) { application.tokens.create!.bearer_token.to_s }
|
||||||
|
|
||||||
context "when valid" do
|
context "when valid" do
|
||||||
it "shows the user's info" do
|
it "shows the user's info" do
|
||||||
get "/api/v2/user/?access_token=" + token
|
get "/api/v0/user/?access_token=" + token
|
||||||
jsonBody = JSON.parse(response.body)
|
jsonBody = JSON.parse(response.body)
|
||||||
expect(jsonBody["username"]).to eq(bob.username)
|
expect(jsonBody["username"]).to eq(bob.username)
|
||||||
expect(jsonBody["email"]).to eq(bob.email)
|
expect(jsonBody["email"]).to eq(bob.email)
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe Api::V2::BaseController do
|
|
||||||
|
|
||||||
end
|
|
||||||
5
spec/presenters/api/v0/base_presenter_spec.rb
Normal file
5
spec/presenters/api/v0/base_presenter_spec.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Api::V0::BasePresenter do
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe Api::V2::BasePresenter do
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Api::V2::BaseController do
|
describe Api::V0::BaseController do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue