<commit_before>module EspnRb
  class Headline

    attr_reader :api_key

    def initialize(opts)
      @api_key = opts && opts[:api_key].nil? ? opts[:api_key] : ENV['espn_api_key']
      raise StandardError, "You must specify an API key." if @api_key.nil?
      create_headline_readers
    end

    def api_resources
      @api_resources ||= YAML::load(File.read('lib/espn_rb/headline_resources.yaml'))
    end

    def api_methods
      @api_methods ||= YAML::load(File.read('lib/espn_rb/headline_methods.yaml'))
    end

    def create_headline_readers
      api_resources.each do |k,v|
        define_singleton_method(k) do |opt=nil|
          api_method = api_methods.keys.include?(opt) ? opt : :news
          get_results(v[:url], api_methods[api_method][:url])
        end
      end
    end

    def get_results(resource, method)
      http = Net::HTTP.new("api.espn.com")
      request = Net::HTTP::Get.new("#{resource}#{method}?apikey=#{@api_key}")
      HeadlineResponse.new JSON.parse(http.request(request).body)
    end
  end
end<commit_msg>Add help command which allows some additional visiblity to user.<commit_after>module EspnRb
  class Headline

    attr_reader :api_key

    def initialize(opts)
      @api_key = opts && opts[:api_key].nil? ? opts[:api_key] : ENV['espn_api_key']
      raise StandardError, "You must specify an API key." if @api_key.nil?
      create_headline_readers
    end

    def api_resources
      @api_resources ||= YAML::load(File.read('lib/espn_rb/headline_resources.yaml'))
    end

    def api_methods
      @api_methods ||= YAML::load(File.read('lib/espn_rb/headline_methods.yaml'))
    end

    def create_headline_readers
      api_resources.each do |k,v|
        define_singleton_method(k) do |opt=nil|
          api_method = api_methods.keys.include?(opt) ? opt : :news
          get_results(v[:url], api_methods[api_method][:url])
        end
      end
    end

    def get_results(resource, method)
      http = Net::HTTP.new("api.espn.com")
      request = Net::HTTP::Get.new("/#{EspnRb::API_VERSION}/#{resource}#{method}?apikey=#{@api_key}")
      HeadlineResponse.new JSON.parse(http.request(request).body)
    end

    def help
      puts "-----------------------------Welcome to EspnRb.---------------------------------\n\n"
      puts s = <<EOF
                                        _.-=""=-._
                                      .'\\\\-++++-//'.
                                     (  ||      ||  )
                                      './/      \\\\.'
                                        `'-=..=-'`
EOF
      puts "--------------------------------------------------------------------------------"
      puts "You are currently using the headlines api from here you can do the follow:\n\n"
      puts "\t#{'Method'.ljust(25)} Description\n\n"
      puts api_resources.map {|k,v| "\t#{(':' + k.to_s).ljust(25)} #{v[:description]}"}.join("\n")
    end
  end
end
{'fraction_non_alphanumeric': 0.18156996587030716, 'fraction_numerical': 0.0013651877133105802, 'mean_word_length': 1.9726166328600405, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4002644', 'n_tokens_mistral': 930, 'n_tokens_neox': 909, 'n_words': 172}