view app/controllers/tweets_controller.rb @ 173:aa78d1eeb6e5

Update rails and other gems
author nanaya <me@nanaya.pro>
date Wed, 08 Aug 2018 20:38:29 +0900
parents 469df6354341
children af84c9f23263
line wrap: on
line source

class TweetsController < ApplicationController
  def index
    return redirect if params[:id].present? || params[:name].present?
  end

  def show
    return redirect if params[:id][/D/].present?

    client = Tweet.new(params[:id].to_i)
    @user = client.user

    return redirect if @user.screen_name != params[:name]

    @tweets = client.timeline
  rescue Twitter::Error::NotFound
    head :not_found
  rescue Twitter::Error::Unauthorized
    head :forbidden
  end

  def redirect
    @user ||= Tweet.new(params[:id].presence || params[:name]).user
    redirect_to tweet_path(@user.id, @user.screen_name)
  rescue Twitter::Error::NotFound
    head :not_found
  rescue Twitter::Error::Unauthorized
    head :forbidden
  end
end