realtimex 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 248492f88d791add118caa113b362ba09278d11a0dca554adc605f797146c2bd
4
+ data.tar.gz: 4014a8f1e9476b8c88ce36235444f36110c793585ea06ac8b1bed6abecc113b1
5
+ SHA512:
6
+ metadata.gz: 5e5b7ebff0ddca610032838935773e8e68f680772c922ac4fdf5c0228dfaeab968ea073dddc7d1dc2d2fda136db0f747f2f7c381b7707718a37a40f929d5991c
7
+ data.tar.gz: a154dbde5fb2fb30f686fd912d9a19a0655d345ceffa104310088e367d71c943aaac403b63f37dbdd48ef8867bbe25f7faa1530b47405982593633d7eb960b23
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 RealtimeX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # RealtimeX Ruby SDK
2
+
3
+ Ruby client library for RealtimeX real-time messaging service.
4
+
5
+ ## Installation
6
+
7
+ ### Gemfile
8
+ ```ruby
9
+ gem 'socketio-client-simple', '~> 1.2'
10
+ gem 'json', '~> 2.0'
11
+ ```
12
+
13
+ ### Manual
14
+ ```bash
15
+ gem install socketio-client-simple json
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ```ruby
21
+ require_relative 'lib/realtimex'
22
+
23
+ # Initialize
24
+ realtimex = RealtimeX.new('YOUR_API_KEY', {
25
+ ws_host: 'localhost',
26
+ ws_port: 3001,
27
+ encrypted: false
28
+ })
29
+
30
+ # Connect
31
+ realtimex.connect
32
+
33
+ # Subscribe to a channel
34
+ channel = realtimex.subscribe('my-channel')
35
+
36
+ # Listen for events
37
+ channel.bind('my-event') do |data|
38
+ puts "Received: #{data}"
39
+ end
40
+
41
+ # Send client events
42
+ channel.trigger('client-my-event', {
43
+ message: 'Hello'
44
+ })
45
+ ```
46
+
47
+ ## API Reference
48
+
49
+ ### RealtimeX
50
+
51
+ #### Constructor
52
+ ```ruby
53
+ realtimex = RealtimeX.new(api_key, options)
54
+ ```
55
+
56
+ **Parameters:**
57
+ - `api_key` (String): Your RealtimeX API key
58
+ - `options` (Hash, optional): Configuration options
59
+ - `:ws_host` (String): WebSocket host, default 'localhost'
60
+ - `:ws_port` (Integer): WebSocket port, default 3001
61
+ - `:encrypted` (Boolean): Use WSS, default false
62
+
63
+ #### Methods
64
+
65
+ **connect**
66
+ ```ruby
67
+ realtimex.connect
68
+ ```
69
+
70
+ **subscribe(channel_name)**
71
+ ```ruby
72
+ channel = realtimex.subscribe('my-channel')
73
+ private_channel = realtimex.subscribe('private-my-channel')
74
+ ```
75
+
76
+ **disconnect**
77
+ ```ruby
78
+ realtimex.disconnect
79
+ ```
80
+
81
+ ### Channel
82
+
83
+ #### Methods
84
+
85
+ **bind(event, &block)**
86
+ ```ruby
87
+ channel.bind('my-event') do |data|
88
+ puts "Event data: #{data}"
89
+ end
90
+ ```
91
+
92
+ **trigger(event, data)**
93
+ ```ruby
94
+ # Client events must start with 'client-'
95
+ channel.trigger('client-my-event', {
96
+ message: 'Hello World'
97
+ })
98
+ ```
99
+
100
+ ### Connection Events
101
+
102
+ ```ruby
103
+ realtimex.connection.bind('connected') do
104
+ puts 'Connected to RealtimeX'
105
+ end
106
+
107
+ realtimex.connection.bind('disconnected') do
108
+ puts 'Disconnected from RealtimeX'
109
+ end
110
+ ```
111
+
112
+ ## Channel Types
113
+
114
+ ### Public Channels
115
+ ```ruby
116
+ channel = realtimex.subscribe('my-channel')
117
+ ```
118
+
119
+ ### Private Channels
120
+ ```ruby
121
+ private_channel = realtimex.subscribe('private-my-channel')
122
+ ```
123
+
124
+ ## WebSocket Protocol
125
+
126
+ ### Connection
127
+ ```
128
+ ws://your-host:port/socket.io/?EIO=4&transport=websocket&api_key=YOUR_API_KEY
129
+ ```
130
+
131
+ ### Message Format
132
+
133
+ **Subscribe:**
134
+ ```json
135
+ {
136
+ "event": "realtimex:subscribe",
137
+ "data": {
138
+ "channel": "my-channel"
139
+ }
140
+ }
141
+ ```
142
+
143
+ **Client Event:**
144
+ ```json
145
+ {
146
+ "event": "client-event",
147
+ "data": {
148
+ "channel": "my-channel",
149
+ "event": "client-my-event",
150
+ "data": { "message": "Hello" }
151
+ }
152
+ }
153
+ ```
154
+
155
+ **Server Event:**
156
+ ```json
157
+ {
158
+ "event": "server-event",
159
+ "data": {
160
+ "event": "my-event",
161
+ "channel": "my-channel",
162
+ "data": { "message": "Hello" }
163
+ }
164
+ }
165
+ ```
166
+
167
+ ## Compatibility
168
+
169
+ ### Ruby Support
170
+ - Ruby 2.7+
171
+ - JRuby 9.3+
172
+ - TruffleRuby 22+
173
+
174
+ ### Dependencies
175
+ - `socketio-client-simple` ~> 1.2
176
+ - `json` ~> 2.0
177
+
178
+ ## Features
179
+
180
+ ✅ WebSocket connection management
181
+ ✅ Channel subscription/unsubscription
182
+ ✅ Event listening and triggering
183
+ ✅ Client events
184
+ ✅ YARD documentation
185
+ ✅ Unit tests with RSpec
186
+
187
+ ## Development
188
+
189
+ ```bash
190
+ # Install dependencies
191
+ bundle install
192
+
193
+ # Run tests
194
+ bundle exec rspec
195
+
196
+ # Generate documentation
197
+ yardoc
198
+ ```
199
+
200
+ ## License
201
+
202
+ MIT
@@ -0,0 +1,29 @@
1
+ # Channel for handling real-time events
2
+ class RealtimeX::Channel
3
+ attr_reader :name
4
+
5
+ def initialize(name, client)
6
+ @name = name
7
+ @client = client
8
+ @callbacks = {}
9
+ end
10
+
11
+ # Send client event to channel
12
+ # @param event [String] Event name (must start with 'client-')
13
+ # @param data [Hash] Event data
14
+ def trigger(event, data)
15
+ raise "Event must start with 'client-'" unless event.start_with?('client-')
16
+ @client.connection.send_client_event(@name, event, data)
17
+ end
18
+
19
+ # Bind callback to event
20
+ # @param event [String] Event name to listen for
21
+ # @param block [Proc] Callback to execute
22
+ def bind(event, &block)
23
+ @callbacks[event] = block
24
+ end
25
+
26
+ def handle_event(event, data)
27
+ @callbacks[event]&.call(data)
28
+ end
29
+ end
@@ -0,0 +1,24 @@
1
+ # Manages channel subscriptions and message routing
2
+ class RealtimeX::ChannelManager
3
+ def initialize
4
+ @channels = {}
5
+ end
6
+
7
+ def get_existing(channel_name)
8
+ @channels[channel_name]
9
+ end
10
+
11
+ def create(channel_name, client)
12
+ channel = RealtimeX::Channel.new(channel_name, client)
13
+ @channels[channel_name] = channel
14
+ channel
15
+ end
16
+
17
+ def route_message(message)
18
+ channel_name = message['channel']
19
+ event = message['event']
20
+ data = message['data']
21
+
22
+ @channels[channel_name]&.handle_event(event, data)
23
+ end
24
+ end
@@ -0,0 +1,60 @@
1
+ require 'socket.io-client-simple'
2
+
3
+ class RealtimeX::Connection
4
+ def initialize(url)
5
+ @url = url
6
+ @socket = nil
7
+ @callbacks = {}
8
+ end
9
+
10
+ def connect
11
+ @socket = SocketIO::Client::Simple.connect(@url, transports: ['websocket'])
12
+ setup_handlers
13
+ end
14
+
15
+ def setup_handlers
16
+ @socket.on :connect do
17
+ emit('connected')
18
+ end
19
+
20
+ @socket.on :disconnect do
21
+ emit('disconnected')
22
+ end
23
+
24
+ @socket.on 'server-event' do |data|
25
+ emit('message', data)
26
+ end
27
+
28
+ @socket.on 'realtimex_internal:subscription_succeeded' do |data|
29
+ emit('subscription_succeeded', data)
30
+ end
31
+ end
32
+
33
+ def send_subscribe(channel)
34
+ @socket.emit('realtimex:subscribe', { channel: channel })
35
+ end
36
+
37
+ def send_client_event(channel, event, data)
38
+ @socket.emit('client-event', {
39
+ channel: channel,
40
+ event: event,
41
+ data: data
42
+ })
43
+ end
44
+
45
+ def send_unsubscribe(channel)
46
+ @socket.emit('realtimex:unsubscribe', { channel: channel })
47
+ end
48
+
49
+ def bind(event, &block)
50
+ @callbacks[event] = block
51
+ end
52
+
53
+ def emit(event, data = nil)
54
+ @callbacks[event]&.call(data)
55
+ end
56
+
57
+ def disconnect
58
+ @socket&.disconnect
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ class RealtimeX
2
+ VERSION = "1.0.1"
3
+ end
data/lib/realtimex.rb ADDED
@@ -0,0 +1,74 @@
1
+ require_relative 'realtimex/version'
2
+ require_relative 'realtimex/connection'
3
+ require_relative 'realtimex/channel'
4
+ require_relative 'realtimex/channel_manager'
5
+
6
+ # RealtimeX Ruby SDK for real-time messaging
7
+ class RealtimeX
8
+ attr_reader :connection
9
+
10
+ # Initialize RealtimeX client
11
+ # @param api_key [String] API key for authentication
12
+ # @param options [Hash] Connection options
13
+ # @option options [String] :ws_host WebSocket host (default: 'localhost')
14
+ # @option options [Integer] :ws_port WebSocket port (default: 3001)
15
+ # @option options [Boolean] :encrypted Use HTTPS/WSS (default: false)
16
+ def initialize(api_key, options = {})
17
+ @api_key = api_key
18
+ @options = default_options.merge(options)
19
+ @channel_manager = ChannelManager.new
20
+
21
+ url = build_url
22
+ @connection = RealtimeX::Connection.new(url)
23
+ setup_connection_handlers
24
+ end
25
+
26
+ # Establish WebSocket connection
27
+ def connect
28
+ @connection.connect
29
+ end
30
+
31
+ # Subscribe to a channel
32
+ # @param channel_name [String] Channel name to subscribe to
33
+ # @return [RealtimeX::Channel] Channel instance
34
+ def subscribe(channel_name)
35
+ existing = @channel_manager.get_existing(channel_name)
36
+ return existing if existing
37
+
38
+ channel = @channel_manager.create(channel_name, self)
39
+ @connection.send_subscribe(channel_name)
40
+ channel
41
+ end
42
+
43
+ # Disconnect from WebSocket
44
+ def disconnect
45
+ @connection.disconnect
46
+ end
47
+
48
+ private
49
+
50
+ def default_options
51
+ {
52
+ ws_host: 'localhost',
53
+ ws_port: 3001,
54
+ encrypted: false
55
+ }
56
+ end
57
+
58
+ def build_url
59
+ protocol = @options[:encrypted] ? 'https' : 'http'
60
+ host = @options[:ws_host]
61
+ port = @options[:ws_port]
62
+ "#{protocol}://#{host}:#{port}/socket.io/?EIO=4&transport=websocket&api_key=#{@api_key}"
63
+ end
64
+
65
+ def setup_connection_handlers
66
+ @connection.bind('message') do |data|
67
+ route_to_channel(data)
68
+ end
69
+ end
70
+
71
+ def route_to_channel(message)
72
+ @channel_manager.route_message(message)
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: realtimex
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - RealtimeX Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-12-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: socket.io-client-simple
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: RealtimeX Ruby SDK provides WebSocket-based real-time messaging with
70
+ channels, events, and client-server communication
71
+ email:
72
+ - support@realtimex.net
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - LICENSE
78
+ - README.md
79
+ - lib/realtimex.rb
80
+ - lib/realtimex/channel.rb
81
+ - lib/realtimex/channel_manager.rb
82
+ - lib/realtimex/connection.rb
83
+ - lib/realtimex/version.rb
84
+ homepage: https://github.com/realtimex/realtimex-ruby
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 2.7.0
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubygems_version: 3.0.3.1
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Ruby client library for RealtimeX real-time messaging service
107
+ test_files: []