pubnub 3.5.14 → 3.6.7
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.
- checksums.yaml +4 -4
- data/3.5_to_3.6_upgrade_notes.md +148 -0
- data/{CHANGELOG → CHANGELOG.txt} +15 -0
- data/Gemfile.lock +5 -4
- data/LICENSE.txt +28 -0
- data/README.md +164 -19
- data/Rakefile +1 -6
- data/examples/demo_console.rb +370 -329
- data/fixtures/vcr_cassettes/grant-multiple-channels-presence-multi-1.yml +44 -0
- data/fixtures/vcr_cassettes/grant-multiple-channels-presence-multi-2.yml +44 -0
- data/fixtures/vcr_cassettes/grant-multiple-channels-presence-multi-3.yml +44 -0
- data/fixtures/vcr_cassettes/grant-multiple-channels-presence-multi-4.yml +44 -0
- data/fixtures/vcr_cassettes/grant-multiple-channels-presence.yml +44 -0
- data/fixtures/vcr_cassettes/heartbeated-subscribe.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-nonssl-block-valid-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-nonssl-block-valid-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-nonssl-block-valid-non-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-nonssl-block-valid-non-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-nonssl-parameter-valid-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-nonssl-parameter-valid-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-nonssl-parameter-valid-non-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-nonssl-parameter-valid-non-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-ssl-block-valid-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-ssl-block-valid-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-ssl-block-valid-non-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-ssl-block-valid-non-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-ssl-parameter-valid-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-ssl-parameter-valid-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-ssl-parameter-valid-non-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/here_now-ssl-parameter-valid-non-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/leave-nonssl-block-valid-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/leave-nonssl-block-valid-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/leave-nonssl-block-valid-non-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/leave-nonssl-block-valid-non-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/leave-nonssl-parameter-valid-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/leave-nonssl-parameter-valid-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/leave-nonssl-parameter-valid-non-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/leave-nonssl-parameter-valid-non-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/leave-ssl-block-valid-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/leave-ssl-block-valid-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/leave-ssl-block-valid-non-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/leave-ssl-block-valid-non-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/leave-ssl-parameter-valid-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/leave-ssl-parameter-valid-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/leave-ssl-parameter-valid-non-200-async.yml +1 -1
- data/fixtures/vcr_cassettes/leave-ssl-parameter-valid-non-200-sync.yml +1 -1
- data/fixtures/vcr_cassettes/state-async-set-state-via-subbedclient-2.yml +140 -0
- data/fixtures/vcr_cassettes/state-async-set-state-via-subbedclient.yml +131 -0
- data/fixtures/vcr_cassettes/state-async-set-state-via-subscribe.yml +90 -0
- data/fixtures/vcr_cassettes/state-set-state-via-client-2.yml +140 -0
- data/fixtures/vcr_cassettes/state-set-state-via-client.yml +90 -0
- data/fixtures/vcr_cassettes/state-set-state-via-subscribe.yml +90 -0
- data/fixtures/vcr_cassettes/where_now-ssl-block-invalid-200-async.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-block-invalid-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-block-invalid-non-200-async.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-block-invalid-non-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-block-valid-200-async.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-block-valid-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-block-valid-non-200-async.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-block-valid-non-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-parameter-invalid-200-async.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-parameter-invalid-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-parameter-invalid-non-200-async.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-parameter-invalid-non-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-parameter-valid-200-async.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-parameter-valid-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-parameter-valid-non-200-async.yml +49 -0
- data/fixtures/vcr_cassettes/where_now-ssl-parameter-valid-non-200-sync.yml +49 -0
- data/lib/pubnub.rb +1 -2
- data/lib/pubnub/client.rb +97 -21
- data/lib/pubnub/configuration.rb +1 -1
- data/lib/pubnub/envelope.rb +3 -2
- data/lib/pubnub/event.rb +9 -5
- data/lib/pubnub/events/audit.rb +1 -1
- data/lib/pubnub/events/grant.rb +1 -1
- data/lib/pubnub/events/heartbeat.rb +7 -3
- data/lib/pubnub/events/here_now.rb +7 -4
- data/lib/pubnub/events/history.rb +1 -1
- data/lib/pubnub/events/leave.rb +10 -4
- data/lib/pubnub/events/presence.rb +1 -1
- data/lib/pubnub/events/publish.rb +6 -2
- data/lib/pubnub/events/revoke.rb +1 -1
- data/lib/pubnub/events/set_state.rb +77 -0
- data/lib/pubnub/events/state.rb +63 -0
- data/lib/pubnub/events/subscribe.rb +7 -0
- data/lib/pubnub/events/where_now.rb +55 -0
- data/lib/pubnub/pam.rb +10 -16
- data/lib/pubnub/version.rb +2 -2
- data/pubnub.gemspec +21 -19
- data/spec/lib/channel_presence_concat_pam_spec.rb +94 -0
- data/spec/lib/client_spec.rb +3 -4
- data/spec/lib/heartbeat_spec.rb +16 -16
- data/spec/lib/integration/global_here_now_dpc_spec.rb +10 -10
- data/spec/lib/integration/global_here_now_spec.rb +8 -8
- data/spec/lib/integration/here_now_dpc_spec.rb +24 -24
- data/spec/lib/integration/here_now_spec.rb +24 -24
- data/spec/lib/integration/leave_dpc_spec.rb +24 -25
- data/spec/lib/integration/leave_spec.rb +24 -24
- data/spec/lib/integration/publish_spec.rb +5 -0
- data/spec/lib/integration/state_spec.rb +84 -0
- data/spec/lib/integration/where_now_spec.rb +312 -0
- metadata +108 -26
- data/LICENSE +0 -27
- data/VERSION +0 -1
- data/examples/demo_console_new.rb +0 -286
- data/fixtures/vcr_cassettes/heartbeat-non200.yml +0 -667
- data/spec/tools/pam-test-generator.rb +0 -367
- data/spec/tools/test-generator.rb +0 -310
data/Rakefile
CHANGED
@@ -1,7 +1,2 @@
|
|
1
|
-
|
2
|
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
1
|
+
require 'bundler/gem_tasks'
|
4
2
|
|
5
|
-
require File.expand_path('../config/application', __FILE__)
|
6
|
-
|
7
|
-
Ruby2::Application.load_tasks
|
data/examples/demo_console.rb
CHANGED
@@ -1,356 +1,397 @@
|
|
1
1
|
require 'pubnub'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
origin = 'pubsub.pubnub.com'
|
24
|
-
sub_key = 'sub-c-a478dd2a-c33d-11e2-883f-02ee2ddab7fe'
|
25
|
-
pub_key = 'pub-c-a2650a22-deb1-44f5-aa87-1517049411d5'
|
26
|
-
sec_key = 'sec-c-YjFmNzYzMGMtYmI3NC00NzJkLTlkYzYtY2MwMzI4YTJhNDVh'
|
27
|
-
|
28
|
-
when 'c'
|
29
|
-
puts 'Provide origin [demo.pubnub.com]:'
|
30
|
-
origin = gets.chomp!.downcase
|
31
|
-
origin = 'demo.pubnub.com' if origin.blank?
|
32
|
-
puts 'Provide subscribe key [demo]:'
|
33
|
-
sub_key = gets.chomp!
|
34
|
-
sub_key = 'demo' if sub_key.blank?
|
35
|
-
|
36
|
-
puts 'Provide publish key [demo]:'
|
37
|
-
pub_key = gets.chomp!
|
38
|
-
pub_key = 'demo' if pub_key.blank?
|
39
|
-
|
40
|
-
puts 'Provide secret key (optional):'
|
41
|
-
sec_key = gets.chomp!
|
42
|
-
sec_key = nil if sec_key.blank?
|
43
|
-
end
|
44
|
-
|
45
|
-
puts 'Provide auth key or skip? (default: skip)'
|
46
|
-
auth_key = gets.chomp!
|
47
|
-
|
48
|
-
puts 'Do you want your connection to be ssl? [y/N]'
|
49
|
-
ssl = gets.chomp!.upcase
|
50
|
-
ssl = 'N' if ssl != 'Y'
|
51
|
-
ssl = ssl == 'Y' ? true : false
|
52
|
-
|
53
|
-
puts "\nUsing following keys:"
|
54
|
-
puts "Subscribe key: #{sub_key}"
|
55
|
-
puts "Publish key: #{pub_key}"
|
56
|
-
puts "Secret key: #{sec_key}" if sec_key
|
57
|
-
puts "Auth key: #{auth_key}" if auth_key
|
58
|
-
|
59
|
-
|
60
|
-
p = Pubnub.new(
|
61
|
-
:ssl => ssl,
|
62
|
-
:subscribe_key => sub_key,
|
63
|
-
:secret_key => sec_key,
|
64
|
-
:publish_key => pub_key,
|
65
|
-
:auth_key => auth_key,
|
66
|
-
:origin => origin,
|
67
|
-
:error_callback => lambda { |msg|
|
68
|
-
puts "Error callback says: #{msg.inspect}"
|
69
|
-
},
|
70
|
-
:connect_callback => lambda { |msg|
|
71
|
-
puts "Connect callback says: #{msg.inspect}"
|
72
|
-
}
|
73
|
-
)
|
74
|
-
|
75
|
-
puts("\nUse PubNub AES encryption? Leave blank for now, else enter your cipher key.")
|
76
|
-
aes = gets.chomp!
|
77
|
-
|
78
|
-
unless aes.blank?
|
79
|
-
p.cipher_key = aes
|
2
|
+
require 'awesome_print'
|
3
|
+
|
4
|
+
class String
|
5
|
+
def black; "\033[30m#{self}\033[0m" end
|
6
|
+
def red; "\033[31m#{self}\033[0m" end
|
7
|
+
def green; "\033[32m#{self}\033[0m" end
|
8
|
+
def brown; "\033[33m#{self}\033[0m" end
|
9
|
+
def blue; "\033[34m#{self}\033[0m" end
|
10
|
+
def magenta; "\033[35m#{self}\033[0m" end
|
11
|
+
def cyan; "\033[36m#{self}\033[0m" end
|
12
|
+
def gray; "\033[37m#{self}\033[0m" end
|
13
|
+
def bg_black; "\033[40m#{self}\0330m" end
|
14
|
+
def bg_red; "\033[41m#{self}\033[0m" end
|
15
|
+
def bg_green; "\033[42m#{self}\033[0m" end
|
16
|
+
def bg_brown; "\033[43m#{self}\033[0m" end
|
17
|
+
def bg_blue; "\033[44m#{self}\033[0m" end
|
18
|
+
def bg_magenta; "\033[45m#{self}\033[0m" end
|
19
|
+
def bg_cyan; "\033[46m#{self}\033[0m" end
|
20
|
+
def bg_gray; "\033[47m#{self}\033[0m" end
|
21
|
+
def bold; "\033[1m#{self}\033[22m" end
|
22
|
+
def reverse_color; "\033[7m#{self}\033[27m" end
|
80
23
|
end
|
81
24
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
25
|
+
class DemoConsole
|
26
|
+
|
27
|
+
OPTIONS = {
|
28
|
+
:'1' => :Publish,
|
29
|
+
:'2' => :Subscribe,
|
30
|
+
:'3' => :Presence,
|
31
|
+
:'4' => :Leave,
|
32
|
+
:'5' => :History,
|
33
|
+
:'6' => :PagedHistory,
|
34
|
+
:'7' => :HereNow,
|
35
|
+
:'8' => :WhereNow,
|
36
|
+
:'9' => :State,
|
37
|
+
:'10' => :Heartbeat,
|
38
|
+
:'11' => :Time,
|
39
|
+
:'12' => :Audit,
|
40
|
+
:'13' => :Grant,
|
41
|
+
:'14' => :Revoke,
|
42
|
+
:A => :set_uuid,
|
43
|
+
:B => :set_auth_key,
|
44
|
+
:C => :show_state,
|
45
|
+
:D => :set_state,
|
46
|
+
:EXIT => :exit
|
47
|
+
}
|
48
|
+
|
49
|
+
def initialize
|
50
|
+
|
51
|
+
welcome
|
52
|
+
|
53
|
+
keys_option = select_keys
|
54
|
+
|
55
|
+
case keys_option.to_s
|
56
|
+
when '1'
|
57
|
+
@origin = 'pubsub.pubnub.com'
|
58
|
+
@subscribe_key = 'demo'
|
59
|
+
@publish_key = 'demo'
|
60
|
+
@secret_key = nil
|
61
|
+
|
62
|
+
when '2'
|
63
|
+
@origin = 'pubsub.pubnub.com'
|
64
|
+
@subscribe_key = 'sub-c-a478dd2a-c33d-11e2-883f-02ee2ddab7fe'
|
65
|
+
@publish_key = 'pub-c-a2650a22-deb1-44f5-aa87-1517049411d5'
|
66
|
+
@secret_key = 'sec-c-YjFmNzYzMGMtYmI3NC00NzJkLTlkYzYtY2MwMzI4YTJhNDVh'
|
67
|
+
|
68
|
+
when '3'
|
69
|
+
puts `clear`
|
70
|
+
print_pubnub
|
71
|
+
puts 'Okey, now you have to provide me your data or accept default:'.green
|
72
|
+
print 'origin [pubsub.pubnub.com]: '
|
73
|
+
@origin = gets.chomp!
|
74
|
+
print 'subscribe_key [demo]: '
|
75
|
+
@subscribe_key = gets.chomp!
|
76
|
+
print 'publish_key [demo]: '
|
77
|
+
@publish_key = gets.chomp!
|
78
|
+
print 'secret_key (nil by default): '
|
79
|
+
@secret_key = gets.chomp!
|
80
|
+
|
81
|
+
@origin = 'pubsub.pubnub.com' if @origin.blank?
|
82
|
+
@subscribe_key = 'demo' if @subscribe_key.blank?
|
83
|
+
@publish_key = 'demo' if @publish_key.blank?
|
84
|
+
@secret_key = nil if @secret_key.blank?
|
85
|
+
else
|
86
|
+
@origin = 'pubsub.pubnub.com'
|
87
|
+
@subscribe_key = 'demo'
|
88
|
+
@publish_key = 'demo'
|
89
|
+
@secret_key = nil
|
90
|
+
end
|
139
91
|
|
140
|
-
|
141
|
-
channel = gets.chomp!
|
92
|
+
set_uuid_and_auth
|
142
93
|
|
143
|
-
|
144
|
-
p.unsubscribe(:channel => channel, :callback => default_cb, :http_sync => false, :ssl => ssl)
|
145
|
-
elsif sync_or_async == 'A' && block_or_parameter == 'B' #ASYNC AND CALLBACK AS PASSED AS BLOCK
|
146
|
-
p.unsubscribe(:channel => channel, :http_sync => false, :ssl => ssl, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
147
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'P' #SYNC AND CALLBACK AS PASSED AS PARAMETER
|
148
|
-
p.unsubscribe(:channel => channel, :callback => default_cb, :http_sync => true, :ssl => ssl)
|
149
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'B' #SYNC AND CALLBACK AS PASSED AS BLOCK
|
150
|
-
p.unsubscribe(:channel => channel, :http_sync => true, :ssl => ssl, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
151
|
-
end
|
94
|
+
my_logger = Logger.new(STDOUT)
|
152
95
|
|
153
|
-
|
96
|
+
@pubnub = Pubnub.new(
|
154
97
|
|
155
|
-
|
156
|
-
|
98
|
+
:subscribe_key => @subscribe_key,
|
99
|
+
:publish_key => @publish_key,
|
100
|
+
:secret_key => @secret_key,
|
101
|
+
:error_callback => method(:error_callback),
|
102
|
+
:auth_key => @auth_key,
|
103
|
+
# :logger => my_logger
|
104
|
+
)
|
157
105
|
|
158
|
-
|
159
|
-
message = gets.chomp!
|
106
|
+
@pubnub.set_uuid(@uuid) unless @uuid.blank?
|
160
107
|
|
161
|
-
|
162
|
-
p.publish(:message => message, :channel => channel, :callback => default_cb, :http_sync => false, :ssl => ssl)
|
163
|
-
elsif sync_or_async == 'A' && block_or_parameter == 'B' #ASYNC AND CALLBACK AS PASSED AS BLOCK
|
164
|
-
p.publish(:message => message, :channel => channel, :http_sync => false, :ssl => ssl, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
165
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'P' #SYNC AND CALLBACK AS PASSED AS PARAMETER
|
166
|
-
p.publish(:message => message, :channel => channel, :callback => default_cb, :http_sync => true, :ssl => ssl)
|
167
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'B' #SYNC AND CALLBACK AS PASSED AS BLOCK
|
168
|
-
p.publish(:message => message, :channel => channel, :http_sync => true, :ssl => ssl, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
169
|
-
end
|
170
|
-
|
171
|
-
when '4' #HISTORY
|
172
|
-
puts('Enter channel')
|
173
|
-
channel = gets.chomp!
|
174
|
-
|
175
|
-
puts('Enter count')
|
176
|
-
count = gets.chomp!
|
177
|
-
if (count == '') then count = nil end
|
178
|
-
|
179
|
-
puts('Enter start')
|
180
|
-
history_start = gets.chomp!
|
181
|
-
if (history_start == '') then history_start = nil end
|
182
|
-
|
183
|
-
puts('Enter end')
|
184
|
-
history_end = gets.chomp!
|
185
|
-
if (history_end == '') then history_end = nil end
|
186
|
-
|
187
|
-
puts('Enter reverse (y/n)')
|
188
|
-
reverse = gets.chomp!
|
189
|
-
if (reverse == "" || reverse == "n") then reverse = false else reverse = true end
|
190
|
-
|
191
|
-
if sync_or_async == 'A' && block_or_parameter == 'P' #ASYNC AND CALLBACK AS PASSED AS PARAMETER
|
192
|
-
p.history(:channel => channel,
|
193
|
-
:count => count,
|
194
|
-
:start => history_start,
|
195
|
-
:end => history_end,
|
196
|
-
:reverse => reverse,
|
197
|
-
:callback => default_cb,
|
198
|
-
:http_sync => false,
|
199
|
-
:ssl => ssl) do |envelope| puts(envelope.inspect) end
|
200
|
-
elsif sync_or_async == 'A' && block_or_parameter == 'B' #ASYNC AND CALLBACK AS PASSED AS BLOCK
|
201
|
-
p.history(:channel => channel,
|
202
|
-
:count => count,
|
203
|
-
:start => history_start,
|
204
|
-
:end => history_end,
|
205
|
-
:reverse => reverse,
|
206
|
-
:http_sync => false,
|
207
|
-
:ssl => ssl, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
208
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'P' #SYNC AND CALLBACK AS PASSED AS PARAMETER
|
209
|
-
p.history(:channel => channel,
|
210
|
-
:count => count,
|
211
|
-
:start => history_start,
|
212
|
-
:end => history_end,
|
213
|
-
:reverse => reverse,
|
214
|
-
:callback => default_cb,
|
215
|
-
:http_sync => true,
|
216
|
-
:ssl => ssl, &default_cb)# do |envelope| puts(envelope.inspect) end
|
217
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'B' #SYNC AND CALLBACK AS PASSED AS BLOCK
|
218
|
-
p.history(:channel => channel,
|
219
|
-
:count => count,
|
220
|
-
:start => history_start,
|
221
|
-
:end => history_end,
|
222
|
-
:reverse => true,
|
223
|
-
:http_sync => false,
|
224
|
-
:ssl => ssl, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
225
|
-
end
|
108
|
+
ap @pubnub
|
226
109
|
|
227
|
-
|
228
|
-
puts('Enter channel')
|
229
|
-
channel = gets.chomp!
|
230
|
-
|
231
|
-
if sync_or_async == 'A' && block_or_parameter == 'P' #ASYNC AND CALLBACK AS PASSED AS PARAMETER
|
232
|
-
p.presence(:channel => channel, :callback => default_cb, :http_sync => false, :ssl => ssl)
|
233
|
-
elsif sync_or_async == 'A' && block_or_parameter == 'B' #ASYNC AND CALLBACK AS PASSED AS BLOCK
|
234
|
-
p.presence(:channel => channel, :http_sync => false, :ssl => ssl, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
235
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'P' #SYNC AND CALLBACK AS PASSED AS PARAMETER
|
236
|
-
p.presence(:channel => channel, :callback => default_cb, :http_sync => true, :ssl => ssl)
|
237
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'B' #SYNC AND CALLBACK AS PASSED AS BLOCK
|
238
|
-
p.presence(:channel => channel, :http_sync => true, :ssl => ssl, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
239
|
-
end
|
110
|
+
start_console
|
240
111
|
|
241
|
-
|
242
|
-
puts('Enter channel')
|
243
|
-
channel = gets.chomp!
|
244
|
-
|
245
|
-
if sync_or_async == 'A' && block_or_parameter == 'P' #ASYNC AND CALLBACK AS PASSED AS PARAMETER
|
246
|
-
p.here_now(:channel => channel, :callback => default_cb, :http_sync => false, :ssl => ssl)
|
247
|
-
elsif sync_or_async == 'A' && block_or_parameter == 'B' #ASYNC AND CALLBACK AS PASSED AS BLOCK
|
248
|
-
p.here_now(:channel => channel, :http_sync => false, :ssl => ssl, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
249
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'P' #SYNC AND CALLBACK AS PASSED AS PARAMETER
|
250
|
-
p.here_now(:channel => channel, :callback => default_cb, :http_sync => true, :ssl => ssl)
|
251
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'B' #SYNC AND CALLBACK AS PASSED AS BLOCK
|
252
|
-
p.here_now(:channel => channel, :http_sync => true, :ssl => ssl, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
253
|
-
end
|
112
|
+
end
|
254
113
|
|
114
|
+
def welcome
|
115
|
+
puts `clear`
|
116
|
+
puts "You have loaded #{Pubnub::VERSION} gem"
|
117
|
+
puts `clear`
|
118
|
+
print_pubnub
|
119
|
+
puts 'Hello in interactive PubNub console!'
|
120
|
+
puts 'Feel free to play around with it!'
|
121
|
+
puts '--'
|
122
|
+
puts '[Hit ENTER to continue]'
|
123
|
+
gets
|
124
|
+
puts `clear`
|
125
|
+
end
|
255
126
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
127
|
+
def select_keys
|
128
|
+
print_pubnub
|
129
|
+
puts 'Before we start, you have to select demo app keys or add your own.'.green
|
130
|
+
print "\n"
|
131
|
+
puts '1. Basic demo keys -- You will be limited to standard events, no PAM features'
|
132
|
+
puts '2. PAM supprot keys -- You can check out all pubnub features, including PAM'
|
133
|
+
puts '3. Custom keys -- If you already have your own keys, you can set them here'
|
134
|
+
print "\n"
|
135
|
+
print 'Your choice: '.green
|
136
|
+
gets.chomp!
|
137
|
+
end
|
266
138
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
if sync_or_async == 'A' && block_or_parameter == 'P' #ASYNC AND CALLBACK AS PASSED AS PARAMETER
|
277
|
-
p.audit(:callback => default_cb, :http_sync => false, :ssl => ssl, :channel => channel, :auth_key => auth_key)
|
278
|
-
elsif sync_or_async == 'A' && block_or_parameter == 'B' #ASYNC AND CALLBACK AS PASSED AS BLOCK
|
279
|
-
p.audit(:http_sync => false, :ssl => ssl, :channel => channel, :auth_key => auth_key, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
280
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'P' #SYNC AND CALLBACK AS PASSED AS PARAMETER
|
281
|
-
p.audit(:callback => default_cb, :http_sync => true, :ssl => ssl, :channel => channel, :auth_key => auth_key)
|
282
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'B' #SYNC AND CALLBACK AS PASSED AS BLOCK
|
283
|
-
p.audit(:http_sync => true, :ssl => ssl, :channel => channel, :auth_key => auth_key, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
284
|
-
end
|
139
|
+
def set_uuid_and_auth
|
140
|
+
puts `clear`
|
141
|
+
print_pubnub
|
142
|
+
puts 'You can set up now your uuid and auth_key: '.green
|
143
|
+
print 'uuid [random_default]: '
|
144
|
+
@uuid = gets.chomp!
|
145
|
+
print 'auth_key (blank by default): '
|
146
|
+
@auth_key = gets.chomp
|
147
|
+
end
|
285
148
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
channel = nil if channel.blank?
|
149
|
+
def set_uuid(uuid)
|
150
|
+
@pubnub.set_uuid(uuid)
|
151
|
+
end
|
290
152
|
|
291
|
-
|
292
|
-
|
293
|
-
|
153
|
+
def set_auth_key(auth_key)
|
154
|
+
@pubnub.set_auth_key(auth_key)
|
155
|
+
end
|
294
156
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
157
|
+
def start_console
|
158
|
+
puts `clear`
|
159
|
+
print_pubnub
|
160
|
+
puts 'CONSOLE STARTED!'.bg_green
|
161
|
+
exit = false
|
162
|
+
choice = false
|
163
|
+
until exit
|
164
|
+
until OPTIONS.keys.include?(choice)
|
165
|
+
puts 'Choose your next operation (type \'exit\' to exit):'.green
|
166
|
+
puts 'Events:'.green
|
167
|
+
puts '1. Publish'
|
168
|
+
puts '2. Subscribe'
|
169
|
+
puts '3. Presence'
|
170
|
+
puts '4. Leave (unsubscribe)'
|
171
|
+
puts '5. History'
|
172
|
+
puts '6. Paged History'
|
173
|
+
puts '7. HereNow'
|
174
|
+
puts '8. WhereNow'
|
175
|
+
puts '9. State'
|
176
|
+
puts '10. Heartbeat'
|
177
|
+
puts '11. Time'
|
178
|
+
puts '12. Audit' if @secret_key
|
179
|
+
puts '13. Grant' if @secret_key
|
180
|
+
puts '14. Revoke' if @secret_key
|
181
|
+
puts "\nPubnub::Client interaction:".green
|
182
|
+
puts 'A. Set UUID'
|
183
|
+
puts 'B. Set auth_key'
|
184
|
+
puts 'C. Check state'
|
185
|
+
puts 'D. Set state'
|
186
|
+
print "\nYour choice: ".red
|
187
|
+
choice = gets.chomp!.to_s.upcase.to_sym
|
299
188
|
end
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
189
|
+
choice = OPTIONS[choice]
|
190
|
+
|
191
|
+
case choice
|
192
|
+
when :exit
|
193
|
+
exit = true
|
194
|
+
when :Publish
|
195
|
+
options = ask_about(:sync, :message, :channel)
|
196
|
+
@pubnub.publish(options)
|
197
|
+
when :Subscribe
|
198
|
+
options = ask_about(:sync, :channel)
|
199
|
+
@pubnub.subscribe(options)
|
200
|
+
when :Presence
|
201
|
+
options = ask_about(:sync, :channel)
|
202
|
+
@pubnub.presence(options)
|
203
|
+
when :Leave
|
204
|
+
options = ask_about(:sync, :channel)
|
205
|
+
@pubnub.leave(options)
|
206
|
+
when :History
|
207
|
+
options = ask_about(:sync, :channel, :reverse, :history_start, :history_end, :count)
|
208
|
+
@pubnub.history(options)
|
209
|
+
when :PagedHistory
|
210
|
+
options = ask_about(:sync, :channel, :reverse, :history_start, :history_end, :limit, :page)
|
211
|
+
@pubnub.paged_history(options)
|
212
|
+
when :HereNow
|
213
|
+
options = ask_about(:sync, :optional_channel)
|
214
|
+
@pubnub.here_now(options)
|
215
|
+
when :WhereNow
|
216
|
+
options = ask_about(:sync, :uuid)
|
217
|
+
@pubnub.where_now(options)
|
218
|
+
when :State
|
219
|
+
options = ask_about(:sync, :channel, :uuid)
|
220
|
+
@pubnub.state(options)
|
221
|
+
when :Heartbeat
|
222
|
+
options = ask_about(:sync, :heartbeat, :channel)
|
223
|
+
@pubnub.heartbeat(options)
|
224
|
+
when :Time
|
225
|
+
options = ask_about(:sync)
|
226
|
+
@pubnub.time(options)
|
227
|
+
when :Audit
|
228
|
+
options = ask_about(:sync, :channel, :subscribe_key)
|
229
|
+
@pubnub.audit(options)
|
230
|
+
when :Grant
|
231
|
+
options = ask_about(:sync, :channel, :subscribe_key, :read, :write)
|
232
|
+
@pubnub.grant(options)
|
233
|
+
when :Revoke
|
234
|
+
options = ask_about(:sync, :channel, :subscribe_key, :read, :write)
|
235
|
+
@pubnub.revoke(options)
|
236
|
+
when :set_uuid
|
237
|
+
print 'Your new uuid: '
|
238
|
+
@pubnub.set_uuid(gets.chomp!)
|
239
|
+
when :set_auth_key
|
240
|
+
print 'Your new auth_key: '
|
241
|
+
@pubnub.set_uuid(gets.chomp!)
|
242
|
+
when :show_state
|
243
|
+
ap @pubnub.env[:state]
|
244
|
+
when :set_state
|
245
|
+
options = ask_about(:sync, :channel)
|
246
|
+
print 'State: '
|
247
|
+
begin
|
248
|
+
state = eval(gets.chomp!)
|
249
|
+
options.merge!({ :state => state})
|
250
|
+
@pubnub.set_state(options)
|
251
|
+
rescue => e
|
252
|
+
print 'ERROR! Invalid state.'.bg_red
|
253
|
+
print e
|
254
|
+
end
|
305
255
|
end
|
256
|
+
choice = nil
|
257
|
+
end
|
258
|
+
end
|
306
259
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
260
|
+
# that adds callback method as :callback in options
|
261
|
+
def ask_about(*things)
|
262
|
+
options = {}
|
263
|
+
things.each do |thing|
|
264
|
+
case thing
|
265
|
+
when :sync
|
266
|
+
print 'Should event be async? '
|
267
|
+
options[:http_sync] = !acceptance
|
268
|
+
|
269
|
+
when :message
|
270
|
+
while options[:message].blank?
|
271
|
+
puts 'Write below message to publish:'
|
272
|
+
options[:message] = gets.chomp!
|
273
|
+
end
|
274
|
+
|
275
|
+
when :channel
|
276
|
+
while options[:channel].blank?
|
277
|
+
print 'Specify channel(s): '
|
278
|
+
options[:channel] = gets.chomp!
|
279
|
+
end
|
280
|
+
|
281
|
+
when :optional_channel
|
282
|
+
print 'Specify channel(s) or leave blank for all channels (global here now): '
|
283
|
+
options[:channel] = gets.chomp!
|
284
|
+
|
285
|
+
when :limit
|
286
|
+
while options[:limit].blank?
|
287
|
+
print 'History limit?: '
|
288
|
+
options[:limit] = gets.chomp!
|
289
|
+
end
|
290
|
+
|
291
|
+
when :reverse
|
292
|
+
while options[:reverse].blank? && options[:reverse] != false
|
293
|
+
print 'In reverse order?: '
|
294
|
+
options[:reverse] = acceptance
|
295
|
+
end
|
296
|
+
|
297
|
+
when :history_start
|
298
|
+
unless options[:reverse]
|
299
|
+
# while options[:start].blank?
|
300
|
+
print 'History start timetoken: '
|
301
|
+
options[:start] = gets.chomp!
|
302
|
+
# end
|
303
|
+
end
|
304
|
+
|
305
|
+
when :history_end
|
306
|
+
unless options[:reverse]
|
307
|
+
# while options[:end].blank?
|
308
|
+
print 'History end timetoken: '
|
309
|
+
options[:end] = gets.chomp!
|
310
|
+
# end
|
311
|
+
end
|
312
|
+
|
313
|
+
when :count
|
314
|
+
while options[:count].blank?
|
315
|
+
print 'Count [100]: '
|
316
|
+
options[:count] = gets.chomp!
|
317
|
+
options[:count] = 100 if options[:count].blank?
|
318
|
+
end
|
319
|
+
|
320
|
+
when :uuid
|
321
|
+
while options[:uuid].blank?
|
322
|
+
print 'Enter uuid: '
|
323
|
+
options[:uuid] = gets.chomp!
|
324
|
+
end
|
325
|
+
|
326
|
+
when :heartbeat
|
327
|
+
while options[:heartbeat].blank?
|
328
|
+
print 'Enter heartbeat rate: '
|
329
|
+
options[:heartbeat] = gets.chomp!
|
330
|
+
end
|
331
|
+
|
332
|
+
when :subscribe_key
|
333
|
+
while options[:subscribe_key].blank?
|
334
|
+
print 'Enter subscribe key: '
|
335
|
+
options[:subscribe_key] = gets.chomp!
|
336
|
+
end
|
337
|
+
|
338
|
+
when :read
|
339
|
+
while options[:read].blank? && options[:read] != false
|
340
|
+
print 'Read? '
|
341
|
+
options[:read] = acceptance
|
342
|
+
end
|
343
|
+
|
344
|
+
when :write
|
345
|
+
while options[:write].blank? && options[:write] != false
|
346
|
+
print 'Write? '
|
347
|
+
options[:write] = acceptance
|
348
|
+
end
|
349
|
+
|
350
|
+
when :limit
|
351
|
+
while options[:limit].blank?
|
352
|
+
print 'limit: '
|
353
|
+
options[:limit] = gets.chomp!.to_i
|
354
|
+
end
|
355
|
+
|
356
|
+
when :page
|
357
|
+
while options[:page].blank?
|
358
|
+
print 'page: '
|
359
|
+
options[:page] = gets.chomp!.to_i
|
360
|
+
end
|
319
361
|
end
|
362
|
+
end
|
363
|
+
options.merge({:callback => method(:callback)})
|
364
|
+
end
|
320
365
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
channel = nil if channel.blank?
|
366
|
+
def acceptance
|
367
|
+
%w(Y 1).include?(gets.chomp!.to_s.upcase)
|
368
|
+
end
|
325
369
|
|
326
|
-
|
327
|
-
|
328
|
-
|
370
|
+
def print_pubnub
|
371
|
+
puts '
|
372
|
+
__________ ___. _______ ___. ________ ________
|
373
|
+
\______ \__ _\_ |__ \ \ __ _\_ |__ \_____ \ / _____/
|
374
|
+
| ___/ | \ __ \ / | \| | \ __ \ _(__ < / __ \
|
375
|
+
| | | | / \_\ \/ | \ | / \_\ \ / \ \ |__\ \
|
376
|
+
|____| |____/|___ /\____|__ /____/|___ / /______ / /\ \_____ /
|
377
|
+
\/ \/ \/ \/ \/ \/
|
378
|
+
|
379
|
+
Pubnub Demo Console
|
380
|
+
'.red
|
381
|
+
end
|
329
382
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
read = gets.chomp!
|
334
|
-
end
|
383
|
+
def callback(envelope)
|
384
|
+
ap envelope.inspect
|
385
|
+
end
|
335
386
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
write = gets.chomp!
|
340
|
-
end
|
387
|
+
def connect_callback(data)
|
388
|
+
puts 'Connection established'.bg_green
|
389
|
+
end
|
341
390
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
if sync_or_async == 'A' && block_or_parameter == 'P' #ASYNC AND CALLBACK AS PASSED AS PARAMETER
|
347
|
-
p.revoke(:callback => default_cb, :http_sync => false, :ssl => ssl, :channel => channel, :read => read, :write => write, :ttl => ttl, :auth_key => auth_key)
|
348
|
-
elsif sync_or_async == 'A' && block_or_parameter == 'B' #ASYNC AND CALLBACK AS PASSED AS BLOCK
|
349
|
-
p.revoke(:http_sync => false, :ssl => ssl, :channel => channel, :read => read, :write => write, :ttl => ttl, :auth_key => auth_key, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
350
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'P' #SYNC AND CALLBACK AS PASSED AS PARAMETER
|
351
|
-
p.revoke(:callback => default_cb, :http_sync => true, :ssl => ssl, :channel => channel, :read => read, :write => write, :ttl => ttl, :auth_key => auth_key)
|
352
|
-
elsif sync_or_async == 'S' && block_or_parameter == 'B' #SYNC AND CALLBACK AS PASSED AS BLOCK
|
353
|
-
p.revoke(:http_sync => true, :ssl => ssl, :channel => channel, :read => read, :write => write, :ttl => ttl, :auth_key => auth_key, &default_cb)#{ |envelope| puts("\nchannel: #{envelope.channel}: \nmsg: #{envelope.message}") }
|
354
|
-
end
|
355
|
-
end
|
391
|
+
def error_callback(error)
|
392
|
+
puts 'ERROR'.bg_red
|
393
|
+
ap error
|
394
|
+
end
|
356
395
|
end
|
396
|
+
|
397
|
+
DemoConsole.new
|