<commit_before>module Tware
  class UnAuthorizedException < StandardError; end

  class TwitterController < ApplicationController
    before_filter :authorize_user

    def create
      store_params_in_session
      twitter_user = TwitterUser.new(current_user)

      if twitter_user.new?
        redirect_to "/auth/twitter?origin=/twitter_post"
      else
        begin
          twitter_user.post_tweet(session[:twitter_message])
          redirect_url = get_redirect_url('You have successfully tweeted the link', 'notice')
        rescue Twitter::Error::Forbidden => e
          redirect_url = get_redirect_url(e.message, 'error')
        ensure
          clear_session!(:twitter_message, :step, :return_to)
          redirect_to redirect_url
        end
      end
    end

    private
    def authorize_user
      redirect_to get_redirect_url('Please Login before you perform this action', 'error') if current_user.nil?
    end

    def store_params_in_session
      session[:step] ||= params[:step]
      session[:twitter_message] ||= params[:twitter_message]
      session[:return_to] ||= params[:return_to]
    end

    def clear_session!(*args)
      args.each {|arg| session[arg] = nil}
    end

    def get_redirect_url(msg, msg_type)
      "#{twitter_callback}?#{query_params(msg, msg_type)}"
    end

    def query_params(message, message_type)
      {
        :return_to => session[:return_to],
        :msg => message,
        :type => message_type,
        :step => session[:step]
      }.to_query
    end<commit_msg>this is tmp commit.<commit_after>module Tware
  class UnAuthorizedException < StandardError; end

  class TwitterController < ApplicationController
    before_filter :authorize_user

    def create
      store_params_in_session
      twitter_user = TwitterUser.new(current_user)

      if twitter_user.new?
        redirect_to "/auth/twitter?origin=/#{twitter_post_path}"
      else
        begin
          twitter_user.post_tweet(session[:twitter_message])
          redirect_url = get_redirect_url('You have successfully tweeted the link', 'notice')
        rescue Twitter::Error::Forbidden => e
          redirect_url = get_redirect_url(e.message, 'error')
        ensure
          clear_session!(:twitter_message, :step, :return_to)
          redirect_to redirect_url
        end
      end
    end

    private
    def authorize_user
      if current_user.nil?
        redirect_to get_redirect_url('Please Login before you perform this action', 'error')
      end
    end

    def store_params_in_session
      session[:step] ||= params[:step]
      session[:twitter_message] ||= params[:twitter_message]
      session[:return_to] ||= params[:return_to]
    end

    def clear_session!(*args)
      args.each {|arg| session[arg] = nil}
    end

    def get_redirect_url(msg, msg_type)
      "#{twitter_callback}?#{query_params(msg, msg_type)}"
    end

    def query_params(message, message_type)
      {
        :return_to => session[:return_to],
        :msg => message,
        :type => message_type,
        :step => session[:step]
      }.to_query
    end
{'fraction_non_alphanumeric': 0.09496124031007752, 'fraction_numerical': 0.0, 'mean_word_length': 2.89070351758794, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3737495', 'n_tokens_mistral': 916, 'n_tokens_neox': 892, 'n_words': 195}