pubnub 4.1.6 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pubnub might be problematic. Click here for more details.

Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.pubnub.yml +40 -6
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile.lock +1 -1
  6. data/README.md +1 -1
  7. data/VERSION +1 -1
  8. data/fixtures/vcr_cassettes/lib/events/get_users.yml +40 -0
  9. data/lib/pubnub/client.rb +14 -0
  10. data/lib/pubnub/client/events.rb +3 -1
  11. data/lib/pubnub/constants.rb +18 -1
  12. data/lib/pubnub/event.rb +12 -4
  13. data/lib/pubnub/events/create_space.rb +84 -0
  14. data/lib/pubnub/events/create_user.rb +84 -0
  15. data/lib/pubnub/events/delete_space.rb +78 -0
  16. data/lib/pubnub/events/delete_user.rb +78 -0
  17. data/lib/pubnub/events/get_members.rb +93 -0
  18. data/lib/pubnub/events/get_space.rb +74 -0
  19. data/lib/pubnub/events/get_space_memberships.rb +93 -0
  20. data/lib/pubnub/events/get_spaces.rb +90 -0
  21. data/lib/pubnub/events/get_user.rb +74 -0
  22. data/lib/pubnub/events/get_users.rb +90 -0
  23. data/lib/pubnub/events/manage_members.rb +105 -0
  24. data/lib/pubnub/events/manage_memberships.rb +105 -0
  25. data/lib/pubnub/events/update_space.rb +86 -0
  26. data/lib/pubnub/events/update_user.rb +86 -0
  27. data/lib/pubnub/validators/create_space.rb +44 -0
  28. data/lib/pubnub/validators/create_user.rb +44 -0
  29. data/lib/pubnub/validators/delete_space.rb +32 -0
  30. data/lib/pubnub/validators/delete_user.rb +32 -0
  31. data/lib/pubnub/validators/get_members.rb +32 -0
  32. data/lib/pubnub/validators/get_space.rb +32 -0
  33. data/lib/pubnub/validators/get_space_memberships.rb +32 -0
  34. data/lib/pubnub/validators/get_spaces.rb +16 -0
  35. data/lib/pubnub/validators/get_user.rb +32 -0
  36. data/lib/pubnub/validators/get_users.rb +16 -0
  37. data/lib/pubnub/validators/manage_members.rb +45 -0
  38. data/lib/pubnub/validators/manage_memberships.rb +45 -0
  39. data/lib/pubnub/validators/update_space.rb +45 -0
  40. data/lib/pubnub/validators/update_user.rb +45 -0
  41. data/lib/pubnub/version.rb +1 -1
  42. data/spec/lib/events/membership_spec.rb +69 -0
  43. data/spec/lib/events/space_spec.rb +75 -0
  44. data/spec/lib/events/user_spec.rb +75 -0
  45. metadata +37 -2
