<commit_before>module FacelauncherInstance
  class ApplicationController < ActionController::Base
    protect_from_forgery :except => :index
    before_filter :get_program

    def index
      respond_to do |format|
        if request.post?
          anchor = index_base
          if !anchor.nil?
            redirect_to(root_url(:anchor => anchor))
          else
            redirect_to(root_url)
          return
        end

        format.html
      end
    end

    def index_base
      anchor = nil

      puts "index_base"

      # Use static values stored in ENV, if they're defined.
      # This is useful for testing.
      facebook_app_id = ENV.key?('FACEBOOK_APP_ID') ? ENV['FACEBOOK_APP_ID'] : @program.facebook_app_id
      facebook_app_secret = ENV.key?('FACEBOOK_APP_SECRET') ? ENV['FACEBOOK_APP_SECRET'] : @program.facebook_app_secret

      fb_oauth = Koala::Facebook::OAuth.new(facebook_app_id, facebook_app_secret)
      if params.key? :signed_request
        fb_signed_request = fb_oauth.parse_signed_request(params[:signed_request])
        logger.info "Signed request: #{fb_signed_request}"
        app_data = fb_signed_request.key?('app_data') ? fb_signed_request['app_data'] : nil

        puts "App data: "
        puts app_data.to_s

        # Call an "event" to allow the app to use the FB app data on its own.
        anchor = before_parse_app_data(app_data) if self.respond_to?('before_parse_app_data') && !app_data.nil?
        # If the event callback did not return an anchor (or doesn't exist), then do default
        # parsing for photo or video.
        unless anchor.nil?
          app_data.match(/^(?<type>photo|video)_(?<id>\d+)/) do |match|
            anchor = "#{match[:type]}s/#{match[:id]}"
          end
        end
      end

      return anchor
    end

    private
    def get_program
      begin<commit_msg>Fixed app_data bugs.<commit_after>module FacelauncherInstance
  class ApplicationController < ActionController::Base
    protect_from_forgery :except => :index
    before_filter :get_program

    def index
      respond_to do |format|
        if request.post?
          anchor = index_base
          if !anchor.nil?
            redirect_to(root_url(:anchor => anchor))
          else
            redirect_to(root_url)
          end
          return
        end

        format.html
      end
    end

    def index_base
      anchor = nil

      # Use static values stored in ENV, if they're defined.
      # This is useful for testing.
      facebook_app_id = ENV.key?('FACEBOOK_APP_ID') ? ENV['FACEBOOK_APP_ID'] : @program.facebook_app_id
      facebook_app_secret = ENV.key?('FACEBOOK_APP_SECRET') ? ENV['FACEBOOK_APP_SECRET'] : @program.facebook_app_secret

      fb_oauth = Koala::Facebook::OAuth.new(facebook_app_id, facebook_app_secret)
      if params.key? :signed_request
        fb_signed_request = fb_oauth.parse_signed_request(params[:signed_request])
        logger.info "Signed request: #{fb_signed_request}"
        app_data = fb_signed_request.key?('app_data') ? fb_signed_request['app_data'] : nil

        # Call an "event" to allow the app to use the FB app data on its own.
        anchor = before_parse_app_data(app_data) if self.respond_to?('before_parse_app_data') && !app_data.nil?
        # If the event callback did not return an anchor (or doesn't exist), then do default
        # parsing for photo or video.
        unless anchor.nil?
          app_data.match(/^(?<type>photo|video)_(?<id>\d+)/) do |match|
            anchor = "#{match[:type]}s/#{match[:id]}"
          end
        end
      end

      return anchor
    end

    private
    def get_program
      begin
{'fraction_non_alphanumeric': 0.09436542669584246, 'fraction_numerical': 0.0, 'mean_word_length': 2.606508875739645, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4152937', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1112, 'n_words': 269}