Class: Mastodon::Streaming::Client

Inherits:
Client
  • Object
show all
Defined in:
lib/mastodon/streaming/client.rb

Constant Summary

Constants inherited from Client

Client::DEFAULT_TIMEOUT

Instance Attribute Summary collapse

Attributes inherited from Client

#base_url, #bearer_token, #timeout

Instance Method Summary collapse

Methods inherited from Client

#user_agent

Constructor Details

#initialize(options = {}) ⇒ Mastodon::Streaming::Client

Initializes a new Client object

Options Hash (options):

  • :tcp_socket_class (String)

    A class that Connection will use to create a new TCP socket.

  • :ssl_socket_class (String)

    A class that Connection will use to create a new SSL socket.


18
19
20
21
22
# File 'lib/mastodon/streaming/client.rb', line 18

def initialize(options = {})
  super
  options[:using_ssl] ||= base_url =~ /^https/
  @connection = Streaming::Connection.new(options)
end

Instance Attribute Details

#connection=(value) ⇒ Object (writeonly)

Sets the attribute connection


10
11
12
# File 'lib/mastodon/streaming/client.rb', line 10

def connection=(value)
  @connection = value
end

Instance Method Details

#before_request(&block) ⇒ Object

Set a Proc to be run when connection established.


60
61
62
63
64
65
66
67
68
69
# File 'lib/mastodon/streaming/client.rb', line 60

def before_request(&block)
  if block_given?
    @before_request = block
    self
  elsif instance_variable_defined?(:@before_request)
    @before_request
  else
    proc {}
  end
end

#direct(options = {}) {|Mastodon::Conversation| ... } ⇒ Object

Returns conversations for a single user

Yields:


48
49
50
# File 'lib/mastodon/streaming/client.rb', line 48

def direct(options = {}, &block)
  stream('direct', options, &block)
end

#hashtag(tag, options = {}) {|Mastodon::Status, Mastodon::Streaming::Events::StatusDelete| ... } ⇒ Object

Returns statuses that contain the specified hashtag

Yields:


34
35
36
# File 'lib/mastodon/streaming/client.rb', line 34

def hashtag(tag, options = {}, &block)
  stream('hashtag', { tag: tag }.merge(options), &block)
end

#public(options = {}) {|Mastodon::Status, Mastodon::Streaming::Events::StatusDelete| ... } ⇒ Object

Returns all public statuses

Yields:


41
42
43
# File 'lib/mastodon/streaming/client.rb', line 41

def public(options = {}, &block)
  stream('public', options, &block)
end

#stream(path, options = {}) {|Mastodon::Status, Mastodon::Notification, Mastodon::Streaming::DeletedStatus| ... } ⇒ Object

Calls an arbitrary streaming endpoint and returns the results

Yields:


55
56
57
# File 'lib/mastodon/streaming/client.rb', line 55

def stream(path, options = {}, &block)
  request(:get, "/api/v1/streaming/#{path}", options, &block)
end

#user(options = {}) {|Mastodon::Status, Mastodon::Notification, Mastodon::Streaming::Events::StatusDelete, Mastodon::Streaming::Events::FiltersChange| ... } ⇒ Object

Streams messages for a single user


27
28
29
# File 'lib/mastodon/streaming/client.rb', line 27

def user(options = {}, &block)
  stream('user', options, &block)
end