From 68d96a3189a369249c2eacc9418892acfcd81ef2 Mon Sep 17 00:00:00 2001 From: theworldbright Date: Sun, 13 Sep 2015 14:11:53 -0700 Subject: [PATCH] Add versionist gem --- Gemfile | 2 ++ Gemfile.lock | 6 ++++++ app/controllers/api/LICENSE | 19 +++++++++++++++++++ app/controllers/api/v2/base_controller.rb | 6 ++++++ app/controllers/api/v2/users_controller.rb | 5 +++++ app/controllers/users_controller.rb | 7 ------- app/presenters/api/v2/base_presenter.rb | 2 ++ app/serializers/user_serializer.rb | 3 +++ config/routes.rb | 7 +++++-- public/docs/v2/index.html | 17 +++++++++++++++++ public/docs/v2/style.css | 5 +++++ .../api/v2/base_controller_spec.rb | 5 +++++ spec/presenters/api/v2/base_presenter_spec.rb | 5 +++++ spec/requests/api/v2/base_controller_spec.rb | 5 +++++ 14 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 app/controllers/api/LICENSE create mode 100644 app/controllers/api/v2/base_controller.rb create mode 100644 app/controllers/api/v2/users_controller.rb create mode 100644 app/presenters/api/v2/base_presenter.rb create mode 100644 app/serializers/user_serializer.rb create mode 100644 public/docs/v2/index.html create mode 100644 public/docs/v2/style.css create mode 100644 spec/controllers/api/v2/base_controller_spec.rb create mode 100644 spec/presenters/api/v2/base_presenter_spec.rb create mode 100644 spec/requests/api/v2/base_controller_spec.rb diff --git a/Gemfile b/Gemfile index 72d743af0..4eb4c33bd 100644 --- a/Gemfile +++ b/Gemfile @@ -195,6 +195,8 @@ gem "rubyzip", "1.1.7" # https://github.com/discourse/discourse/pull/238 gem "minitest" +gem "versionist", "1.4.1" + # Windows and OSX have an execjs compatible runtime built-in, Linux users should # install Node.js or use "therubyracer". # diff --git a/Gemfile.lock b/Gemfile.lock index ad32b01d8..bef65ab00 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -849,6 +849,10 @@ GEM validate_url (1.0.2) activemodel (>= 3.0.0) addressable + versionist (1.4.1) + activesupport (>= 3) + railties (>= 3) + yard (~> 0.7) warden (1.2.4) rack (>= 1.0) webfinger (1.0.1) @@ -864,6 +868,7 @@ GEM xml-simple (1.1.5) xpath (2.0.0) nokogiri (~> 1.3) + yard (0.8.7.6) PLATFORMS ruby @@ -1008,6 +1013,7 @@ DEPENDENCIES uglifier (= 2.7.2) unicorn (= 5.0.1) uuid (= 2.3.8) + versionist (= 1.4.1) webmock (= 1.22.3) will_paginate (= 3.0.7) diff --git a/app/controllers/api/LICENSE b/app/controllers/api/LICENSE new file mode 100644 index 000000000..de7a5345d --- /dev/null +++ b/app/controllers/api/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2012 Brian Ploetz (bploetz@gmail.com) + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/app/controllers/api/v2/base_controller.rb b/app/controllers/api/v2/base_controller.rb new file mode 100644 index 000000000..33bfb9d71 --- /dev/null +++ b/app/controllers/api/v2/base_controller.rb @@ -0,0 +1,6 @@ +class Api::V2::BaseController < ApplicationController + include Openid::Authentication + + before_action :authenticate_user! + before_filter :require_access_token +end diff --git a/app/controllers/api/v2/users_controller.rb b/app/controllers/api/v2/users_controller.rb new file mode 100644 index 000000000..0a6d34114 --- /dev/null +++ b/app/controllers/api/v2/users_controller.rb @@ -0,0 +1,5 @@ +class Api::V2::UsersController < Api::V2::BaseController + def show + render json: current_user + end +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 823f2ba3e..91376d45f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,17 +3,10 @@ # the COPYRIGHT file. class UsersController < ApplicationController - include Openid::Authentication before_action :authenticate_user!, except: [:new, :create, :public, :user_photo] - before_filter :require_access_token, only: [:show] respond_to :html - # TODO: Adjust so that it sends back only required elements, e.g, should not send hashed password (serialized_private_key) back - def show - render json: current_user - end - def edit @aspect = :user_edit @user = current_user diff --git a/app/presenters/api/v2/base_presenter.rb b/app/presenters/api/v2/base_presenter.rb new file mode 100644 index 000000000..2afabc56a --- /dev/null +++ b/app/presenters/api/v2/base_presenter.rb @@ -0,0 +1,2 @@ +class Api::V2::BasePresenter +end diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb new file mode 100644 index 000000000..b0d134815 --- /dev/null +++ b/app/serializers/user_serializer.rb @@ -0,0 +1,3 @@ +class UserSerializer < ActiveModel::Serializer + attributes :name, :email, :language, :username +end diff --git a/config/routes.rb b/config/routes.rb index 8dfbfd08a..3cb9501cb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -245,8 +245,11 @@ Diaspora::Application.routes.draw do resource :openid do resources :authorizations, only: [:new, :create] match 'connect', to: 'connect#show', via: [:get, :post] - match '.well-known/:id', to: 'discovery#show' , :via => [:get, :post] + match '.well-known/:id', to: 'discovery#show' , via: [:get, :post] post 'access_tokens', to: proc { |env| Openid::TokenEndpoint.new.call(env) } - match 'user_info', to: 'users#show', :via => [:get, :post] + end + + api_version(:module => "Api::V2", path: {value: "api/v2"}, default: true) do + match 'user', to: 'users#show', via: :get end end diff --git a/public/docs/v2/index.html b/public/docs/v2/index.html new file mode 100644 index 000000000..518259ab3 --- /dev/null +++ b/public/docs/v2/index.html @@ -0,0 +1,17 @@ + + + + Documentation for v2 + + + +
+
+

API Operations

+
+
+

Documentation for v2

+
+
+ + diff --git a/public/docs/v2/style.css b/public/docs/v2/style.css new file mode 100644 index 000000000..ea6e1ce9c --- /dev/null +++ b/public/docs/v2/style.css @@ -0,0 +1,5 @@ +body {margin: 0; background-color: #fff; color: #000; font-family: Arial,sans-serif;} +content {margin-left: 200px;} +content h1 {text-align: center;} +operations {float: left; width: 200px; border-right: 1px solid #ccc;} +operations h3 {text-align: center;} diff --git a/spec/controllers/api/v2/base_controller_spec.rb b/spec/controllers/api/v2/base_controller_spec.rb new file mode 100644 index 000000000..221629acb --- /dev/null +++ b/spec/controllers/api/v2/base_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Api::V2::BaseController do + +end diff --git a/spec/presenters/api/v2/base_presenter_spec.rb b/spec/presenters/api/v2/base_presenter_spec.rb new file mode 100644 index 000000000..f9ab6b5df --- /dev/null +++ b/spec/presenters/api/v2/base_presenter_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Api::V2::BasePresenter do + +end diff --git a/spec/requests/api/v2/base_controller_spec.rb b/spec/requests/api/v2/base_controller_spec.rb new file mode 100644 index 000000000..221629acb --- /dev/null +++ b/spec/requests/api/v2/base_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Api::V2::BaseController do + +end