es-http-client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.rubocop.yml +8 -0
- data/.ruby-version +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +84 -0
- data/Guardfile +13 -0
- data/LICENSE +21 -0
- data/README.md +52 -0
- data/es-http-client.gemspec +24 -0
- data/lib/es_http_client.rb +27 -0
- data/lib/es_http_client/caught_up_stream.rb +32 -0
- data/lib/es_http_client/client.rb +22 -0
- data/lib/es_http_client/connection.rb +58 -0
- data/lib/es_http_client/error_handler.rb +15 -0
- data/lib/es_http_client/es_http_client_error.rb +14 -0
- data/lib/es_http_client/event.rb +24 -0
- data/lib/es_http_client/page.rb +39 -0
- data/lib/es_http_client/readonly_stream.rb +22 -0
- data/lib/es_http_client/ref.rb +11 -0
- data/lib/es_http_client/stream_events.rb +41 -0
- data/lib/es_http_client/writeable_stream.rb +41 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 96beb2009b1bb63cfc65f17f652c828541290e16
|
4
|
+
data.tar.gz: a4e96f7f8f7c264fe05728fd3c6d0b1398a6204c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a2901d97560b14975dae589d656bd1a2bc5660c1b0bb2b2f42047c0de0ea2fa521bfe33d383d728bf59750c05d39e3eb6de2d3c90623e15e7a359e0f12df506
|
7
|
+
data.tar.gz: 13acf122a54d600287869df41ca1d7789f64f0d1a28c720863a96f5e37228767e12c7299e279871241cd1d5d3bdc6d363d378d164b49480ad459d563f8d72796
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coderay (1.1.1)
|
5
|
+
diff-lcs (1.3)
|
6
|
+
faraday (0.11.0)
|
7
|
+
multipart-post (>= 1.2, < 3)
|
8
|
+
faraday_middleware (0.11.0.1)
|
9
|
+
faraday (>= 0.7.4, < 1.0)
|
10
|
+
ffi (1.9.18)
|
11
|
+
formatador (0.2.5)
|
12
|
+
guard (2.14.1)
|
13
|
+
formatador (>= 0.2.4)
|
14
|
+
listen (>= 2.7, < 4.0)
|
15
|
+
lumberjack (~> 1.0)
|
16
|
+
nenv (~> 0.1)
|
17
|
+
notiffany (~> 0.0)
|
18
|
+
pry (>= 0.9.12)
|
19
|
+
shellany (~> 0.0)
|
20
|
+
thor (>= 0.18.1)
|
21
|
+
guard-compat (1.2.1)
|
22
|
+
guard-rspec (4.7.3)
|
23
|
+
guard (~> 2.1)
|
24
|
+
guard-compat (~> 1.1)
|
25
|
+
rspec (>= 2.99.0, < 4.0)
|
26
|
+
hashie (3.5.5)
|
27
|
+
json (2.0.3)
|
28
|
+
listen (3.1.5)
|
29
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
30
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
31
|
+
ruby_dep (~> 1.2)
|
32
|
+
lumberjack (1.0.11)
|
33
|
+
method_source (0.8.2)
|
34
|
+
multipart-post (2.0.0)
|
35
|
+
nenv (0.3.0)
|
36
|
+
notiffany (0.1.1)
|
37
|
+
nenv (~> 0.1)
|
38
|
+
shellany (~> 0.0)
|
39
|
+
pry (0.10.4)
|
40
|
+
coderay (~> 1.1.0)
|
41
|
+
method_source (~> 0.8.1)
|
42
|
+
slop (~> 3.4)
|
43
|
+
rake (12.0.0)
|
44
|
+
rb-fsevent (0.9.8)
|
45
|
+
rb-inotify (0.9.8)
|
46
|
+
ffi (>= 0.5.0)
|
47
|
+
rspec (3.5.0)
|
48
|
+
rspec-core (~> 3.5.0)
|
49
|
+
rspec-expectations (~> 3.5.0)
|
50
|
+
rspec-mocks (~> 3.5.0)
|
51
|
+
rspec-core (3.5.4)
|
52
|
+
rspec-support (~> 3.5.0)
|
53
|
+
rspec-expectations (3.5.0)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.5.0)
|
56
|
+
rspec-mocks (3.5.0)
|
57
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
+
rspec-support (~> 3.5.0)
|
59
|
+
rspec-support (3.5.0)
|
60
|
+
ruby_dep (1.5.0)
|
61
|
+
shellany (0.0.1)
|
62
|
+
slop (3.6.0)
|
63
|
+
thor (0.19.4)
|
64
|
+
uuidtools (2.1.5)
|
65
|
+
|
66
|
+
PLATFORMS
|
67
|
+
ruby
|
68
|
+
|
69
|
+
DEPENDENCIES
|
70
|
+
faraday
|
71
|
+
faraday_middleware
|
72
|
+
guard
|
73
|
+
guard-rspec
|
74
|
+
hashie
|
75
|
+
json
|
76
|
+
rake
|
77
|
+
rspec
|
78
|
+
uuidtools
|
79
|
+
|
80
|
+
RUBY VERSION
|
81
|
+
ruby 2.4.0p0
|
82
|
+
|
83
|
+
BUNDLED WITH
|
84
|
+
1.13.7
|
data/Guardfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
directories %w(lib spec) \
|
2
|
+
.select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
3
|
+
|
4
|
+
guard :rspec, cmd: "bundle exec rspec", all_on_start: true, first_match: true do
|
5
|
+
require "guard/rspec/dsl"
|
6
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
7
|
+
|
8
|
+
# RSpec files
|
9
|
+
rspec = dsl.rspec
|
10
|
+
watch(rspec.spec_files)
|
11
|
+
watch(%r{^spec/.+\.rb$}) { rspec.spec_dir }
|
12
|
+
watch(%r{^lib/.+\.rb$}) { rspec.spec_dir }
|
13
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Kevin Rutherford
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# es-http-client
|
2
|
+
A Ruby HTTP client for EventStore
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Install the gem
|
7
|
+
|
8
|
+
```
|
9
|
+
gem install es-http-client
|
10
|
+
```
|
11
|
+
|
12
|
+
Or add it to your Gemfile and run `bundle`.
|
13
|
+
|
14
|
+
``` ruby
|
15
|
+
gem 'es-http-client'
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Open a connection to EventStore:
|
21
|
+
```ruby
|
22
|
+
eventstore = EsHttpClient.connect('http://localhost:2113', 'admin', 'changeit')
|
23
|
+
```
|
24
|
+
|
25
|
+
Subscribe to `$all`:
|
26
|
+
|
27
|
+
``` ruby
|
28
|
+
stream = eventstore.all_events
|
29
|
+
stream = stream.replay_forward {|event| ... }
|
30
|
+
stream.subscribe {|event| ... }
|
31
|
+
```
|
32
|
+
|
33
|
+
Write to a stream:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
stream = eventstore.stream(:user, user_id)
|
37
|
+
return 404 unless stream.exists?
|
38
|
+
stream_version = -1
|
39
|
+
stream.replay_forward do |event|
|
40
|
+
if event.type == 'UserAccountClosed'
|
41
|
+
return [410, JSON.pretty_generate({
|
42
|
+
errors: 'User account already closed'
|
43
|
+
})]
|
44
|
+
end
|
45
|
+
stream_version = event.number
|
46
|
+
end
|
47
|
+
return [400, JSON.pretty_generate({
|
48
|
+
errors: "Stream #{stream} unexpectedly empty"
|
49
|
+
})] if stream_version < 0
|
50
|
+
event = EsHttpClient.create_event('UserAccountClosed', { userId: user_id })
|
51
|
+
stream.append(event, stream_version) ? 200 : 409
|
52
|
+
```
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'es-http-client'
|
5
|
+
spec.version = '0.1.0'
|
6
|
+
spec.licenses = ['MIT']
|
7
|
+
spec.authors = ['Kevin Rutherford']
|
8
|
+
spec.email = ['kevin@rutherford-software.com']
|
9
|
+
|
10
|
+
spec.summary = %q{A simple HTTP client for EventStore}
|
11
|
+
spec.description = %q{A simple HTTP client for EventStore}
|
12
|
+
spec.homepage = "https://github.com/kevinrutherford/es-http-client"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
|
15
|
+
spec.require_paths = ['lib']
|
16
|
+
|
17
|
+
spec.add_development_dependency 'rspec', '3.5.0'
|
18
|
+
|
19
|
+
spec.add_dependency 'faraday', '0.11.0'
|
20
|
+
spec.add_dependency 'faraday_middleware', '0.11.0.1'
|
21
|
+
spec.add_dependency 'json', '2.0.3'
|
22
|
+
spec.add_dependency 'hashie', '3.5.5'
|
23
|
+
spec.add_dependency 'uuidtools', '2.1.5'
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'uuidtools'
|
2
|
+
require_relative './es_http_client/client'
|
3
|
+
require_relative './es_http_client/connection'
|
4
|
+
require_relative './es_http_client/es_http_client_error'
|
5
|
+
|
6
|
+
module EsHttpClient
|
7
|
+
|
8
|
+
module ExpectedVersion
|
9
|
+
Any = -2
|
10
|
+
NoStream = -1
|
11
|
+
EmptyStream = -1
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.connect(endpoint, username, password)
|
15
|
+
Client.new(Connection.new(endpoint, username, password))
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.create_event(type, data)
|
19
|
+
id = UUIDTools::UUID.random_create.to_s
|
20
|
+
timestamp = Time.now.strftime('%FT%T.%3N%:z')
|
21
|
+
data = data.merge({
|
22
|
+
occurredAt: timestamp
|
23
|
+
})
|
24
|
+
Event.new(id, type, data, timestamp, 0)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative './event'
|
2
|
+
require_relative './page'
|
3
|
+
|
4
|
+
module EsHttpClient
|
5
|
+
|
6
|
+
class CaughtUpStream
|
7
|
+
|
8
|
+
def initialize(ref, connection)
|
9
|
+
@ref = ref
|
10
|
+
@connection = connection
|
11
|
+
end
|
12
|
+
|
13
|
+
def subscribe(&block)
|
14
|
+
loop do
|
15
|
+
sleep 1
|
16
|
+
@ref = fetch(@ref, &block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def fetch(ref, &block)
|
21
|
+
response = @connection.get(ref.uri, ref.etag)
|
22
|
+
page = Page.new(response.body)
|
23
|
+
next_uri = ref.uri
|
24
|
+
if page.has_entries?
|
25
|
+
page.each_event(&block)
|
26
|
+
next_uri = page.previous
|
27
|
+
end
|
28
|
+
return Ref.new(next_uri, response.headers['etag'])
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative './readonly_stream'
|
2
|
+
require_relative './writeable_stream'
|
3
|
+
|
4
|
+
module EsHttpClient
|
5
|
+
|
6
|
+
class Client
|
7
|
+
|
8
|
+
def initialize(connection)
|
9
|
+
@connection = connection
|
10
|
+
end
|
11
|
+
|
12
|
+
def stream(type, id)
|
13
|
+
WriteableStream.new("#{type}-#{id}", @connection)
|
14
|
+
end
|
15
|
+
|
16
|
+
def all_events
|
17
|
+
@all ||= ReadonlyStream.new("$all", @connection)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'json'
|
4
|
+
require 'base64'
|
5
|
+
require_relative './error_handler'
|
6
|
+
|
7
|
+
module EsHttpClient
|
8
|
+
|
9
|
+
class Connection
|
10
|
+
|
11
|
+
def initialize(endpoint, username=nil, password=nil)
|
12
|
+
STDERR.puts "Faraday connecting to #{endpoint}"
|
13
|
+
@connection = Faraday.new(url: endpoint) do |faraday|
|
14
|
+
faraday.request :retry, max: 4, interval: 0.05, interval_randomness: 0.5, backoff_factor: 2
|
15
|
+
faraday.response :json, content_type: 'application/json'
|
16
|
+
faraday.response :mashify
|
17
|
+
faraday.adapter Faraday.default_adapter
|
18
|
+
faraday.use ErrorHandler
|
19
|
+
end
|
20
|
+
@headers = {
|
21
|
+
'Accept' => 'application/json',
|
22
|
+
'Content-Type' => 'application/json'
|
23
|
+
}
|
24
|
+
if username && password
|
25
|
+
token = Base64.encode64("#{username}:#{password}")[0..-2]
|
26
|
+
@headers.merge!({ 'Authorization' => "Basic #{token}" })
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def get(uri, etag)
|
31
|
+
response = @connection.send(:get, uri) do |req|
|
32
|
+
req.headers = @headers
|
33
|
+
req.headers.merge({ 'If-None-Match' => etag, 'ES-LongPoll' => 10 }) if etag
|
34
|
+
req.body = {}.to_json
|
35
|
+
req.params['embed'] = 'body'
|
36
|
+
end
|
37
|
+
response
|
38
|
+
rescue EsHttpClientError => e
|
39
|
+
STDERR.puts "Faraday: Error response #{e}"
|
40
|
+
raise e
|
41
|
+
end
|
42
|
+
|
43
|
+
def post(uri, event, expected_version)
|
44
|
+
@connection.send(:post, uri) do |req|
|
45
|
+
req.headers = {
|
46
|
+
'Accept' => 'application/json',
|
47
|
+
'Content-Type' => 'application/json',
|
48
|
+
'ES-EventType' => event.type,
|
49
|
+
'ES-EventId' => event.id,
|
50
|
+
'ES-ExpectedVersion' => expected_version.to_s
|
51
|
+
}
|
52
|
+
req.body = event.data.to_json
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require_relative './es_http_client_error'
|
4
|
+
|
5
|
+
module EsHttpClient
|
6
|
+
|
7
|
+
class ErrorHandler < Faraday::Response::Middleware
|
8
|
+
|
9
|
+
def on_complete(env)
|
10
|
+
status = env[:status]
|
11
|
+
raise EsHttpClientError.new(status, env[:reason_phrase]) if status >= 400
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module EsHttpClient
|
2
|
+
|
3
|
+
class Event < Struct.new(:id, :type, :data, :updated, :number, :uri, :stream_id)
|
4
|
+
|
5
|
+
def self.load_from(hash)
|
6
|
+
return nil unless hash['data']
|
7
|
+
data = JSON.parse(hash['data'], symbolize_names: true)
|
8
|
+
event = Event.new(hash['eventId'], hash['eventType'], data, hash['updated'], hash['eventNumber'].to_i, hash['id'], hash['streamId'])
|
9
|
+
event
|
10
|
+
end
|
11
|
+
|
12
|
+
def occurred_at
|
13
|
+
data[:occurredAt]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def initialize(id, type, data, updated=nil, number=nil, uri=nil, stream_id=nil)
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module EsHttpClient
|
2
|
+
|
3
|
+
class Page
|
4
|
+
|
5
|
+
def initialize(body)
|
6
|
+
@body = body
|
7
|
+
end
|
8
|
+
|
9
|
+
def last
|
10
|
+
find_link('last')
|
11
|
+
end
|
12
|
+
|
13
|
+
def previous
|
14
|
+
find_link('previous')
|
15
|
+
end
|
16
|
+
|
17
|
+
def has_entries?
|
18
|
+
@body['entries'] && @body['entries'].length > 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def each_event(&block)
|
22
|
+
@body['entries']
|
23
|
+
.reverse!
|
24
|
+
.map {|e| Event.load_from(e)}
|
25
|
+
.compact
|
26
|
+
.select {|e| e.type !~ /^\$/ }
|
27
|
+
.each {|e| yield e }
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def find_link(rel)
|
33
|
+
link = @body['links'].detect { |l| l['relation'] == rel }
|
34
|
+
link.nil? ? nil : link['uri']
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative './stream_events'
|
2
|
+
require_relative './caught_up_stream'
|
3
|
+
require_relative './event'
|
4
|
+
require_relative './ref'
|
5
|
+
|
6
|
+
module EsHttpClient
|
7
|
+
|
8
|
+
class ReadonlyStream
|
9
|
+
|
10
|
+
def initialize(stream_name, connection)
|
11
|
+
@stream_name = stream_name
|
12
|
+
@connection = connection
|
13
|
+
end
|
14
|
+
|
15
|
+
def replay_forward(&block)
|
16
|
+
ref = StreamEvents.new(@stream_name, @connection).each(&block)
|
17
|
+
CaughtUpStream.new(ref, @connection)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative './page'
|
2
|
+
|
3
|
+
module EsHttpClient
|
4
|
+
|
5
|
+
class StreamEvents
|
6
|
+
|
7
|
+
def initialize(name, connection)
|
8
|
+
@connection = connection
|
9
|
+
@latest_ref = Ref.head_of(name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def each(&block)
|
13
|
+
page = read_stream_page(@latest_ref.uri)
|
14
|
+
last = page.last
|
15
|
+
page = read_stream_page(last) if last
|
16
|
+
loop do
|
17
|
+
break unless page.has_entries?
|
18
|
+
page.each_event(&block)
|
19
|
+
next_page = page.previous
|
20
|
+
break unless next_page
|
21
|
+
page = read_stream_page(next_page)
|
22
|
+
end
|
23
|
+
return @latest_ref
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def read_stream_page(uri)
|
29
|
+
response = @connection.get(uri, @latest_ref.etag)
|
30
|
+
@latest_ref = Ref.new(uri, response.headers['etag'])
|
31
|
+
Page.new(response.body)
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_link(links, rel)
|
35
|
+
link = links.detect { |l| l['relation'] == rel }
|
36
|
+
link.nil? ? nil : link['uri']
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative './stream_events'
|
2
|
+
require_relative './ref'
|
3
|
+
|
4
|
+
module EsHttpClient
|
5
|
+
|
6
|
+
class WriteableStream
|
7
|
+
|
8
|
+
def initialize(name, connection)
|
9
|
+
@stream_name = name
|
10
|
+
@connection = connection
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
@stream_name
|
15
|
+
end
|
16
|
+
|
17
|
+
def exists?
|
18
|
+
ref = Ref.head_of(@stream_name)
|
19
|
+
@connection.get(ref.uri, ref.etag)
|
20
|
+
true
|
21
|
+
rescue EsHttpClientError => e
|
22
|
+
return false if e.code == 404
|
23
|
+
raise e
|
24
|
+
end
|
25
|
+
|
26
|
+
def append(event, expected_version=ExpectedVersion::Any)
|
27
|
+
@connection.post(Ref.head_of(@stream_name).uri, event, expected_version)
|
28
|
+
true
|
29
|
+
rescue EsHttpClientError => e
|
30
|
+
STDERR.puts e.message
|
31
|
+
STDERR.puts e.backtrace
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
def replay_forward(&block)
|
36
|
+
StreamEvents.new(@stream_name, @connection).each(&block)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: es-http-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Rutherford
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.5.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.5.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.11.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.11.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.11.0.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.11.0.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.0.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.0.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hashie
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.5.5
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.5.5
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: uuidtools
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.1.5
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.1.5
|
97
|
+
description: A simple HTTP client for EventStore
|
98
|
+
email:
|
99
|
+
- kevin@rutherford-software.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".ruby-version"
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- Guardfile
|
111
|
+
- LICENSE
|
112
|
+
- README.md
|
113
|
+
- es-http-client.gemspec
|
114
|
+
- lib/es_http_client.rb
|
115
|
+
- lib/es_http_client/caught_up_stream.rb
|
116
|
+
- lib/es_http_client/client.rb
|
117
|
+
- lib/es_http_client/connection.rb
|
118
|
+
- lib/es_http_client/error_handler.rb
|
119
|
+
- lib/es_http_client/es_http_client_error.rb
|
120
|
+
- lib/es_http_client/event.rb
|
121
|
+
- lib/es_http_client/page.rb
|
122
|
+
- lib/es_http_client/readonly_stream.rb
|
123
|
+
- lib/es_http_client/ref.rb
|
124
|
+
- lib/es_http_client/stream_events.rb
|
125
|
+
- lib/es_http_client/writeable_stream.rb
|
126
|
+
homepage: https://github.com/kevinrutherford/es-http-client
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.6.8
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: A simple HTTP client for EventStore
|
150
|
+
test_files: []
|