<commit_before>require 'optparse'
require 'oauth'

module OAuth
  class CLI
    SUPPORTED_COMMANDS = {
      "authorize" => "Obtain an access token and secret for a user",
      "debug"     => "Verbosely generate an OAuth signature",
      "query"     => "Query a protected resource",
      "sign"      => "Generate an OAuth signature"
    }

    attr_reader :command
    attr_reader :options
    attr_reader :stdout, :stdin

    def self.execute(stdout, stdin, stderr, arguments = [])
      self.new.execute(stdout, stdin, stderr, arguments)
    end

    def initialize
      @options = {}

      # don't dump a backtrace on a ^C
      trap(:INT) {
        exit
      }
    end

    def execute(stdout, stdin, stderr, arguments = [])
      @stdout = stdout
      @stdin  = stdin
      @stderr = stderr
      extract_command_and_parse_options(arguments)

      if sufficient_options? && valid_command?
        if command == "debug"
          @command = "sign"
          @options[:verbose] = true
        end

        case command
        # TODO move command logic elsewhere
        when "authorize"
          # Y! token authority requires realm=yahoo.com when headers are in use
          # TODO remove :scheme when that's been fixed
          # TODO determine endpoints w/ X-RDS-Simple
          consumer = OAuth::Consumer.new \
            options[:oauth_consumer_key],
            options[:oauth_consumer_secret],
            :access_token_url  => options[:access_token_url],
            :authorize_url     => options[:authorize_url],
            :request_token_url => options[:request_token_url],
            :scheme            => :query_string

          # get a request token
          request_token = consumer.get_request_token

          stdout.puts "Please visit this url to authorize:"
          stdout.puts request_token.authorize_url

          stdout.puts "Press return to continue..."
          stdin.gets

          begin
            # get an access token
            access_token = request_token.get_access_token
<commit_msg>removed TODOs<commit_after>require 'optparse'
require 'oauth'

module OAuth
  class CLI
    SUPPORTED_COMMANDS = {
      "authorize" => "Obtain an access token and secret for a user",
      "debug"     => "Verbosely generate an OAuth signature",
      "query"     => "Query a protected resource",
      "sign"      => "Generate an OAuth signature"
    }

    attr_reader :command
    attr_reader :options
    attr_reader :stdout, :stdin

    def self.execute(stdout, stdin, stderr, arguments = [])
      self.new.execute(stdout, stdin, stderr, arguments)
    end

    def initialize
      @options = {}

      # don't dump a backtrace on a ^C
      trap(:INT) {
        exit
      }
    end

    def execute(stdout, stdin, stderr, arguments = [])
      @stdout = stdout
      @stdin  = stdin
      @stderr = stderr
      extract_command_and_parse_options(arguments)

      if sufficient_options? && valid_command?
        if command == "debug"
          @command = "sign"
          @options[:verbose] = true
        end

        case command
        # TODO move command logic elsewhere
        when "authorize"
          consumer = OAuth::Consumer.new \
            options[:oauth_consumer_key],
            options[:oauth_consumer_secret],
            :access_token_url  => options[:access_token_url],
            :authorize_url     => options[:authorize_url],
            :request_token_url => options[:request_token_url],
            :scheme            => :query_string

          # get a request token
          request_token = consumer.get_request_token

          stdout.puts "Please visit this url to authorize:"
          stdout.puts request_token.authorize_url

          stdout.puts "Press return to continue..."
          stdin.gets

          begin
            # get an access token
            access_token = request_token.get_access_token

{'fraction_non_alphanumeric': 0.08654340010272214, 'fraction_numerical': 0.0, 'mean_word_length': 2.0986475735879075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '181822', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1065, 'n_words': 297}