Add streams API routes
This commit is contained in:
parent
c9ba1ee197
commit
41750e38da
4 changed files with 87 additions and 1 deletions
55
app/controllers/api/v0/streams_controller.rb
Normal file
55
app/controllers/api/v0/streams_controller.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
23
spec/integration/api/streams_controller_spec.rb
Normal file
23
spec/integration/api/streams_controller_spec.rb
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue