Class: Mastodon::Streaming::Client
- Defined in:
- lib/mastodon/streaming/client.rb
Overview
Streaming client class, to handle all streaming purposes.
Constant Summary
Constants inherited from Client
Instance Attribute Summary collapse
-
#connection ⇒ Object
writeonly
Sets the attribute connection.
Attributes inherited from Client
#base_url, #bearer_token, #timeout
Instance Method Summary collapse
-
#before_request(&block) ⇒ Object
Set a Proc to be run when connection established.
-
#direct(options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Returns direct messages for the authenticated user.
-
#firehose(options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Returns all public statuses.
-
#hashtag(tag, options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Returns statuses that contain the specified hashtag.
-
#initialize(options = {}) ⇒ Mastodon::Streaming::Client
constructor
Initializes a new Client object.
-
#list(id, options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Returns statuses from the specified list.
-
#local(options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Streams posts from the local instance.
-
#local_hashtag(tag, options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Returns local statuses that contain the specified hashtag.
-
#stream(path, options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Calls an arbitrary streaming endpoint and returns the results Mastodon::Streaming::DeletedStatus] A stream of Mastodon objects.
-
#user(options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Streams messages for a single user.
Methods inherited from Client
Constructor Details
#initialize(options = {}) ⇒ Mastodon::Streaming::Client
Initializes a new Client object
24 25 26 27 28 |
# File 'lib/mastodon/streaming/client.rb', line 24 def initialize( = {}) super [:using_ssl] ||= base_url =~ /^https/ @connection = Streaming::Connection.new() end |
Instance Attribute Details
#connection=(value) ⇒ Object (writeonly)
Sets the attribute connection
14 15 16 |
# File 'lib/mastodon/streaming/client.rb', line 14 def connection=(value) @connection = value end |
Instance Method Details
#before_request(&block) ⇒ Object
Set a Proc to be run when connection established.
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/mastodon/streaming/client.rb', line 98 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::Status, Mastodon::Notification, | ... } ⇒ Object
Returns direct messages for the authenticated user
Mastodon::Streaming::DeletedStatus] A stream of Mastodon objects.
77 78 79 |
# File 'lib/mastodon/streaming/client.rb', line 77 def direct( = {}, &block) stream('direct', , &block) end |
#firehose(options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Returns all public statuses
Mastodon::Streaming::DeletedStatus] A stream of Mastodon objects.
85 86 87 |
# File 'lib/mastodon/streaming/client.rb', line 85 def firehose( = {}, &block) stream('public', , &block) end |
#hashtag(tag, options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Returns statuses that contain the specified hashtag
Mastodon::Streaming::DeletedStatus] A stream of Mastodon objects.
50 51 52 53 |
# File 'lib/mastodon/streaming/client.rb', line 50 def hashtag(tag, = {}, &block) ['tag'] = tag stream('hashtag', , &block) end |
#list(id, options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Returns statuses from the specified list
Mastodon::Streaming::DeletedStatus] A stream of Mastodon objects.
68 69 70 71 |
# File 'lib/mastodon/streaming/client.rb', line 68 def list(id, = {}, &block) ['list'] = id stream('list', , &block) end |
#local(options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Streams posts from the local instance
Mastodon::Streaming::DeletedStatus] A stream of Mastodon objects.
42 43 44 |
# File 'lib/mastodon/streaming/client.rb', line 42 def local( = {}, &block) stream('public/local', , &block) end |
#local_hashtag(tag, options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Returns local statuses that contain the specified hashtag
Mastodon::Streaming::DeletedStatus] A stream of Mastodon objects.
59 60 61 62 |
# File 'lib/mastodon/streaming/client.rb', line 59 def local_hashtag(tag, = {}, &block) ['tag'] = tag stream('hashtag/local', , &block) end |
#stream(path, options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Calls an arbitrary streaming endpoint and returns the results Mastodon::Streaming::DeletedStatus] A stream of Mastodon objects.
93 94 95 |
# File 'lib/mastodon/streaming/client.rb', line 93 def stream(path, = {}, &block) request(:get, "/api/v1/streaming/#{path}", , &block) end |
#user(options = {}) {|Mastodon::Status, Mastodon::Notification, | ... } ⇒ Object
Streams messages for a single user
Mastodon::Streaming::DeletedStatus] A stream of Mastodon objects.
34 35 36 |
# File 'lib/mastodon/streaming/client.rb', line 34 def user( = {}, &block) stream('user', , &block) end |