remove pointless authentication, fix up status & headers

This commit is contained in:
Sami Samhuri 2014-10-18 15:37:49 -07:00
parent 034d975225
commit 7e47c2d670

View file

@ -76,47 +76,34 @@ end
# list years # list years
get '/years' do get '/years' do
unless authenticated?(request['Auth']) status 200
status 403 headers 'Content-Type' => 'application/json'
return 'forbidden'
end
JSON.generate(years: blog.years) JSON.generate(years: blog.years)
end end
# list months # list months
get '/months' do get '/months' do
unless authenticated?(request['Auth']) status 200
status 403 headers 'Content-Type' => 'application/json'
return 'forbidden'
end
JSON.generate(months: blog.months) JSON.generate(months: blog.months)
end end
# list posts # list posts
get '/posts/:year/?:month?' do |year, month| get '/posts/:year/?:month?' do |year, month|
unless authenticated?(request['Auth'])
status 403
return 'forbidden'
end
posts = posts =
if month if month
blog.posts_for_month(year, month) blog.posts_for_month(year, month)
else else
blog.posts_for_year(year) blog.posts_for_year(year)
end end
status 200
headers 'Content-Type' => 'application/json'
JSON.generate(posts: posts.map(&:fields)) JSON.generate(posts: posts.map(&:fields))
end end
# get a post # get a post
get '/posts/:year/:month/:slug' do |year, month, slug| get '/posts/:year/:month/:slug' do |year, month, slug|
unless authenticated?(request['Auth'])
status 403
return 'forbidden'
end
begin begin
post = blog.get_post(year, month, slug) post = blog.get_post(year, month, slug)
rescue HarpBlog::InvalidDataError => e rescue HarpBlog::InvalidDataError => e