Class: OnyxMesh::Feed
- Inherits:
-
ResponseObject
- Object
- ResponseObject
- OnyxMesh::Feed
- Defined in:
- lib/onyx_mesh/feed.rb
Defined Under Namespace
Classes: ClientModule, Query
Instance Attribute Summary collapse
-
#cursor ⇒ String
readonly
The position where the next call to consume should begin.
-
#filter ⇒ String
readonly
The query filter used to select matching items.
-
#filter_params ⇒ Array<String|Integer>
readonly
A list of values that will be interpolated into the filter expression.
-
#id ⇒ String
readonly
Unique feed identifier.
-
#type ⇒ String
readonly
Type of feed, "action" or "transaction".
Instance Method Summary collapse
-
#ack ⇒ void
Ack ("acknowledge") saves a feed's position so that a future call to consume picks up where the last one left off.
-
#consume {|object| ... } ⇒ void
Consume yields successive items in a feed, waiting until at least one is available (or the call times out).
-
#initialize(raw_attribs, base_session) ⇒ Feed
constructor
A new instance of Feed.
Constructor Details
#initialize(raw_attribs, base_session) ⇒ Feed
Returns a new instance of Feed.
37 38 39 40 41 42 43 |
# File 'lib/onyx_mesh/feed.rb', line 37 def initialize(raw_attribs, base_session) super(raw_attribs) # The consume/ack cycle should run on its own thread, so make a copy of # the base connection so this feed has an exclusive HTTP connection. @consume_session = base_session.dup end |
Instance Attribute Details
#cursor ⇒ String (readonly)
The position where the next call to consume should begin.
35 |
# File 'lib/onyx_mesh/feed.rb', line 35 attrib :cursor |
#filter ⇒ String (readonly)
The query filter used to select matching items.
25 |
# File 'lib/onyx_mesh/feed.rb', line 25 attrib :filter |
#filter_params ⇒ Array<String|Integer> (readonly)
A list of values that will be interpolated into the filter expression.
30 |
# File 'lib/onyx_mesh/feed.rb', line 30 attrib :filter_params |
#id ⇒ String (readonly)
Unique feed identifier.
15 |
# File 'lib/onyx_mesh/feed.rb', line 15 attrib :id |
#type ⇒ String (readonly)
Type of feed, "action" or "transaction".
20 |
# File 'lib/onyx_mesh/feed.rb', line 20 attrib :type |
Instance Method Details
#ack ⇒ void
This method returns an undefined value.
Ack ("acknowledge") saves a feed's position so that a future call to consume picks up where the last one left off. Without ack, some of the same items may be redelivered by consume. Consume does its own internal acks from time to time.
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/onyx_mesh/feed.rb', line 71 def ack if @next_cursor @consume_session.request( 'ack-feed', id: id, cursor: @next_cursor, previous_cursor: cursor, ) self.cursor = @next_cursor @next_cursor = nil end end |
#consume {|object| ... } ⇒ void
This method returns an undefined value.
Consume yields successive items in a feed, waiting until at least one is available (or the call times out). Since it waits it may be desirable to call consume in its own thread.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/onyx_mesh/feed.rb', line 51 def consume loop do page = @consume_session.request('stream-feed-items', id: id) page['items'].each_with_index do |item, index| @next_cursor = page['cursors'][index] if type == 'action' yield Action.new(item) else yield Transaction.new(item) end end end end |