Sha256: 0c6f47151d85cc5a0b6a045d4c86b0007aac829400af046aeb0f967516bba437

Contents?: true

Size: 799 Bytes

Versions: 3

Compression:

Stored size: 799 Bytes

Contents

require_relative './stream_events'
require_relative './ref'

module EsHttpClient

  class WriteableStream

    def initialize(name, connection)
      @stream_name = name
      @connection = connection
    end

    def to_s
      @stream_name
    end

    def exists?
      ref = Ref.head_of(@stream_name)
      @connection.get(ref.uri, ref.etag)
      true
    rescue EsHttpClientError => e
      return false if e.code == 404
      raise e
    end

    def append(event, expected_version=ExpectedVersion::Any)
      @connection.post(Ref.head_of(@stream_name).uri, event, expected_version)
      true
    rescue EsHttpClientError => e
      STDERR.puts e.message
      false
    end

    def replay_forward(&block)
      StreamEvents.new(@stream_name, @connection).each(&block)
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

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