# File lib/gist.rb, line 110
  def multi_gist(files, options={})
    if options[:anonymous]
      raise 'Anonymous gists are no longer supported. Please log in with `gist --login`. ' \
        '(Github now requires credentials to gist https://bit.ly/2GBBxKw)'
    else
      access_token = (options[:access_token] || auth_token())
    end

    json = {}

    json[:description] = options[:description] if options[:description]
    json[:public] = !!options[:public]
    json[:files] = {}

    files.each_pair do |(name, content)|
      if content.to_s.strip == ""
        raise "Cannot gist empty files" unless options[:skip_empty]
      else
        name = name == "-" ? default_filename : File.basename(name)
        json[:files][name] = {:content => content}
      end
    end

    return if json[:files].empty? && options[:skip_empty]

    existing_gist = options[:update].to_s.split("/").last

    url = "#{base_path}/gists"
    url << "/" << CGI.escape(existing_gist) if existing_gist.to_s != ''
    url << "?access_token=" << CGI.escape(access_token) if access_token.to_s != ''

    request = Net::HTTP::Post.new(url)
    request.body = JSON.dump(json)
    request.content_type = 'application/json'

    retried = false

    begin
      response = http(api_url, request)
      if Net::HTTPSuccess === response
        on_success(response.body, options)
      else
        raise "Got #{response.class} from gist: #{response.body}"
      end
    rescue => e
      raise if retried
      retried = true
      retry
    end

  rescue => e
    raise e.extend Error
  end