@@ -0,0 +1,78 @@
1
+ # Toplevel Pubnub module.
2
+ # frozen_string_literal: true
3
+
4
+ module Pubnub
5
+ # Holds DeleteUser functionality
6
+ class DeleteUser < SingleEvent
7
+ include Concurrent::Async
8
+ include Pubnub::Validator::DeleteUser
9
+
10
+ def initialize(options, app)
11
+ @event = :delete_user
12
+ @telemetry_name = :l_obj
13
+ @user_id = options[:user_id]
14
+ super
15
+ end
16
+
17
+ def fire
18
+ Pubnub.logger.debug('Pubnub::DeleteUser') { "Fired event #{self.class}" }
19
+
20
+ body = Formatter.format_message(@data, @cipher_key, false)
21
+ response = send_request(body)
22
+
23
+ envelopes = fire_callbacks(handle(response, uri))
24
+ finalize_event(envelopes)
25
+ envelopes
26
+ end
27
+
28
+ private
29
+
30
+ def current_operation
31
+ Pubnub::Constants::OPERATION_DELETE_USER
32
+ end
33
+
34
+ def path
35
+ '/' + [
36
+ 'v1',
37
+ 'objects',
38
+ @subscribe_key,
39
+ 'users',
40
+ @user_id
41
+ ].join('/')
42
+ end
43
+
44
+ def valid_envelope(parsed_response, req_res_objects)
45
+ Pubnub::Envelope.new(
46
+ event: @event,
47
+ event_options: @given_options,
48
+ timetoken: nil,
49
+
50
+ result: {
51
+ code: req_res_objects[:response].code,
52
+ operation: Pubnub::Constants::OPERATION_DELETE_USER,
53
+ client_request: req_res_objects[:request],
54
+ server_response: req_res_objects[:response],
55
+ data: parsed_response
56
+ },
57
+
58
+ status: {
59
+ code: req_res_objects[:response].code,
60
+ operation: Pubnub::Constants::OPERATION_DELETE_USER,
61
+ client_request: req_res_objects[:request],
62
+ server_response: req_res_objects[:response],
63
+ data: nil,
64
+ category: Pubnub::Constants::STATUS_ACK,
65
+ error: false,
66
+ auto_retried: false,
67
+
68
+ current_timetoken: nil,
69
+ last_timetoken: nil,
70
+ subscribed_channels: nil,
71
+ subscribed_channel_groups: nil,
72
+
73
+ config: get_config
74
+ }
75
+ )
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,93 @@
1
+ # Toplevel Pubnub module.
2
+ # frozen_string_literal: true
3
+
4
+ module Pubnub
5
+ # Holds GetMembers functionality
6
+ class GetMembers < SingleEvent
7
+ include Concurrent::Async
8
+ include Pubnub::Validator::GetMembers
9
+ @max_limit = 100
10
+
11
+ def initialize(options, app)
12
+ @event = :get_members
13
+ @telemetry_name = :l_obj
14
+ @start = options[:start]
15
+ @end = if options[:end].nil?
16
+ @max_limit
17
+ else
18
+ @end = options[:end]
19
+ end
20
+ @limit = options[:limit]
21
+ @count = if options[:count].nil?
22
+ false
23
+ else
24
+ options[:count]
25
+ end
26
+ @include = options[:include]
27
+ @space_id = options[:space_id]
28
+ super
29
+ end
30
+
31
+ private
32
+
33
+ def current_operation
34
+ Pubnub::Constants::OPERATION_GET_MEMBERS
35
+ end
36
+
37
+ def parameters(*_args)
38
+ parameters = super
39
+ parameters[:start] = @start if @start
40
+ parameters[:end] = @end if @end && !@start
41
+ parameters[:count] = @count if @count
42
+ parameters[:limit] = @limit if @limit && @limit != @max_limit
43
+ parameters[:include] = @include if @include
44
+
45
+ parameters
46
+ end
47
+
48
+ def path
49
+ '/' + [
50
+ 'v1',
51
+ 'objects',
52
+ @subscribe_key,
53
+ 'spaces',
54
+ @space_id,
55
+ 'users'
56
+ ].join('/')
57
+ end
58
+
59
+ def valid_envelope(parsed_response, req_res_objects)
60
+ Pubnub::Envelope.new(
61
+ event: @event,
62
+ event_options: @given_options,
63
+ timetoken: nil,
64
+
65
+ result: {
66
+ code: req_res_objects[:response].code,
67
+ operation: Pubnub::Constants::OPERATION_GET_MEMBERS,
68
+ client_request: req_res_objects[:request],
69
+ server_response: req_res_objects[:response],
70
+ data: parsed_response
71
+ },
72
+
73
+ status: {
74
+ code: req_res_objects[:response].code,
75
+ operation: Pubnub::Constants::OPERATION_GET_MEMBERS,
76
+ client_request: req_res_objects[:request],
77
+ server_response: req_res_objects[:response],
78
+ data: nil,
79
+ category: Pubnub::Constants::STATUS_ACK,
80
+ error: false,
81
+ auto_retried: false,
82
+
83
+ current_timetoken: nil,
84
+ last_timetoken: nil,
85
+ subscribed_channels: nil,
86
+ subscribed_channel_groups: nil,
87
+
88
+ config: get_config
89
+ }
90
+ )
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,74 @@
1
+ # Toplevel Pubnub module.
2
+ # frozen_string_literal: true
3
+
4
+ module Pubnub
5
+ # Holds GetSpace functionality
6
+ class GetSpace < SingleEvent
7
+ include Concurrent::Async
8
+ include Pubnub::Validator::GetSpace
9
+
10
+ def initialize(options, app)
11
+ @event = :get_space
12
+ @telemetry_name = :l_obj
13
+ @space_id = options[:space_id]
14
+ @include = options[:include]
15
+ super
16
+ end
17
+
18
+ private
19
+
20
+ def current_operation
21
+ Pubnub::Constants::OPERATION_GET_SPACE
22
+ end
23
+
24
+ def parameters(*_args)
25
+ parameters = super
26
+ parameters[:include] = @include if @include
27
+ parameters
28
+ end
29
+
30
+ def path
31
+ '/' + [
32
+ 'v1',
33
+ 'objects',
34
+ @subscribe_key,
35
+ 'spaces',
36
+ @space_id
37
+ ].join('/')
38
+ end
39
+
40
+ def valid_envelope(parsed_response, req_res_objects)
41
+ Pubnub::Envelope.new(
42
+ event: @event,
43
+ event_options: @given_options,
44
+ timetoken: nil,
45
+
46
+ result: {
47
+ code: req_res_objects[:response].code,
48
+ operation: Pubnub::Constants::OPERATION_GET_SPACE,
49
+ client_request: req_res_objects[:request],
50
+ server_response: req_res_objects[:response],
51
+ data: parsed_response
52
+ },
53
+
54
+ status: {
55
+ code: req_res_objects[:response].code,
56
+ operation: Pubnub::Constants::OPERATION_GET_SPACE,
57
+ client_request: req_res_objects[:request],
58
+ server_response: req_res_objects[:response],
59
+ data: nil,
60
+ category: Pubnub::Constants::STATUS_ACK,
61
+ error: false,
62
+ auto_retried: false,
63
+
64
+ current_timetoken: nil,
65
+ last_timetoken: nil,
66
+ subscribed_channels: nil,
67
+ subscribed_channel_groups: nil,
68
+
69
+ config: get_config
70
+ }
71
+ )
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,93 @@
1
+ # Toplevel Pubnub module.
2
+ # frozen_string_literal: true
3
+
4
+ module Pubnub
5
+ # Holds GetSpaceMemberships functionality
6
+ class GetSpaceMemberships < SingleEvent
7
+ include Concurrent::Async
8
+ include Pubnub::Validator::GetSpaceMemberships
9
+ @max_limit = 100
10
+
11
+ def initialize(options, app)
12
+ @event = :get_space_memberships
13
+ @telemetry_name = :l_obj
14
+ @start = options[:start]
15
+ @end = if options[:end].nil?
16
+ @max_limit
17
+ else
18
+ @end = options[:end]
19
+ end
20
+ @limit = options[:limit]
21
+ @count = if options[:count].nil?
22
+ false
23
+ else
24
+ options[:count]
25
+ end
26
+ @include = options[:include]
27
+ @user_id = options[:user_id]
28
+ super
29
+ end
30
+
31
+ private
32
+
33
+ def current_operation
34
+ Pubnub::Constants::OPERATION_GET_SPACE_MEMBERSHIPS
35
+ end
36
+
37
+ def parameters(*_args)
38
+ parameters = super
39
+ parameters[:start] = @start if @start
40
+ parameters[:end] = @end if @end && !@start
41
+ parameters[:count] = @count if @count
42
+ parameters[:limit] = @limit if @limit && @limit != @max_limit
43
+ parameters[:include] = @include if @include
44
+
45
+ parameters
46
+ end
47
+
48
+ def path
49
+ '/' + [
50
+ 'v1',
51
+ 'objects',
52
+ @subscribe_key,
53
+ 'users',
54
+ @user_id,
55
+ 'spaces'
56
+ ].join('/')
57
+ end
58
+
59
+ def valid_envelope(parsed_response, req_res_objects)
60
+ Pubnub::Envelope.new(
61
+ event: @event,
62
+ event_options: @given_options,
63
+ timetoken: nil,
64
+
65
+ result: {
66
+ code: req_res_objects[:response].code,
67
+ operation: Pubnub::Constants::OPERATION_GET_SPACE_MEMBERSHIPS,
68
+ client_request: req_res_objects[:request],
69
+ server_response: req_res_objects[:response],
70
+ data: parsed_response
71
+ },
72
+
73
+ status: {
74
+ code: req_res_objects[:response].code,
75
+ operation: Pubnub::Constants::OPERATION_GET_SPACE_MEMBERSHIPS,
76
+ client_request: req_res_objects[:request],
77
+ server_response: req_res_objects[:response],
78
+ data: nil,
79
+ category: Pubnub::Constants::STATUS_ACK,
80
+ error: false,
81
+ auto_retried: false,
82
+
83
+ current_timetoken: nil,
84
+ last_timetoken: nil,
85
+ subscribed_channels: nil,
86
+ subscribed_channel_groups: nil,
87
+
88
+ config: get_config
89
+ }
90
+ )
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,90 @@
1
+ # Toplevel Pubnub module.
2
+ # frozen_string_literal: true
3
+
4
+ module Pubnub
5
+ # Holds GetSpaces functionality
6
+ class GetSpaces < SingleEvent
7
+ include Concurrent::Async
8
+ include Pubnub::Validator::GetSpaces
9
+ @max_limit = 100
10
+
11
+ def initialize(options, app)
12
+ @event = :get_spaces
13
+ @telemetry_name = :l_obj
14
+ @start = options[:start]
15
+ @end = if options[:end].nil?
16
+ @max_limit
17
+ else
18
+ @end = options[:end]
19
+ end
20
+ @limit = options[:limit]
21
+ @count = if options[:count].nil?
22
+ false
23
+ else
24
+ options[:count]
25
+ end
26
+ @include = options[:include]
27
+ super
28
+ end
29
+
30
+ private
31
+
32
+ def current_operation
33
+ Pubnub::Constants::OPERATION_GET_SPACES
34
+ end
35
+
36
+ def parameters(*_args)
37
+ parameters = super
38
+ parameters[:start] = @start if @start
39
+ parameters[:end] = @end if @end && !@start
40
+ parameters[:count] = @count if @count
41
+ parameters[:limit] = @limit if @limit && @limit != @max_limit
42
+ parameters[:include] = @include if @include
43
+
44
+ parameters
45
+ end
46
+
47
+ def path
48
+ '/' + [
49
+ 'v1',
50
+ 'objects',
51
+ @subscribe_key,
52
+ 'spaces'
53
+ ].join('/')
54
+ end
55
+
56
+ def valid_envelope(parsed_response, req_res_objects)
57
+ Pubnub::Envelope.new(
58
+ event: @event,
59
+ event_options: @given_options,
60
+ timetoken: nil,
61
+
62
+ result: {
63
+ code: req_res_objects[:response].code,
64
+ operation: Pubnub::Constants::OPERATION_GET_SPACES,
65
+ client_request: req_res_objects[:request],
66
+ server_response: req_res_objects[:response],
67
+ data: parsed_response
68
+ },
69
+
70
+ status: {
71
+ code: req_res_objects[:response].code,
72
+ operation: Pubnub::Constants::OPERATION_GET_SPACES,
73
+ client_request: req_res_objects[:request],
74
+ server_response: req_res_objects[:response],
75
+ data: nil,
76
+ category: Pubnub::Constants::STATUS_ACK,
77
+ error: false,
78
+ auto_retried: false,
79
+
80
+ current_timetoken: nil,
81
+ last_timetoken: nil,
82
+ subscribed_channels: nil,
83
+ subscribed_channel_groups: nil,
84
+
85
+ config: get_config
86
+ }
87
+ )
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,74 @@
1
+ # Toplevel Pubnub module.
2
+ # frozen_string_literal: true
3
+
4
+ module Pubnub
5
+ # Holds GetUser functionality
6
+ class GetUser < SingleEvent
7
+ include Concurrent::Async
8
+ include Pubnub::Validator::GetUser
9
+
10
+ def initialize(options, app)
11
+ @event = :get_user
12
+ @telemetry_name = :l_obj
13
+ @user_id = options[:user_id]
14
+ @include = options[:include]
15
+ super
16
+ end
17
+
18
+ private
19
+
20
+ def current_operation
21
+ Pubnub::Constants::OPERATION_GET_USER
22
+ end
23
+
24
+ def parameters(*_args)
25
+ parameters = super
26
+ parameters[:include] = @include if @include
27
+ parameters
28
+ end
29
+
30
+ def path
31
+ '/' + [
32
+ 'v1',
33
+ 'objects',
34
+ @subscribe_key,
35
+ 'users',
36
+ @user_id
37
+ ].join('/')
38
+ end
39
+
40
+ def valid_envelope(parsed_response, req_res_objects)
41
+ Pubnub::Envelope.new(
42
+ event: @event,
43
+ event_options: @given_options,
44
+ timetoken: nil,
45
+
46
+ result: {
47
+ code: req_res_objects[:response].code,
48
+ operation: Pubnub::Constants::OPERATION_GET_USER,
49
+ client_request: req_res_objects[:request],
50
+ server_response: req_res_objects[:response],
51
+ data: parsed_response
52
+ },
53
+
54
+ status: {
55
+ code: req_res_objects[:response].code,
56
+ operation: Pubnub::Constants::OPERATION_GET_USER,
57
+ client_request: req_res_objects[:request],
58
+ server_response: req_res_objects[:response],
59
+ data: nil,
60
+ category: Pubnub::Constants::STATUS_ACK,
61
+ error: false,
62
+ auto_retried: false,
63
+
64
+ current_timetoken: nil,
65
+ last_timetoken: nil,
66
+ subscribed_channels: nil,
67
+ subscribed_channel_groups: nil,
68
+
69
+ config: get_config
70
+ }
71
+ )
72
+ end
73
+ end
74
+ end