2019-01-16 16:28:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller to wrap social networks public feeds
|
2015-05-05 03:10:25 +02:00
|
|
|
class API::FeedsController < API::ApiController
|
|
|
|
|
|
|
|
respond_to :json
|
|
|
|
|
|
|
|
def twitter_timelines
|
2019-01-16 16:28:25 +01:00
|
|
|
limit = if params
|
|
|
|
params[:limit]
|
|
|
|
else
|
|
|
|
3
|
|
|
|
end
|
2016-03-23 18:39:41 +01:00
|
|
|
from_account = Setting.find_by(name: 'twitter_name').try(:value) || ENV['TWITTER_NAME']
|
2016-11-24 09:38:42 +01:00
|
|
|
begin
|
2019-01-16 16:28:25 +01:00
|
|
|
@tweet_news = Feed.twitter.user_timeline(from_account, count: limit)
|
2016-11-24 09:38:42 +01:00
|
|
|
rescue Twitter::Error::BadRequest => e
|
|
|
|
STDERR.puts "[WARNING] Unable to retrieve the twitter feed, please check your ENV configuration. Details: #{e.message}"
|
|
|
|
render status: :no_content
|
|
|
|
end
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|