<commit_before># encoding: utf-8

module Github
  class Gists < API
    extend AutoloadHelper

    autoload_all 'github_api/gists',
      :Comments => 'comments'

    include Github::Gists::Comments

    REQUIRED_GIST_INPUTS = %w[ description public files content ]

    # Creates new Gists API
    def initialize(options = {})
      super(options)
    end

    # List a user's gists.
    #
    # = Examples
    #  @github = Github.new :user => 'user-name'
    #  @github.gists.gists
    #
    # List the authenticated user’s gists or if called anonymously,
    # this will returns all public gists
    #
    # = Examples
    #  @github = Github.new :oauth_token => '...'
    #  @github.gists.gists
    #
    def gists(user_name=nil, params={})
      _update_user_repo_params(user_name)
      _normalize_params_keys(params)

      response = if user
        get("/users/#{user}/gists", params)
      elsif oauth_token
        get("/gists", params)
      else
        get("/gists/public", params)
      end
      return response unless block_given?
      response.each { |el| yield el }
    end
    alias :list_gists :gists

    # List the authenticated user's starred gists
    #
    # = Examples
    #  @github = Github.new :oauth_token => '...'
    #  @github.gists.starred
    #
    def starred(params={})
      _normalize_params_keys(params)
      get("/gists/starred", params)
    end

    # Get a single gist
    #
    # = Examples
    #  @github = Github.new :oauth_token => '...'
    #  @github.gists.get_gist 'gist-id'
    #
    def get_gist(gist_id, params={})
      _normalize_params_keys(params)
      get("/gists/#{gist_id}", params)
    end

    # Create a gist
    #
    # = Inputs
    #  <tt>:description</tt> - Optional string
    #  <tt>:public</tt>  - Required boolean
    #  <tt>:files</tt> - Required hash - Files that make up this gist.
    #     The key of which should be a required string filename and 
    #     the value another required hash with parameters:
    #        <tt>:content</tt> - Required string - File contents.
    #
    # = Examples
    #  @github = Github.new :oauth_token => '...'
    #  @github.gists.create_gist 
    #    'description' => 'the description for this gist',<commit_msg>Change validations, update docs for main gists api.<commit_after># encoding: utf-8

module Github
  class Gists < API
    extend AutoloadHelper

    autoload_all 'github_api/gists',
      :Comments => 'comments'

    include Github::Gists::Comments

    REQUIRED_GIST_INPUTS = %w[ description public files content ]

    # Creates new Gists API
    def initialize(options = {})
      super(options)
    end

    # List a user's gists.
    #
    # = Examples
    #  @github = Github.new :user => 'user-name'
    #  @github.gists.gists
    #
    # List the authenticated user’s gists or if called anonymously,
    # this will returns all public gists
    #
    # = Examples
    #  @github = Github.new :oauth_token => '...'
    #  @github.gists.gists
    #
    def gists(user_name=nil, params={})
      _update_user_repo_params(user_name)
      _normalize_params_keys(params)

      response = if user
        get("/users/#{user}/gists", params)
      elsif oauth_token
        get("/gists", params)
      else
        get("/gists/public", params)
      end
      return response unless block_given?
      response.each { |el| yield el }
    end
    alias :list_gists :gists

    # List the authenticated user's starred gists
    #
    # = Examples
    #  @github = Github.new :oauth_token => '...'
    #  @github.gists.starred
    #
    def starred(params={})
      _normalize_params_keys(params)

      response = get("/gists/starred", params)
      return response unless block_given?
      response.each { |el| yield el }
    end

    # Get a single gist
    #
    # = Examples
    #  @github = Github.new
    #  @github.gists.get_gist 'gist-id'
    #
    def gist(gist_id, params={})
      _normalize_params_keys(params)
      _validate_presence_of(gist_id)

      get("/gists/#{gist_id}", params)
    end
    alias :get_gist :gist

    # Create a gist
    #
    # = Inputs
    #  <tt>:description</tt> - Optional string
    #  <tt>:public</tt>  - Required boolean
    #  <tt>:files</tt> - Required hash - Files that make up this gist.
    #     The key of which should be a required string filename and 
    #     the value another required hash with parameters:
    #        <tt>:content</tt> - Required string - File contents.
    #
    # = Examples
    #  @github = Github.new :oauth_token => '...'
    #  @github.gists.create_gist 
    #    'description' => 'the description for this gist',
{'fraction_non_alphanumeric': 0.11732929991356958, 'fraction_numerical': 0.000432152117545376, 'mean_word_length': 2.3302158273381295, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 32, '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': '5181329', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1507, 'n_words': 372}