10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/event_store_client/adapters/http/commands/streams/read.rb', line 10
def call(stream_name, options: {})
count = options[:count] || config.per_page
start = options[:start].to_i
direction = options[:direction] || 'forward'
= { 'Accept' => 'application/vnd.eventstore.atom+json' }
['ES-ResolveLinkTos'] = true if options.key?(:resolve_links)
response =
connection.call(
:get,
"/streams/#{stream_name}/#{start}/#{direction}/#{count}",
headers:
)
return Failure(:stream_not_found) unless response.success? || response.status == 404
return Failure(:connection_failed) if response.body.nil? || response.body.empty?
skip_decryption = options[:skip_decryption] || false
entries = JSON.parse(response.body)['entries'].map do |entry|
deserialize_event(entry, skip_decryption: skip_decryption)
end.reverse
Success(entries)
rescue Faraday::ConnectionFailed
Failure(:connection_failed)
end
|