class EventStore::Client
Public Class Methods
new(conn_string)
click to toggle source
# File lib/eventstore/client.rb, line 13 def initialize conn_string @conn_string = conn_string @uuid_gen = Cql::TimeUuid::Generator.new end
Public Instance Methods
read_events(stream, read_count=20)
click to toggle source
# File lib/eventstore/client.rb, line 34 def read_events stream, read_count=20 resume_read stream, 0, read_count end
resume_read(stream, last_event_id, read_count=20)
click to toggle source
# File lib/eventstore/client.rb, line 38 def resume_read stream, last_event_id, read_count=20 stream = Stream.new url_for stream stream.events_from(last_event_id).take(read_count) end
write_event(stream, event_type, event_body, uuid=nil)
click to toggle source
# File lib/eventstore/client.rb, line 18 def write_event stream, event_type, event_body, uuid=nil uuid ||= new_uuid json_body = event_body.to_json response = self.class.post url_for(stream), { body: json_body, headers: { 'Content-Type' => 'application/json', 'ES-EventId' => uuid, 'ES-EventType' => event_type, 'ES-ResolveLinkTo' => 'true' }, no_follow: true } [uuid, response] end
Private Instance Methods
new_uuid()
click to toggle source
# File lib/eventstore/client.rb, line 47 def new_uuid @uuid_gen.next.to_s end
url_for(stream)
click to toggle source
# File lib/eventstore/client.rb, line 44 def url_for stream URI.join(@conn_string,'/streams/',stream) end