def new_posts subreddit = nil, caching = false
      cache = lambda do |id, &block|
        next block.call unless caching
        require "fileutils"
        FileUtils.mkdir_p "cache"
        filename = "cache/#{Digest::MD5.hexdigest id.inspect}"
        next YAML.load File.read filename if File.exist? filename
        block.call.tap do |data|
          File.write filename, YAML.dump(data)
        end
      end
      Enumerator.new do |e|
        after = {}
        loop do
          # TODO maybe force lib user to prepend "r/" to @subreddit constructor?
          args = [:get, "/#{subreddit || (@subreddit ? "r/#{@subreddit}" : fail)}/new", {limit: 100}.merge(after)]
          result = cache.call(args){ json *args }
          fail if result.keys != %w{ kind data }
          fail if result["kind"] != "Listing"
          fail result["data"].keys.inspect unless result["data"].keys == %w{ after dist modhash whitelist_status children before } ||
                                                  result["data"].keys == %w{ modhash dist children after before }
          @@skip_erroneous_descending_ids[ result["data"]["children"].map do |post|
            fail "unknown type post['kind']: #{post["kind"]}" unless post["kind"] == "t3"
            post["data"]
          end ].each do |data|
            e << data
          end
          break unless marker = result["data"]["after"]
          after = {after: marker}
        end
      end
    end
def new_posts subreddit = nil, caching = false
      cache = lambda do |id, &block|
        next block.call unless caching
        require "fileutils"
        FileUtils.mkdir_p "cache"
        filename = "cache/#{Digest::MD5.hexdigest id.inspect}"
        next YAML.load File.read filename if File.exist? filename
        block.call.tap do |data|
          File.write filename, YAML.dump(data)
        end
      end
      Enumerator.new do |e|
        after = {}
        loop do
          # TODO maybe force lib user to prepend "r/" to @subreddit constructor?
          args = [:get, "/#{subreddit || (@subreddit ? "r/#{@subreddit}" : fail)}/new", {limit: 100}.merge(after)]
          result = cache.call(args){ json *args }
          fail if result.keys != %w{ kind data }
          fail if result["kind"] != "Listing"
          fail result["data"].keys.inspect unless result["data"].keys == %w{ after dist modhash whitelist_status children before } ||
                                                  result["data"].keys == %w{ modhash dist children after before }
          @@skip_erroneous_descending_ids[ result["data"]["children"].map do |post|
            fail "unknown type post['kind']: #{post["kind"]}" unless post["kind"] == "t3"
            post["data"]
          end ].each do |data|
            e << data
          end
          break unless marker = result["data"]["after"]
          after = {after: marker}
        end
      end
    end
:yields: JSON objects: ["data"] part of post or self.post