Class: EventStoreClient::HTTP::Commands::Streams::LinkTo

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

Instance Method Summary collapse

Methods inherited from Command

inherited

Instance Method Details

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



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

def call(stream_name, events, options: {})
  expected_version = options[:expected_version]
  data = build_linking_data(events)
  headers = {
    'ES-ExpectedVersion' => expected_version&.to_s
  }.reject { |_key, val| val.nil? || val.empty? }

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