Class: Slack::RealTime::Client
- Inherits:
-
Object
- Object
- Slack::RealTime::Client
- Includes:
- Api::Message, Api::MessageId, Api::Ping, Api::Typing
- Defined in:
- lib/slack/real_time/client.rb
Defined Under Namespace
Classes: ClientAlreadyStartedError, ClientNotStartedError
Class Attribute Summary collapse
-
.events ⇒ Object
Returns the value of attribute events.
Instance Attribute Summary collapse
-
#store ⇒ Object
Returns the value of attribute store.
-
#url ⇒ Object
Returns the value of attribute url.
-
#web_client ⇒ Object
Returns the value of attribute web_client.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #on(type, &block) ⇒ Object
-
#start! {|driver| ... } ⇒ Object
Start RealTime client and block until it disconnects.
-
#start_async {|driver| ... } ⇒ Object
Start RealTime client and return immediately.
- #started? ⇒ Boolean
- #stop! ⇒ Object
Methods included from Api::Typing
Methods included from Api::Message
Methods included from Api::Ping
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
23 24 25 26 27 28 29 30 31 |
# File 'lib/slack/real_time/client.rb', line 23 def initialize( = {}) @callbacks = Hash.new { |h, k| h[k] = [] } Slack::RealTime::Config::ATTRIBUTES.each do |key| send("#{key}=", [key] || Slack::RealTime.config.send(key)) end @store_class = .key?(:store_class) ? [:store_class] : Slack::RealTime::Store @token ||= Slack.config.token @web_client = Slack::Web::Client.new(token: token) end |
Class Attribute Details
.events ⇒ Object
Returns the value of attribute events.
15 16 17 |
# File 'lib/slack/real_time/client.rb', line 15 def events @events end |
Instance Attribute Details
#store ⇒ Object
Returns the value of attribute store.
19 20 21 |
# File 'lib/slack/real_time/client.rb', line 19 def store @store end |
#url ⇒ Object
Returns the value of attribute url.
20 21 22 |
# File 'lib/slack/real_time/client.rb', line 20 def url @url end |
#web_client ⇒ Object
Returns the value of attribute web_client.
18 19 20 |
# File 'lib/slack/real_time/client.rb', line 18 def web_client @web_client end |
Class Method Details
.config ⇒ Object
73 74 75 |
# File 'lib/slack/real_time/client.rb', line 73 def config Config end |
.configure ⇒ Object
69 70 71 |
# File 'lib/slack/real_time/client.rb', line 69 def configure block_given? ? yield(config) : config end |
Instance Method Details
#on(type, &block) ⇒ Object
39 40 41 42 |
# File 'lib/slack/real_time/client.rb', line 39 def on(type, &block) type = type.to_s callbacks[type] << block end |
#start! {|driver| ... } ⇒ Object
Start RealTime client and block until it disconnects.
46 47 48 49 |
# File 'lib/slack/real_time/client.rb', line 46 def start!(&block) socket = build_socket socket.start_sync { run_loop(socket, &block) } end |
#start_async {|driver| ... } ⇒ Object
Start RealTime client and return immediately. The RealTime::Client will run in the background.
54 55 56 57 |
# File 'lib/slack/real_time/client.rb', line 54 def start_async(&block) socket = build_socket socket.start_async { run_loop(socket, &block) } end |
#started? ⇒ Boolean
64 65 66 |
# File 'lib/slack/real_time/client.rb', line 64 def started? @socket && @socket.connected? end |
#stop! ⇒ Object
59 60 61 62 |
# File 'lib/slack/real_time/client.rb', line 59 def stop! fail ClientNotStartedError unless started? @socket.disconnect! if @socket end |