0.0
No commit activity in last 3 years
No release in over 3 years
A simple HTTP client for EventStore
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.5

Runtime

~> 0.13
~> 3.5
~> 2.1
~> 2.1
 Project Readme

es-http-client

A Ruby HTTP client for EventStore

Installation

Install the gem

gem install es-http-client

Or add it to your Gemfile and run bundle.

gem 'es-http-client'

Usage

Open a connection to EventStore:

eventstore = EsHttpClient.connect('http://localhost:2113', 'admin', 'changeit')

Subscribe to $all:

stream = eventstore.all_events
stream = stream.replay_forward {|event| ... }
stream.subscribe {|event| ... }

Write to a stream:

stream = eventstore.stream(:user, user_id)
return 404 unless stream.exists?
stream_version = -1
stream.replay_forward do |event|
  if event.type == 'UserAccountClosed'
    return [410, JSON.pretty_generate({
      errors: 'User account already closed'
    })]
  end
  stream_version = event.number
end
return [400, JSON.pretty_generate({
  errors: "Stream #{stream} unexpectedly empty"
})] if stream_version < 0
event = EsHttpClient.create_event('UserAccountClosed', { userId:  user_id })
stream.append(event, stream_version) ? 200 : 409