Skip to content

Commit 17617e1

Browse files
authored
Add userId as a supported configuration option
1 parent 3d7a18b commit 17617e1

File tree

82 files changed

+1090
-1064
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+1090
-1064
lines changed

lib/pubnub/client.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ class Client
111111
# <dd><b>optional.</b> Required to encrypt messages.</dd>
112112
#
113113
# <dt>uuid</dt>
114-
# <dd><b>optional.</b> Sets given uuid as client uuid, does not generates random uuid on init as usually.</dd>
114+
# <dd><b>optional.</b> <b>Deprecated.</b> Sets given uuid as client uuid, does not generates random uuid on init as usually</dd>
115+
#
116+
# <dt>user_id</dt>
117+
# <dd><b>required.</b> Sets given user_id as client user_id.</dd>
115118
#
116119
# <dt>origin</dt>
117120
# <dd><b>optional.</b> Specifies the fully qualified domain name of the PubNub origin.
@@ -155,7 +158,7 @@ class Client
155158
# publish_key: :demo,
156159
# secret_key: :secret,
157160
# cipher_key: :other_secret,
158-
# uuid: :mad_max,
161+
# user_id: :mad_max,
159162
# origin: 'custom.pubnub.com',
160163
# callback: ->(envelope) { puts envelope.message },
161164
# connect_callback: ->(message) { puts message },
@@ -289,7 +292,7 @@ def kill_request_dispatcher(origin, event_type)
289292

290293
def sequence_number_for_publish!
291294
@env[:sequence_number_for_publish] += 1
292-
@env[:sequence_number_for_publish] % 2**32
295+
@env[:sequence_number_for_publish] % 2 ** 32
293296
end
294297

295298
def apply_state(event)
@@ -379,6 +382,7 @@ def setup_app(options)
379382
Pubnub.logger = options[:logger] || Logger.new('pubnub.log')
380383
Concurrent.global_logger = Pubnub.logger
381384
@subscriber = Subscriber.new(self)
385+
options[:user_id] = options[:uuid] if options[:user_id].nil?
382386
@env = options
383387
end
384388

lib/pubnub/client/getters_setters.rb

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class Client
77
# Module that holds some getters and setters
88
module GettersSetters
99

10+
extend Gem::Deprecate
11+
1012
def sdk_version
1113
"PubNub-Ruby/#{Pubnub::VERSION}"
1214
end
@@ -15,7 +17,7 @@ def sdk_version
1517
# ===========
1618
# <dl>
1719
# <dt>uuid</dt>
18-
# <dd>New uuid to be set.</dd>
20+
# <dd>New uuid to be set. Note that this will override user_id value</dd>
1921
# </dl>
2022
#
2123
# Returns:
@@ -26,16 +28,38 @@ def sdk_version
2628
# ==============
2729
# Can't change uuid while subscribed. You have to leave every subscribed channel.
2830
def change_uuid(uuid)
29-
Pubnub.logger.debug('Pubnub::Client') { 'Changing uuid' }
30-
raise('Cannot change UUID while subscribed.') if subscribed?
31-
Validator::Client.validate_uuid uuid
31+
change_user_id(uuid)
32+
end
33+
deprecate :change_uuid, :change_user_id, 2023, 1
3234

33-
@env[:uuid] = uuid
35+
# Parameters:
36+
# ===========
37+
# <dl>
38+
# <dt>user_id</dt>
39+
# <dd>New user_id to be set. Note that this will override uuid value</dd>
40+
# </dl>
41+
#
42+
# Returns:
43+
# ========
44+
# New user_id.
45+
#
46+
# Functionality:
47+
# ==============
48+
# Can't change user_id while subscribed. You have to leave every subscribed channel.
49+
def change_user_id(user_id)
50+
Pubnub.logger.debug('Pubnub::Client') { 'Changing user_id' }
51+
raise('Cannot change user_id while subscribed.') if subscribed?
52+
Validator::Client.validate_user_id user_id
53+
54+
@env[:user_id] = user_id
3455
end
3556

