Class: EventStore::HTTPClient::Events::Read
- Inherits:
-
Object
- Object
- EventStore::HTTPClient::Events::Read
- Defined in:
- lib/event_store_http_client/events/read.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#stream_name ⇒ Object
Returns the value of attribute stream_name.
Class Method Summary collapse
Instance Method Summary collapse
- #! ⇒ Object
-
#initialize(stream_name) ⇒ Read
constructor
A new instance of Read.
- #make_request ⇒ Object
Constructor Details
#initialize(stream_name) ⇒ Read
Returns a new instance of Read.
29 30 31 |
# File 'lib/event_store_http_client/events/read.rb', line 29 def initialize(stream_name) @stream_name = stream_name end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
7 8 9 |
# File 'lib/event_store_http_client/events/read.rb', line 7 def body @body end |
#stream_name ⇒ Object
Returns the value of attribute stream_name.
6 7 8 |
# File 'lib/event_store_http_client/events/read.rb', line 6 def stream_name @stream_name end |
Class Method Details
.!(params) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/event_store_http_client/events/read.rb', line 12 def self.!(params) instance = build(params) instance.! do |result| yield result end end |
.build(params) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/event_store_http_client/events/read.rb', line 19 def self.build(params) body = params[:body] stream_name = params[:stream_name] new(stream_name).tap do |instance| Logger.configure instance EventStore::HTTPClient::Client::Builder.configure instance end end |
Instance Method Details
#! ⇒ Object
33 34 35 36 37 |
# File 'lib/event_store_http_client/events/read.rb', line 33 def ! make_request do |result| yield result end end |
#make_request ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/event_store_http_client/events/read.rb', line 39 def make_request logger.debug "Making request to #{stream_name}" request = client.get("/streams/#{stream_name}?embed=body") do |resp| logger.debug "Response #{resp.status_code}" resp.body_handler do |body| status = resp.status_code == 200 ? :success : :error yield({ status: status, status_code: resp.status_code, body: body.to_s}) end end request.put_header('Accept', 'application/vnd.eventstore.atom+json') request.put_header('Content-Type', 'application/json') request.exception_handler { |e| logger.error "Failed to read, trying again" Vertx.set_timer(rand(1000)) do make_request do |result| yield result end end } request.end end |