Skip to content

Commit

Permalink
More API
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtOfCode- committed Dec 14, 2017
1 parent b8e2af7 commit 193783b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/api/api/apps_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AppsAPI < API::Base
prefix :apps

get '/' do
std_result APIKey.all.order(id: :desc), filter: 'MMIGHGKIMLJJIMHGNNONNMNMGFNFNJOMMIMLJHNFIH'
std_result APIKey.all.order(id: :desc), filter: 'MOGLMLJKJKJMNIMGHGKHJKGMOONLMOFGLNIIJLHIFJMLN'
end
end
end
1 change: 1 addition & 0 deletions app/api/api/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ def single_result(item, **_opts)
mount API::CommitStatusesAPI
mount API::DeletionLogsAPI
mount API::DomainTagsAPI
mount API::FeedbacksAPI
end
end
2 changes: 1 addition & 1 deletion app/api/api/commit_statuses_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class CommitStatusesAPI < API::Base
prefix :commit_statuses

get '/' do
std_result CommitStatus.all.order(id: :desc), filter: 'GGLIFMJJOLIGGNFGINNMOFNIGGMMMJKIFGKFJ'
std_result CommitStatus.all.order(id: :desc), filter: 'GGOFONNHNJHHIHNJLHHGHGNGGGHLFGGGNNMJFFOL'
end
end
end
4 changes: 2 additions & 2 deletions app/api/api/deletion_logs_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class DeletionLogsAPI < API::Base
prefix :deletion_logs

get '/' do
std_result DeletionLog.all.order(id: :desc), filter: 'OFNLKGOKFHJIKOJNIJOOHNILNKMLGIKGLN'
std_result DeletionLog.all.order(id: :desc), filter: 'OIFJKOKOMFJOJJGGGGFIHLLJOJHGOLHJGHFIH'
end

get '/post/:id' do
std_result DeletionLog.where(post_id: params[:id]).order(id: :desc), filter: 'OFNLKGOKFHJIKOJNIJOOHNILNKMLGIKGLN'
std_result DeletionLog.where(post_id: params[:id]).order(id: :desc), filter: 'OIFJKOKOMFJOJJGGGGFIHLLJOJHGOLHJGHFIH'
end
end
end
57 changes: 57 additions & 0 deletions app/api/api/feedbacks_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module API
class FeedbacksAPI < API::Base
prefix :feedbacks

get '/' do
std_result Feedback.all.order(id: :desc), filter: 'GNIFHNJLJHLIIKHLMIOFKLOOOOKLFKFFNINJ'
end

get 'post/:id' do
std_result Feedback.where(post_id: params[:id]).order(id: :desc), filter: 'GNIFHNJLJHLIIKHLMIOFKLOOOOKLFKFFNINJ'
end

get 'user/:id' do
std_result Feedback.where(user_id: params[:id]).order(id: :desc), filter: 'GNIFHNJLJHLIIKHLMIOFKLOOOOKLFKFFNINJ'
end

get 'app/:id' do
std_result Feedback.where(api_key_id: params[:id]).order(id: :desc), filter: 'GNIFHNJLJHLIIKHLMIOFKLOOOOKLFKFFNINJ'
end

before do
authenticate_user!
role :reviewer
end
params do
requires :key, type: String
requires :token, type: String
requires :type, type: String
end
post 'post/:id/create' do
post = Post.find params[:id]
feedback = Feedback.new user: current_user, post: post, api_key: @key, feedback_type: params[:type]

if post.is_question? && feedback.is_naa?
error!({ name: 'illegal', detail: 'NAA feedback is not allowed on questions.' }, 400)
end

if feedback.save
if feedback.is_naa?
begin
ActionCable.server.broadcast 'smokedetector_messages', naa: { post_link: @post.link }
rescue # rubocop:disable Lint/HandleExceptions
end
elsif @feedback.is_negative?
begin
ActionCable.server.broadcast 'smokedetector_messages', fp: { post_link: @post.link }
rescue # rubocop:disable Lint/HandleExceptions
end
end

std_result post.feedbacks.order(id: :desc), filter: 'GNIFHNJLJHLIIKHLMIOFKLOOOOKLFKFFNINJ'
else
error!({ name: 'persistence_fail', detail: 'Feedback object failed to save.' }, 500)
end
end
end
end

0 comments on commit 193783b

Please sign in to comment.