Sha256: d1f796ecff1ca6a3f9edb8b1b793235f3cb87287ebf000cb9210a95726f23135

Contents?: true

Size: 628 Bytes

Versions: 4

Compression:

Stored size: 628 Bytes

Contents

module EsHttpClient

  class Page

    def initialize(body)
      @body = body
    end

    def last
      find_link('last')
    end

    def previous
      find_link('previous')
    end

    def has_entries?
      @body['entries'] && @body['entries'].length > 0
    end

    def each_event(&block)
      @body['entries']
        .reverse!
        .map {|e| Event.load_from(e)}
        .compact
        .select {|e| e.type !~ /^\$/ }
        .each {|e| yield e }
    end

    private

    def find_link(rel)
      link = @body['links'].detect { |l| l['relation'] == rel }
      link.nil? ? nil : link['uri']
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
es-http-client-0.2.0 lib/es_http_client/page.rb
es-http-client-0.1.2 lib/es_http_client/page.rb
es-http-client-0.1.1 lib/es_http_client/page.rb
es-http-client-0.1.0 lib/es_http_client/page.rb