3657
alias session_uuid= change_uuid
3758
alias uuid= change_uuid
3859
alias set_uuid= change_uuid
60+
alias session_user_id= change_user_id
61+
alias user_id= change_user_id
62+
alias set_user_id= change_user_id
3963

4064
# Returns:
4165
# ========
@@ -97,7 +121,15 @@ def timetoken=(timetoken)
97121
# ========
98122
# Current uuid.
99123
def uuid
100-
@env[:uuid]
124+
user_id
125+
end
126+
deprecate :uuid, :user_id, 2023, 1
127+
128+
# Returns:
129+
# ========
130+
# Current user_id.
131+
def user_id
132+
@env[:user_id]
101133
end
102134

103135
# Returns:

lib/pubnub/event.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def parameters(_set_signature = false)
148148
token = @app.env[:token]
149149
empty_if_blank = {
150150
auth: token ? token : @auth_key,
151-
uuid: @app.env[:uuid],
151+
uuid: @app.user_id,
152152
@telemetry_name => @current_telemetry
153153
}
154154

@@ -223,7 +223,7 @@ def error_message(parsed_response)
223223
def get_config
224224
{
225225
tls: @app.env[:ssl],
226-
uuid: @app.env[:uuid],
226+
uuid: @app.user_id,
227227
auth_key: @app.env[:auth_key],
228228
origin: @app.current_origin
229229
}

lib/pubnub/events/get_memberships.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class GetMemberships < SingleEvent
1010
def initialize(options, app)
1111
@event = current_operation
1212
@telemetry_name = :l_obj
13-
@uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
13+
@uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
1414
@limit = [options[:limit], 100].min unless options[:limit].nil?
1515
@sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
1616
@filter = options[:filter] if options[:filter] && !options[:filter].empty?

lib/pubnub/events/get_uuid_metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class GetUuidMetadata < SingleEvent
1010
def initialize(options, app)
1111
@event = current_operation
1212
@telemetry_name = :l_obj
13-
@uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
13+
@uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
1414

1515
if options[:include]
1616
@include = "custom" unless [0, '0', false].include?(options[:include][:custom])

lib/pubnub/events/remove_memberships.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class RemoveMemberships < SingleEvent
1010
def initialize(options, app)
1111
@event = current_operation
1212
@telemetry_name = :l_obj
13-
@uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
13+
@uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
1414
@limit = [options[:limit], 100].min unless options[:limit].nil?
1515
@sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
1616
@filter = options[:filter] if options[:filter] && !options[:filter].empty?

lib/pubnub/events/remove_uuid_metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class RemoveUuidMetadata < SingleEvent
1010
def initialize(options, app)
1111
@event = current_operation
1212
@telemetry_name = :l_obj
13-
@uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
13+
@uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
1414
super
1515
end
1616

lib/pubnub/events/set_memberships.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SetMemberships < SingleEvent
1010
def initialize(options, app)
1111
@event = current_operation
1212
@telemetry_name = :l_obj
13-
@uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
13+
@uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
1414
@limit = [options[:limit], 100].min unless options[:limit].nil?
1515
@sort = options[:sort].join(",") if options[:sort] && !options[:sort].empty?
1616
@filter = options[:filter] if options[:filter] && !options[:filter].empty?

lib/pubnub/events/set_state.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def path
3434
'channel',
3535
Formatter.channels_for_url(@channel),
3636
'uuid',
37-
Formatter.encode(@app.uuid),
37+
Formatter.encode(@app.user_id),
3838
'data'
3939
].join('/')
4040
end

lib/pubnub/events/set_uuid_metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SetUuidMetadata < SingleEvent
1010
def initialize(options, app)
1111
@event = current_operation
1212
@telemetry_name = :l_obj
13-
@uuid = options[:uuid].nil? ? app.env[:uuid] : options[:uuid]
13+
@uuid = options[:uuid].nil? ? app.user_id : options[:uuid]
1414

1515
# Clean up user-provided metadata object from nils.
1616
@metadata = options[:metadata].delete_if { |_k, v| v.blank? } unless options[:metadata].nil?

0 commit comments

Comments
 (0)