Class: RealtimeX
- Inherits:
-
Object
- Object
- RealtimeX
- Defined in:
- lib/realtimex.rb,
lib/realtimex/version.rb
Overview
RealtimeX Ruby SDK for real-time messaging
Defined Under Namespace
Classes: Channel, ChannelManager, Connection
Constant Summary collapse
- VERSION =
"2.0.3"
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#connect ⇒ Object
Establish WebSocket connection.
-
#disconnect ⇒ Object
Disconnect from WebSocket.
-
#initialize(api_key, options = {}) ⇒ RealtimeX
constructor
Initialize RealtimeX client.
-
#subscribe(channel_name) ⇒ RealtimeX::Channel
Subscribe to a channel.
Constructor Details
#initialize(api_key, options = {}) ⇒ RealtimeX
Initialize RealtimeX client
16 17 18 19 20 21 22 23 24 |
# File 'lib/realtimex.rb', line 16 def initialize(api_key, = {}) @api_key = api_key @options = .merge() @channel_manager = ChannelManager.new url = build_url @connection = RealtimeX::Connection.new(url, debug: @options[:debug]) setup_connection_handlers end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
8 9 10 |
# File 'lib/realtimex.rb', line 8 def connection @connection end |
Instance Method Details
#connect ⇒ Object
Establish WebSocket connection
27 28 29 |
# File 'lib/realtimex.rb', line 27 def connect @connection.connect end |
#disconnect ⇒ Object
Disconnect from WebSocket
44 45 46 |
# File 'lib/realtimex.rb', line 44 def disconnect @connection.disconnect end |
#subscribe(channel_name) ⇒ RealtimeX::Channel
Subscribe to a channel
34 35 36 37 38 39 40 41 |
# File 'lib/realtimex.rb', line 34 def subscribe(channel_name) existing = @channel_manager.get_existing(channel_name) return existing if existing channel = @channel_manager.create(channel_name, self) @connection.send_subscribe(channel_name) channel end |