Module: Elephrame::TimelineWatcher

Included in:
Bots::Watcher
Defined in:
lib/elephrame/streaming/watcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



3
4
5
# File 'lib/elephrame/streaming/watcher.rb', line 3

def endpoint
  @endpoint
end

Instance Method Details

#run_watcher(&block) ⇒ Object Also known as: run



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/elephrame/streaming/watcher.rb', line 20

def run_watcher &block
  @streamer.send(@endpoint,
                 @endpoint_arg) do |post|
    next if post.kind_of? Mastodon::Notification or
            post.kind_of? Mastodon::Streaming::DeletedStatus
    
    # this makes it so .content calls strip instead 
    post.class.module_eval { alias_method :content, :strip } if @strip_html
    
    block.call(self, post)
  end
end

#setup_watcher(timeline, arg = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/elephrame/streaming/watcher.rb', line 5

def setup_watcher(timeline, arg = nil)

  @endpoint = format_tl(timeline)

  raise 'list or tag not supplied' if endpoint_needs_arg? and arg.nil?
  @endpoint_arg = arg

  # does some heavy lifting so the developer
  #  doesn't need to know the ID of the list
  @endpoint_arg = fetch_list_id(arg) if @endpoint == 'list'

  # in case the the argument contains an actual hash symbol
  @endpoint_arg.gsub!('#', '') if @endpoint =~ /tag/
end