Class: EventStore::Client
- Inherits:
-
Object
- Object
- EventStore::Client
- Includes:
- HTTParty
- Defined in:
- lib/eventstore.rb,
lib/eventstore/client.rb
Instance Method Summary collapse
-
#initialize(conn_string) ⇒ Client
constructor
A new instance of Client.
- #read_events(stream, read_count = 20) ⇒ Object
- #resume_read(stream, last_event_id, read_count = 20) ⇒ Object
- #write_event(stream, event_type, event_body, uuid = nil) ⇒ Object
Constructor Details
#initialize(conn_string) ⇒ Client
Returns a new instance of Client.
13 14 15 16 |
# File 'lib/eventstore/client.rb', line 13 def initialize conn_string @conn_string = conn_string @uuid_gen = Cql::TimeUuid::Generator.new end |
Instance Method Details
#read_events(stream, read_count = 20) ⇒ Object
34 35 36 |
# 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) ⇒ Object
38 39 40 41 |
# 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) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |