Skip to content
Extraits de code Groupes Projets
Valider 9de2837a rédigé par theworldbright's avatar theworldbright Validation de theworldbright
Parcourir les fichiers

Move new API from /api/v2 to /api/v0

parent beae7710
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
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
......
class Api::V2::UsersController < Api::V2::BaseController class Api::V0::UsersController < Api::V0::BaseController
def show def show
render json: user render json: user
......
class Api::V0::BasePresenter
end
class Api::V2::BasePresenter
end
...@@ -198,15 +198,7 @@ Diaspora::Application.routes.draw do ...@@ -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 ...@@ -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 ...@@ -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
......
<!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 @@ ...@@ -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>
......
Fichier déplacé
require 'spec_helper' require 'spec_helper'
describe Api::V2::BaseController do describe Api::V0::BaseController do
end end
...@@ -2,14 +2,14 @@ require 'spec_helper' ...@@ -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)
......
require 'spec_helper' require 'spec_helper'
describe Api::V2::BasePresenter do describe Api::V0::BasePresenter do
end end
require 'spec_helper' require 'spec_helper'
describe Api::V2::BaseController do describe Api::V0::BaseController do
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter