diff --git a/app/controllers/api/v0/streams_controller.rb b/app/controllers/api/v0/streams_controller.rb new file mode 100644 index 000000000..fed4b1acb --- /dev/null +++ b/app/controllers/api/v0/streams_controller.rb @@ -0,0 +1,55 @@ +module Api + module V0 + class StreamsController < Api::V0::BaseController + + before_action do + require_access_token %w(read) + end + + def aspects + aspect_ids = (params[:a_ids] || []) + @stream = Stream::Aspect.new(current_user, aspect_ids, max_time: max_time) + stream_responder + end + + def public + stream_responder(Stream::Public) + end + + def activity + stream_responder(Stream::Activity) + end + + def multi + stream_responder(Stream::Multi) + end + + def commented + stream_responder(Stream::Comments) + end + + def liked + stream_responder(Stream::Likes) + end + + def mentioned + stream_responder(Stream::Mention) + end + + def followed_tags + stream_responder(Stream::FollowedTag) + end + + private + + def stream_responder(stream_klass=nil) + + if stream_klass.present? + @stream ||= stream_klass.new(current_user, max_time: max_time) + end + + render json: @stream.stream_posts.map {|p| LastThreeCommentsDecorator.new(PostPresenter.new(p, current_user))} + end + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 31b4f0642..60748c434 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -226,6 +226,14 @@ Rails.application.routes.draw do resources :posts, only: %i(show create destroy) do resources :comments, only: %i(create destroy) end + get "activity" => "streams#activity", :as => "activity_stream" + get "stream" => "streams#multi", :as => "stream" + get "public" => "streams#public", :as => "public_stream" + get "followed_tags" => "streams#followed_tags", :as => "followed_tags_stream" + get "mentions" => "streams#mentioned", :as => "mentioned_stream" + get "liked" => "streams#liked", :as => "liked_stream" + get "commented" => "streams#commented", :as => "commented_stream" + get "aspects" => "streams#aspects", :as => "aspects_stream" end namespace :api do diff --git a/spec/factories.rb b/spec/factories.rb index 0c08448d0..8393a5504 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -423,7 +423,7 @@ FactoryGirl.define do factory :auth_with_read_and_write, class: Api::OpenidConnect::Authorization do o_auth_application - user + association :user, factory: :user_with_aspect scopes %w(openid sub aud profile picture nickname name read write) after(:build) {|m| m.redirect_uri = m.o_auth_application.redirect_uris[0] diff --git a/spec/integration/api/streams_controller_spec.rb b/spec/integration/api/streams_controller_spec.rb new file mode 100644 index 000000000..89896ebee --- /dev/null +++ b/spec/integration/api/streams_controller_spec.rb @@ -0,0 +1,23 @@ +require "spec_helper" + +describe Api::V0::PostsController do + let(:auth) { FactoryGirl.create(:auth_with_read_and_write) } + let!(:access_token) { auth.create_access_token.to_s } + + before do + @aspect = auth.user.aspects.first + @status = auth.user.post(:status_message, text: "This is a status message", public: true, to: "all") + end + + describe "#aspect" do + it "contains expected aspect message" do + get api_v0_aspects_stream_path(a_ids: [@aspect.id]), access_token: access_token + expect(response.body).to include("This is a status message") + end + + it "does not save to requested aspects to session" do + get api_v0_aspects_stream_path(a_ids: [@aspect.id]), access_token: access_token + expect(session[:a_ids]).to be_nil + end + end +end