Class: EventStoreClient::HTTP::Commands::Streams::Append

Inherits:
Command
  • Object
show all
Includes:
Configuration
Defined in:
lib/event_store_client/adapters/http/commands/streams/append.rb

Instance Method Summary collapse

Methods included from Configuration

#config

Methods inherited from Command

inherited

Instance Method Details

#call(stream_name, events, options: {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/event_store_client/adapters/http/commands/streams/append.rb', line 10

def call(stream_name, events, options: {})
  expected_version = options[:expected_version]
  serialized_events = events.map { |event| config.mapper.serialize(event) }
  headers = {
    'ES-ExpectedVersion' => expected_version&.to_s
  }.reject { |_key, val| val.nil? || val.empty? }

  data = build_events_data(serialized_events)
  response =
    connection.call(:post, "/streams/#{stream_name}", body: data, headers: headers)
  validate_response(response, expected_version)
end