pubnub 3.3.0.7 → 3.4
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 +7 -0
- data/.gitignore +7 -0
- data/.yardoc/checksums +13 -0
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/LICENSE +27 -0
- data/README.md +259 -0
- data/Rakefile +7 -0
- data/VERSION +1 -0
- data/examples/demo_console.rb +198 -0
- data/examples/error_server.rb +28 -0
- data/examples/pubnub_livestream/.gitignore +16 -0
- data/examples/pubnub_livestream/Gemfile +51 -0
- data/examples/pubnub_livestream/Gemfile.lock +191 -0
- data/examples/pubnub_livestream/README.rdoc +28 -0
- data/examples/pubnub_livestream/Rakefile +6 -0
- data/examples/pubnub_livestream/app/assets/images/.keep +0 -0
- data/examples/pubnub_livestream/app/assets/javascripts/application.js +16 -0
- data/examples/pubnub_livestream/app/assets/javascripts/streamer.js.coffee +42 -0
- data/examples/pubnub_livestream/app/assets/stylesheets/application.css.sass +22 -0
- data/examples/pubnub_livestream/app/assets/stylesheets/streamer.css.scss +3 -0
- data/examples/pubnub_livestream/app/controllers/application_controller.rb +5 -0
- data/examples/pubnub_livestream/app/controllers/concerns/.keep +0 -0
- data/examples/pubnub_livestream/app/controllers/streamer_controller.rb +38 -0
- data/examples/pubnub_livestream/app/helpers/application_helper.rb +2 -0
- data/examples/pubnub_livestream/app/helpers/streamer_helper.rb +2 -0
- data/examples/pubnub_livestream/app/mailers/.keep +0 -0
- data/examples/pubnub_livestream/app/models/.keep +0 -0
- data/examples/pubnub_livestream/app/models/concerns/.keep +0 -0
- data/examples/pubnub_livestream/app/models/message.rb +11 -0
- data/examples/pubnub_livestream/app/views/layouts/application.html.erb +14 -0
- data/examples/pubnub_livestream/app/views/streamer/index.haml +22 -0
- data/examples/pubnub_livestream/bin/bundle +3 -0
- data/examples/pubnub_livestream/bin/rails +4 -0
- data/examples/pubnub_livestream/bin/rake +4 -0
- data/examples/pubnub_livestream/config.ru +4 -0
- data/examples/pubnub_livestream/config/application.rb +23 -0
- data/examples/pubnub_livestream/config/boot.rb +4 -0
- data/examples/pubnub_livestream/config/database.yml +25 -0
- data/examples/pubnub_livestream/config/environment.rb +5 -0
- data/examples/pubnub_livestream/config/environments/development.rb +29 -0
- data/examples/pubnub_livestream/config/environments/production.rb +80 -0
- data/examples/pubnub_livestream/config/environments/test.rb +36 -0
- data/examples/pubnub_livestream/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/pubnub_livestream/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/pubnub_livestream/config/initializers/inflections.rb +16 -0
- data/examples/pubnub_livestream/config/initializers/mime_types.rb +5 -0
- data/examples/pubnub_livestream/config/initializers/pubnub.rb +12 -0
- data/examples/pubnub_livestream/config/initializers/secret_token.rb +12 -0
- data/examples/pubnub_livestream/config/initializers/session_store.rb +3 -0
- data/examples/pubnub_livestream/config/initializers/wrap_parameters.rb +14 -0
- data/examples/pubnub_livestream/config/locales/en.yml +23 -0
- data/examples/pubnub_livestream/config/routes.rb +62 -0
- data/examples/pubnub_livestream/db/migrate/20130826110322_create_messages.rb +11 -0
- data/examples/pubnub_livestream/db/schema.rb +24 -0
- data/examples/pubnub_livestream/db/seeds.rb +7 -0
- data/examples/pubnub_livestream/lib/assets/.keep +0 -0
- data/examples/pubnub_livestream/lib/tasks/.keep +0 -0
- data/examples/pubnub_livestream/log/.keep +0 -0
- data/examples/pubnub_livestream/public/404.html +58 -0
- data/examples/pubnub_livestream/public/422.html +58 -0
- data/examples/pubnub_livestream/public/500.html +57 -0
- data/examples/pubnub_livestream/public/assets/application-22a604196dfb65fd0d602eb1eb65f9b7.js +4 -0
- data/examples/pubnub_livestream/public/assets/application-22a604196dfb65fd0d602eb1eb65f9b7.js.gz +0 -0
- data/examples/pubnub_livestream/public/assets/application-3fac0c014bbdf9ee7b3986ff615d5da0.css +5019 -0
- data/examples/pubnub_livestream/public/assets/application-3fac0c014bbdf9ee7b3986ff615d5da0.css.gz +0 -0
- data/examples/pubnub_livestream/public/assets/application-f06834e402639ad43230e3859b9bdd78.css +1 -0
- data/examples/pubnub_livestream/public/assets/application-f06834e402639ad43230e3859b9bdd78.css.gz +0 -0
- data/examples/pubnub_livestream/public/assets/application-f91b87f490140d86003c46b4d06b6c70.js +10682 -0
- data/examples/pubnub_livestream/public/assets/application-f91b87f490140d86003c46b4d06b6c70.js.gz +0 -0
- data/examples/pubnub_livestream/public/assets/manifest-c129e1f5ec52d8b661ebfa902554a2e2.json +1 -0
- data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-0bc0341283e3bb8ec518375794cc7c28.eot +0 -0
- data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-24dfb40c91db789b8b8faba6886ac1ef.svg +228 -0
- data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-4b2130768da98222338d1519f9179528.ttf +0 -0
- data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-7a07f26f72466361ac9671de2d33fd1c.woff +0 -0
- data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-9f75212cf9fca594cee7e0e3587db9d1.svg +228 -0
- data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-ab2f6984951c07fd89e6afdefabd93c7.eot +0 -0
- data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-c21928f7d46b397b0af6b9ee4a7bd0dd.ttf +0 -0
- data/examples/pubnub_livestream/public/assets/twitter/glyphicons-halflings-regular-fa1d7f79d80d03f8a598822bd9df79bf.woff +0 -0
- data/examples/pubnub_livestream/public/favicon.ico +0 -0
- data/examples/pubnub_livestream/public/robots.txt +5 -0
- data/examples/pubnub_livestream/test/controllers/.keep +0 -0
- data/examples/pubnub_livestream/test/controllers/streamer_controller_test.rb +7 -0
- data/examples/pubnub_livestream/test/fixtures/.keep +0 -0
- data/examples/pubnub_livestream/test/fixtures/messages.yml +9 -0
- data/examples/pubnub_livestream/test/helpers/.keep +0 -0
- data/examples/pubnub_livestream/test/helpers/streamer_helper_test.rb +4 -0
- data/examples/pubnub_livestream/test/integration/.keep +0 -0
- data/examples/pubnub_livestream/test/mailers/.keep +0 -0
- data/examples/pubnub_livestream/test/models/.keep +0 -0
- data/examples/pubnub_livestream/test/models/message_test.rb +7 -0
- data/examples/pubnub_livestream/test/test_helper.rb +15 -0
- data/examples/pubnub_livestream/vendor/assets/javascripts/.keep +0 -0
- data/examples/pubnub_livestream/vendor/assets/stylesheets/.keep +0 -0
- data/examples/serial_publish.rb +46 -0
- data/examples/sinatra/.sass-cache/65d837cc121fc62381bb76d93e5bd081356aa3f9/application.sassc +0 -0
- data/examples/sinatra/.sass-cache/d1525a8542f6e7fb2ecd3275251283768779b344/main.rbc +0 -0
- data/examples/sinatra/.sass-cache/d35765d68c1df11fa3368aa802b3d38109cba214/application.sassc +0 -0
- data/examples/sinatra/main.rb +54 -0
- data/examples/sinatra/public/bootstrap-responsive.min.css +9 -0
- data/examples/sinatra/public/bootstrap.css +5909 -0
- data/examples/sinatra/public/bootstrap.min.css +845 -0
- data/examples/sinatra/public/jquery-1.10.2.min.js +5 -0
- data/examples/sinatra/views/application.sass +6 -0
- data/examples/sinatra/views/index.slim +16 -0
- data/examples/sinatra/views/layout.slim +12 -0
- data/examples/sinatra/views/streamer.coffee +41 -0
- data/examples/sub_and_unsub_1.rb +56 -0
- data/examples/translator.rb +129 -0
- data/lib/pubnub.rb +31 -375
- data/lib/pubnub/client.rb +527 -0
- data/lib/pubnub/configuration.rb +25 -0
- data/lib/pubnub/crypto.rb +53 -0
- data/lib/pubnub/error.rb +23 -0
- data/lib/pubnub/request.rb +288 -0
- data/lib/pubnub/response.rb +126 -0
- data/lib/pubnub/subscription.rb +24 -0
- data/lib/tasks/examples.rake +39 -0
- data/lib/version.rb +1 -0
- data/pubnub.gemspec +26 -0
- data/spec/lib/client_spec.rb +346 -0
- data/spec/lib/crypto_spec.rb +89 -0
- data/spec/lib/history_integration_spec.rb +0 -0
- data/spec/lib/presence_integration_spec.rb +16 -0
- data/spec/lib/publish_integration_spec.rb +994 -0
- data/spec/lib/pubnub_spec.rb +12 -0
- data/spec/lib/request_spec.rb +151 -0
- data/spec/lib/subscribe_integration_spec.rb +944 -0
- data/spec/lib/time_integration_spec.rb +0 -0
- data/spec/spec_helper.rb +15 -0
- metadata +158 -45
- data/lib/pubnub_crypto.rb +0 -53
- data/lib/pubnub_request.rb +0 -310
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rr'
|
3
|
+
require 'vcr'
|
4
|
+
|
5
|
+
describe Pubnub::Request do
|
6
|
+
before do
|
7
|
+
@pubnub_request = Pubnub::Request.new(
|
8
|
+
:subscribe_key => 'subscribe_key',
|
9
|
+
:origin => 'pubsub.pubnub.com'
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'origin' do
|
14
|
+
context 'port' do
|
15
|
+
it 'set port to 80 and http when ssl isn\'t set' do
|
16
|
+
@pubnub_request.ssl = false
|
17
|
+
@pubnub_request.port.should eq 80
|
18
|
+
@pubnub_request.origin[0..4].should eq 'http:'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'set port to 443 and http when ssl isn\'t set' do
|
22
|
+
@pubnub_request.ssl = true
|
23
|
+
@pubnub_request.port.should eq 443
|
24
|
+
@pubnub_request.origin[0..4].should eq 'https'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'created path' do
|
30
|
+
context 'when operation' do
|
31
|
+
context 'is publish' do
|
32
|
+
context 'and it\'s not encrypted' do
|
33
|
+
it 'is valid' do
|
34
|
+
@pubnub_request = Pubnub::Request.new(
|
35
|
+
:operation => 'publish',
|
36
|
+
:channel => 'channel',
|
37
|
+
:subscribe_key => 'subscribe_key',
|
38
|
+
:origin => 'pubsub.pubnub.com',
|
39
|
+
:publish_key => 'publish_key',
|
40
|
+
:message => 'test_message'
|
41
|
+
)
|
42
|
+
|
43
|
+
@pubnub_request.path.should eq '/publish/publish_key/subscribe_key/0/channel/0/%22test_message%22'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
context 'and it\'s encrypted' do
|
47
|
+
it 'is valid' do
|
48
|
+
@pubnub_request = Pubnub::Request.new(
|
49
|
+
:operation => 'publish',
|
50
|
+
:channel => 'channel',
|
51
|
+
:subscribe_key => 'subscribe_key',
|
52
|
+
:origin => 'pubsub.pubnub.com',
|
53
|
+
:publish_key => 'publish_key',
|
54
|
+
:message => 'test_message',
|
55
|
+
:cipher_key => 'so_secret_key'
|
56
|
+
)
|
57
|
+
|
58
|
+
@pubnub_request.path.should eq '/publish/publish_key/subscribe_key/0/channel/0/%22OfUPhgfENucj3lsbSef1qg==%22'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'is subscribe' do
|
64
|
+
it 'is valid' do
|
65
|
+
@pubnub_request = Pubnub::Request.new(
|
66
|
+
:operation => 'subscribe',
|
67
|
+
:channel => 'channel',
|
68
|
+
:subscribe_key => 'subscribe_key',
|
69
|
+
:origin => 'pubsub.pubnub.com',
|
70
|
+
:publish_key => 'publish_key'
|
71
|
+
)
|
72
|
+
|
73
|
+
@pubnub_request.path.should eq '/subscribe/subscribe_key/channel/0/0'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'is history' do
|
78
|
+
it 'is valid' do
|
79
|
+
@pubnub_request = Pubnub::Request.new(
|
80
|
+
:operation => 'history',
|
81
|
+
:channel => 'channel',
|
82
|
+
:subscribe_key => 'subscribe_key',
|
83
|
+
:origin => 'pubsub.pubnub.com',
|
84
|
+
:publish_key => 'publish_key'
|
85
|
+
)
|
86
|
+
|
87
|
+
@pubnub_request.path.should eq '/v2/history/sub-key/subscribe_key/channel/channel'
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'is presence' do
|
93
|
+
it 'is valid' do
|
94
|
+
@pubnub_request = Pubnub::Request.new(
|
95
|
+
:operation => 'presence',
|
96
|
+
:channel => 'channel',
|
97
|
+
:subscribe_key => 'subscribe_key',
|
98
|
+
:origin => 'pubsub.pubnub.com',
|
99
|
+
:publish_key => 'publish_key'
|
100
|
+
)
|
101
|
+
|
102
|
+
@pubnub_request.path.should eq '/subscribe/subscribe_key/channel-pnpres/0/0'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'is here_now' do
|
107
|
+
it 'is valid' do
|
108
|
+
@pubnub_request = Pubnub::Request.new(
|
109
|
+
:operation => 'here_now',
|
110
|
+
:channel => 'channel',
|
111
|
+
:subscribe_key => 'subscribe_key',
|
112
|
+
:origin => 'pubsub.pubnub.com',
|
113
|
+
:publish_key => 'publish_key'
|
114
|
+
)
|
115
|
+
|
116
|
+
@pubnub_request.path.should eq '/v2/presence/sub-key/subscribe_key/channel/channel'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'is time' do
|
121
|
+
it 'is valid' do
|
122
|
+
@pubnub_request = Pubnub::Request.new(
|
123
|
+
:operation => 'time',
|
124
|
+
:channel => 'channel',
|
125
|
+
:subscribe_key => 'subscribe_key',
|
126
|
+
:origin => 'pubsub.pubnub.com',
|
127
|
+
:publish_key => 'publish_key'
|
128
|
+
)
|
129
|
+
|
130
|
+
@pubnub_request.path.should eq '/time/0'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe 'created query' do
|
137
|
+
it 'fits to passed parameters' do
|
138
|
+
params = { :uuid => '123-123-123', :some_val => 'value' }
|
139
|
+
@pubnub_request = Pubnub::Request.new(
|
140
|
+
:operation => 'time',
|
141
|
+
:channel => 'channel',
|
142
|
+
:subscribe_key => 'subscribe_key',
|
143
|
+
:origin => 'pubsub.pubnub.com',
|
144
|
+
:publish_key => 'publish_key',
|
145
|
+
:params => params
|
146
|
+
)
|
147
|
+
|
148
|
+
@pubnub_request.query.should eq 'some_val=value&uuid=123-123-123'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,944 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe '#subscribe' do
|
4
|
+
before do
|
5
|
+
EM.stop if EM.reactor_running?
|
6
|
+
stub_request(:get, 'http://pubsub.pubnub.com/v2/presence/sub-key/demo/channel/demo/leave').
|
7
|
+
to_return(
|
8
|
+
{
|
9
|
+
:body => '{"action": "leave"}',
|
10
|
+
:status => 200,
|
11
|
+
:headers => {
|
12
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
13
|
+
}
|
14
|
+
}
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when it gets server error' do
|
19
|
+
|
20
|
+
before(:each) do
|
21
|
+
@after_callback = false
|
22
|
+
@output = StringIO.new
|
23
|
+
@error_output = StringIO.new
|
24
|
+
@msg_output = StringIO.new
|
25
|
+
|
26
|
+
@callback = lambda { |envelope|
|
27
|
+
$log.debug 'FIRE CALLBACK'
|
28
|
+
@after_callback = true
|
29
|
+
@output.write envelope.response
|
30
|
+
@msg_output.write envelope.msg
|
31
|
+
EM.stop if EM.reactor_running?
|
32
|
+
}
|
33
|
+
|
34
|
+
@error_callback = lambda { |envelope|
|
35
|
+
$log.error envelope.response
|
36
|
+
@error_output.write envelope.response
|
37
|
+
@after_error_callback = true
|
38
|
+
}
|
39
|
+
|
40
|
+
@pn = Pubnub.new(:publish_key => :demo, :subscribe_key => :demo, :error_callback => @error_callback)
|
41
|
+
@pn.session_uuid = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'via http' do
|
45
|
+
context 'and response message is usable' do
|
46
|
+
before(:each) do
|
47
|
+
@counter = 0
|
48
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/subscribe\/demo\/demo\/0\/\d+/).
|
49
|
+
to_return(lambda { |request|
|
50
|
+
@counter += 1
|
51
|
+
if @counter < 10
|
52
|
+
{
|
53
|
+
:body => [500, 'Error msg'].to_json,
|
54
|
+
:status => 500,
|
55
|
+
:headers => {
|
56
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
57
|
+
}
|
58
|
+
}
|
59
|
+
else
|
60
|
+
{
|
61
|
+
:body => [[{"text" => "hey"}],"#{/\d+$/.match(request.uri.path).to_s.to_i + 1}"].to_json,
|
62
|
+
:status => 200,
|
63
|
+
:headers => {
|
64
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
65
|
+
}
|
66
|
+
}
|
67
|
+
end
|
68
|
+
}
|
69
|
+
)
|
70
|
+
|
71
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/time\/0/).
|
72
|
+
to_return(
|
73
|
+
{
|
74
|
+
:body => '[13804562752311765]',
|
75
|
+
:status => 200,
|
76
|
+
:headers => {
|
77
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
78
|
+
}
|
79
|
+
}
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'and it\'s synchronous' do
|
84
|
+
before(:each) do
|
85
|
+
@http_sync = true
|
86
|
+
end
|
87
|
+
it 'fires given callback on response envelope and retry' do
|
88
|
+
response_regex = /text.*hey\D*\d*/
|
89
|
+
|
90
|
+
$log.debug 'START #SUBSCRIBE SPEC #7'
|
91
|
+
|
92
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
93
|
+
|
94
|
+
@output.seek(0)
|
95
|
+
|
96
|
+
@output.read.should match response_regex
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'fires given block on response envelope and retry' do
|
100
|
+
response_regex = /text.*hey\D*\d*/
|
101
|
+
|
102
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
103
|
+
|
104
|
+
@output.seek(0)
|
105
|
+
|
106
|
+
@output.read.should match response_regex
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'and it\'s asynchronous' do
|
111
|
+
before(:each) do
|
112
|
+
@http_sync = false
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'fires given callback on response envelope and retry' do
|
116
|
+
response_regex = /text.*hey\D*\d*/
|
117
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
118
|
+
until @after_callback do end
|
119
|
+
@output.seek(0)
|
120
|
+
@output.read.should match response_regex
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'fires given block on response envelope and retry' do
|
124
|
+
response_regex = /text.*hey\D*\d*/
|
125
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
126
|
+
until @after_callback do end
|
127
|
+
@output.seek(0)
|
128
|
+
@output.read.should match response_regex
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'and response message is not usable' do
|
134
|
+
before(:each) do
|
135
|
+
@counter = 0
|
136
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/subscribe\/demo\/demo\/0\/\d+/).
|
137
|
+
to_return(lambda { |request|
|
138
|
+
@counter += 1
|
139
|
+
if @counter < 10
|
140
|
+
{
|
141
|
+
:body => '2132131asad@!EASD#!',
|
142
|
+
:status => 500,
|
143
|
+
:headers => {
|
144
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
145
|
+
}
|
146
|
+
}
|
147
|
+
else
|
148
|
+
@counter = 0
|
149
|
+
{
|
150
|
+
:body => [[{"text" => "hey"}],"#{/\d+$/.match(request.uri.path).to_s.to_i + 1}"].to_json,
|
151
|
+
:status => 200,
|
152
|
+
:headers => {
|
153
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
154
|
+
}
|
155
|
+
}
|
156
|
+
end
|
157
|
+
}
|
158
|
+
)
|
159
|
+
|
160
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/time\/0/).
|
161
|
+
to_return(
|
162
|
+
{
|
163
|
+
:body => '[13804562752311765]',
|
164
|
+
:status => 200,
|
165
|
+
:headers => {
|
166
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
167
|
+
}
|
168
|
+
}
|
169
|
+
)
|
170
|
+
end
|
171
|
+
context 'and it\'s synchronous' do
|
172
|
+
before(:each) do
|
173
|
+
@http_sync = true
|
174
|
+
end
|
175
|
+
it 'fires given callback on response envelope and retry' do
|
176
|
+
response_regex = /text.*hey\D*\d*/
|
177
|
+
|
178
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
179
|
+
|
180
|
+
@output.seek(0)
|
181
|
+
|
182
|
+
@output.read.should match response_regex
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'fires given block on response envelope and retry' do
|
186
|
+
response_regex = /text.*hey\D*\d*/
|
187
|
+
|
188
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
189
|
+
|
190
|
+
@output.seek(0)
|
191
|
+
|
192
|
+
@output.read.should match response_regex
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
context 'and it\'s asynchronous' do
|
197
|
+
before(:each) do
|
198
|
+
@http_sync = false
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'fires given callback on response envelope and retry' do
|
202
|
+
response_regex = /text.*hey\D*\d*/
|
203
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
204
|
+
until @after_callback do end
|
205
|
+
@output.seek(0)
|
206
|
+
@output.read.should match response_regex
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'fires given block on response envelope and retry' do
|
210
|
+
response_regex = /text.*hey\D*\d*/
|
211
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
212
|
+
until @after_callback do end
|
213
|
+
@output.seek(0)
|
214
|
+
@output.read.should match response_regex
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context 'via https' do
|
221
|
+
before do
|
222
|
+
@pn.ssl = true
|
223
|
+
end
|
224
|
+
context 'and response message is usable' do
|
225
|
+
before(:each) do
|
226
|
+
@counter = 0
|
227
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/subscribe\/demo\/demo\/0\/\d+/).
|
228
|
+
to_return(lambda { |request|
|
229
|
+
@counter += 1
|
230
|
+
if @counter < 10
|
231
|
+
{
|
232
|
+
:body => [500, 'Error msg'].to_json,
|
233
|
+
:status => 500,
|
234
|
+
:headers => {
|
235
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
236
|
+
}
|
237
|
+
}
|
238
|
+
else
|
239
|
+
{
|
240
|
+
:body => [[{"text" => "hey"}],"#{/\d+$/.match(request.uri.path).to_s.to_i + 1}"].to_json,
|
241
|
+
:status => 200,
|
242
|
+
:headers => {
|
243
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
244
|
+
}
|
245
|
+
}
|
246
|
+
end
|
247
|
+
}
|
248
|
+
)
|
249
|
+
|
250
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/time\/0/).
|
251
|
+
to_return(
|
252
|
+
{
|
253
|
+
:body => '[13804562752311765]',
|
254
|
+
:status => 200,
|
255
|
+
:headers => {
|
256
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
257
|
+
}
|
258
|
+
}
|
259
|
+
)
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'and it\'s synchronous' do
|
263
|
+
before(:each) do
|
264
|
+
@http_sync = true
|
265
|
+
end
|
266
|
+
it 'fires given callback on response envelope and retry' do
|
267
|
+
response_regex = /text.*hey\D*\d*/
|
268
|
+
|
269
|
+
$log.debug 'START #SUBSCRIBE SPEC #7'
|
270
|
+
|
271
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
272
|
+
|
273
|
+
@output.seek(0)
|
274
|
+
|
275
|
+
@output.read.should match response_regex
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'fires given block on response envelope and retry' do
|
279
|
+
response_regex = /text.*hey\D*\d*/
|
280
|
+
|
281
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
282
|
+
|
283
|
+
@output.seek(0)
|
284
|
+
|
285
|
+
@output.read.should match response_regex
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
context 'and it\'s asynchronous' do
|
290
|
+
before(:each) do
|
291
|
+
@http_sync = false
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'fires given callback on response envelope and retry' do
|
295
|
+
response_regex = /text.*hey\D*\d*/
|
296
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
297
|
+
until @after_callback do end
|
298
|
+
@output.seek(0)
|
299
|
+
@output.read.should match response_regex
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'fires given block on response envelope and retry' do
|
303
|
+
response_regex = /text.*hey\D*\d*/
|
304
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
305
|
+
until @after_callback do end
|
306
|
+
@output.seek(0)
|
307
|
+
@output.read.should match response_regex
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
context 'and response message is not usable' do
|
313
|
+
before(:each) do
|
314
|
+
@counter = 0
|
315
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/subscribe\/demo\/demo\/0\/\d+/).
|
316
|
+
to_return(lambda { |request|
|
317
|
+
@counter += 1
|
318
|
+
if @counter < 10
|
319
|
+
{
|
320
|
+
:body => '2132131asad@!EASD#!',
|
321
|
+
:status => 500,
|
322
|
+
:headers => {
|
323
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
324
|
+
}
|
325
|
+
}
|
326
|
+
else
|
327
|
+
@counter = 0
|
328
|
+
{
|
329
|
+
:body => [[{"text" => "hey"}],"#{/\d+$/.match(request.uri.path).to_s.to_i + 1}"].to_json,
|
330
|
+
:status => 200,
|
331
|
+
:headers => {
|
332
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
333
|
+
}
|
334
|
+
}
|
335
|
+
end
|
336
|
+
}
|
337
|
+
)
|
338
|
+
|
339
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/time\/0/).
|
340
|
+
to_return(
|
341
|
+
{
|
342
|
+
:body => '[13804562752311765]',
|
343
|
+
:status => 200,
|
344
|
+
:headers => {
|
345
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
346
|
+
}
|
347
|
+
}
|
348
|
+
)
|
349
|
+
end
|
350
|
+
context 'and it\'s synchronous' do
|
351
|
+
before(:each) do
|
352
|
+
@http_sync = true
|
353
|
+
end
|
354
|
+
it 'fires given callback on response envelope and retry' do
|
355
|
+
response_regex = /text.*hey\D*\d*/
|
356
|
+
|
357
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
358
|
+
|
359
|
+
@output.seek(0)
|
360
|
+
|
361
|
+
@output.read.should match response_regex
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'fires given block on response envelope and retry' do
|
365
|
+
response_regex = /text.*hey\D*\d*/
|
366
|
+
|
367
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
368
|
+
|
369
|
+
@output.seek(0)
|
370
|
+
|
371
|
+
@output.read.should match response_regex
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
context 'and it\'s asynchronous' do
|
376
|
+
before(:each) do
|
377
|
+
@http_sync = false
|
378
|
+
end
|
379
|
+
|
380
|
+
it 'fires given callback on response envelope and retry' do
|
381
|
+
response_regex = /text.*hey\D*\d*/
|
382
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
383
|
+
until @after_callback do end
|
384
|
+
@output.seek(0)
|
385
|
+
@output.read.should match response_regex
|
386
|
+
end
|
387
|
+
|
388
|
+
it 'fires given block on response envelope and retry' do
|
389
|
+
response_regex = /text.*hey\D*\d*/
|
390
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
391
|
+
until @after_callback do end
|
392
|
+
@output.seek(0)
|
393
|
+
@output.read.should match response_regex
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
context 'it gets correct single message' do
|
401
|
+
|
402
|
+
before(:each) do
|
403
|
+
@after_callback = false
|
404
|
+
@output = StringIO.new
|
405
|
+
@error_output = StringIO.new
|
406
|
+
@msg_output = StringIO.new
|
407
|
+
|
408
|
+
@callback = lambda { |envelope|
|
409
|
+
$log.debug 'FIRE CALLBACK'
|
410
|
+
@after_callback = true
|
411
|
+
@output.write envelope.response
|
412
|
+
@msg_output.write envelope.msg
|
413
|
+
EM.stop if EM.reactor_running?
|
414
|
+
}
|
415
|
+
|
416
|
+
@error_callback = lambda { |envelope|
|
417
|
+
$log.error envelope.response
|
418
|
+
@error_output.write envelope.response
|
419
|
+
@after_error_callback = true
|
420
|
+
}
|
421
|
+
|
422
|
+
@pn = Pubnub.new(:publish_key => :demo, :subscribe_key => :demo, :error_callback => @error_callback)
|
423
|
+
@pn.session_uuid = nil
|
424
|
+
end
|
425
|
+
|
426
|
+
before(:each) do
|
427
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/subscribe\/demo\/demo\/0\/\d+/).
|
428
|
+
to_return(lambda { |request|
|
429
|
+
{
|
430
|
+
:body => [[{"text" => "hey"}],"#{/\d+$/.match(request.uri.path).to_s.to_i + 1}"].to_json,
|
431
|
+
:status => 200,
|
432
|
+
:headers => {
|
433
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
434
|
+
}
|
435
|
+
}
|
436
|
+
}
|
437
|
+
)
|
438
|
+
|
439
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/time\/0/).
|
440
|
+
to_return(
|
441
|
+
{
|
442
|
+
:body => '[13804562752311765]',
|
443
|
+
:status => 200,
|
444
|
+
:headers => {
|
445
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
446
|
+
}
|
447
|
+
}
|
448
|
+
)
|
449
|
+
end
|
450
|
+
context 'without secret key' do
|
451
|
+
context 'without cipher_key' do
|
452
|
+
context 'via http' do
|
453
|
+
context 'and it\'s asynchronous' do
|
454
|
+
before(:each) do
|
455
|
+
@http_sync = false
|
456
|
+
end
|
457
|
+
it 'fires given callback on response envelope and retry' do
|
458
|
+
response_regex = /text.*hey\D*\d*/
|
459
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
460
|
+
until @after_callback do end
|
461
|
+
@output.seek(0)
|
462
|
+
@output.read.should match response_regex
|
463
|
+
end
|
464
|
+
|
465
|
+
it 'fires given block on response envelope and retry' do
|
466
|
+
response_regex = /text.*hey\D*\d*/
|
467
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
468
|
+
until @after_callback do end
|
469
|
+
@output.seek(0)
|
470
|
+
@output.read.should match response_regex
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
context 'and it\'s synchronous' do
|
475
|
+
before(:each) do
|
476
|
+
@http_sync = true
|
477
|
+
end
|
478
|
+
it 'fires given callback on response envelope and retry' do
|
479
|
+
response_regex = /text.*hey\D*\d*/
|
480
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
481
|
+
until @after_callback do end
|
482
|
+
@output.seek(0)
|
483
|
+
@output.read.should match response_regex
|
484
|
+
end
|
485
|
+
|
486
|
+
it 'fires given block on response envelope and retry' do
|
487
|
+
response_regex = /text.*hey\D*\d*/
|
488
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
489
|
+
until @after_callback do end
|
490
|
+
@output.seek(0)
|
491
|
+
@output.read.should match response_regex
|
492
|
+
end
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
context 'via https' do
|
497
|
+
before do
|
498
|
+
@pn.ssl = true
|
499
|
+
end
|
500
|
+
context 'and it\'s asynchronous' do
|
501
|
+
before(:each) do
|
502
|
+
@http_sync = false
|
503
|
+
end
|
504
|
+
context 'and it\'s asynchronous' do
|
505
|
+
before(:each) do
|
506
|
+
@http_sync = false
|
507
|
+
end
|
508
|
+
it 'fires given callback on response envelope and retry' do
|
509
|
+
response_regex = /text.*hey\D*\d*/
|
510
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
511
|
+
until @after_callback do end
|
512
|
+
@output.seek(0)
|
513
|
+
@output.read.should match response_regex
|
514
|
+
end
|
515
|
+
|
516
|
+
it 'fires given block on response envelope and retry' do
|
517
|
+
response_regex = /text.*hey\D*\d*/
|
518
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
519
|
+
until @after_callback do end
|
520
|
+
@output.seek(0)
|
521
|
+
@output.read.should match response_regex
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
context 'and it\'s synchronous' do
|
526
|
+
before(:each) do
|
527
|
+
@http_sync = true
|
528
|
+
end
|
529
|
+
it 'fires given callback on response envelope and retry' do
|
530
|
+
response_regex = /text.*hey\D*\d*/
|
531
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
532
|
+
until @after_callback do end
|
533
|
+
@output.seek(0)
|
534
|
+
@output.read.should match response_regex
|
535
|
+
end
|
536
|
+
|
537
|
+
it 'fires given block on response envelope and retry' do
|
538
|
+
response_regex = /text.*hey\D*\d*/
|
539
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
540
|
+
until @after_callback do end
|
541
|
+
@output.seek(0)
|
542
|
+
@output.read.should match response_regex
|
543
|
+
end
|
544
|
+
end
|
545
|
+
end
|
546
|
+
end
|
547
|
+
end
|
548
|
+
|
549
|
+
context 'using cipher_key' do
|
550
|
+
before do
|
551
|
+
@pn.cipher_key = 'enigma'
|
552
|
+
|
553
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/subscribe\/demo\/demo\/0\/\d+/).
|
554
|
+
to_return(lambda { |request|
|
555
|
+
{
|
556
|
+
:body => ["E8VOcbfrYqLyHMtoVGv9UQ==","#{/\d+$/.match(request.uri.path).to_s.to_i + 1}"].to_json,
|
557
|
+
:status => 200,
|
558
|
+
:headers => {
|
559
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
560
|
+
}
|
561
|
+
}
|
562
|
+
}
|
563
|
+
)
|
564
|
+
|
565
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/time\/0/).
|
566
|
+
to_return(
|
567
|
+
{
|
568
|
+
:body => '[13804562752311765]',
|
569
|
+
:status => 200,
|
570
|
+
:headers => {
|
571
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
572
|
+
}
|
573
|
+
}
|
574
|
+
)
|
575
|
+
end
|
576
|
+
context 'via http' do
|
577
|
+
context 'and it\'s synchronous' do
|
578
|
+
before(:each) do
|
579
|
+
@http_sync = true
|
580
|
+
end
|
581
|
+
it 'fires given callback on response envelope and retry' do
|
582
|
+
response_regex = /text.*hey\D*\d*/
|
583
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
584
|
+
until @after_callback do end
|
585
|
+
@msg_output.seek(0)
|
586
|
+
@msg_output.read.should match response_regex
|
587
|
+
end
|
588
|
+
|
589
|
+
it 'fires given block on response envelope and retry' do
|
590
|
+
response_regex = /text.*hey\D*\d*/
|
591
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
592
|
+
until @after_callback do end
|
593
|
+
@msg_output.seek(0)
|
594
|
+
@msg_output.read.should match response_regex
|
595
|
+
end
|
596
|
+
end
|
597
|
+
|
598
|
+
context 'and it\'s asynchronous' do
|
599
|
+
before(:each) do
|
600
|
+
@http_sync = false
|
601
|
+
end
|
602
|
+
it 'fires given callback on response envelope and retry' do
|
603
|
+
response_regex = /text.*hey\D*\d*/
|
604
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
605
|
+
until @after_callback do end
|
606
|
+
@msg_output.seek(0)
|
607
|
+
@msg_output.read.should match response_regex
|
608
|
+
end
|
609
|
+
|
610
|
+
it 'fires given block on response envelope and retry' do
|
611
|
+
response_regex = /text.*hey\D*\d*/
|
612
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
613
|
+
until @after_callback do end
|
614
|
+
@msg_output.seek(0)
|
615
|
+
@msg_output.read.should match response_regex
|
616
|
+
end
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
context 'via https' do
|
621
|
+
before do
|
622
|
+
@pn.ssl = true
|
623
|
+
end
|
624
|
+
context 'and it\'s asynchronous' do
|
625
|
+
before(:each) do
|
626
|
+
@http_sync = false
|
627
|
+
end
|
628
|
+
it 'fires given callback on response envelope and retry' do
|
629
|
+
response_regex = /text.*hey\D*\d*/
|
630
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
631
|
+
until @after_callback do end
|
632
|
+
@msg_output.seek(0)
|
633
|
+
@msg_output.read.should match response_regex
|
634
|
+
end
|
635
|
+
|
636
|
+
it 'fires given block on response envelope and retry' do
|
637
|
+
response_regex = /text.*hey\D*\d*/
|
638
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
639
|
+
until @after_callback do end
|
640
|
+
@msg_output.seek(0)
|
641
|
+
@msg_output.read.should match response_regex
|
642
|
+
end
|
643
|
+
end
|
644
|
+
|
645
|
+
context 'and it\'s synchronous' do
|
646
|
+
before(:each) do
|
647
|
+
@http_sync = true
|
648
|
+
end
|
649
|
+
it 'fires given callback on response envelope and retry' do
|
650
|
+
response_regex = /text.*hey\D*\d*/
|
651
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
652
|
+
until @after_callback do end
|
653
|
+
@msg_output.seek(0)
|
654
|
+
@msg_output.read.should match response_regex
|
655
|
+
end
|
656
|
+
|
657
|
+
it 'fires given block on response envelope and retry' do
|
658
|
+
response_regex = /text.*hey\D*\d*/
|
659
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
660
|
+
until @after_callback do end
|
661
|
+
@msg_output.seek(0)
|
662
|
+
@msg_output.read.should match response_regex
|
663
|
+
end
|
664
|
+
end
|
665
|
+
end
|
666
|
+
end
|
667
|
+
end
|
668
|
+
end
|
669
|
+
|
670
|
+
context 'it gets correct multiple message' do
|
671
|
+
|
672
|
+
before(:each) do
|
673
|
+
@after_callback = false
|
674
|
+
@output = StringIO.new
|
675
|
+
@error_output = StringIO.new
|
676
|
+
@msg_output = StringIO.new
|
677
|
+
@first_callback_done = false
|
678
|
+
|
679
|
+
@callback = lambda { |envelope|
|
680
|
+
$log.debug 'FIRE CALLBACK'
|
681
|
+
@output.write envelope.response
|
682
|
+
@msg_output.write envelope.msg
|
683
|
+
if @first_callback_done
|
684
|
+
EM.stop if EM.reactor_running?
|
685
|
+
@after_callback = true
|
686
|
+
else
|
687
|
+
@first_callback_done = true
|
688
|
+
end
|
689
|
+
}
|
690
|
+
|
691
|
+
@error_callback = lambda { |envelope|
|
692
|
+
$log.error envelope.response
|
693
|
+
@error_output.write envelope.response
|
694
|
+
@after_error_callback = true
|
695
|
+
}
|
696
|
+
|
697
|
+
@pn = Pubnub.new(:publish_key => :demo, :subscribe_key => :demo, :error_callback => @error_callback)
|
698
|
+
@pn.session_uuid = nil
|
699
|
+
end
|
700
|
+
|
701
|
+
before(:each) do
|
702
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/subscribe\/demo\/demo\/0\/\d+/).
|
703
|
+
to_return(lambda { |request|
|
704
|
+
{
|
705
|
+
:body => [[{"text" => "hey"},{"text" => "hey"}],"#{/\d+$/.match(request.uri.path).to_s.to_i + 1}"].to_json,
|
706
|
+
:status => 200,
|
707
|
+
:headers => {
|
708
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
709
|
+
}
|
710
|
+
}
|
711
|
+
}
|
712
|
+
)
|
713
|
+
|
714
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/time\/0/).
|
715
|
+
to_return(
|
716
|
+
{
|
717
|
+
:body => '[13804562752311765]',
|
718
|
+
:status => 200,
|
719
|
+
:headers => {
|
720
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
721
|
+
}
|
722
|
+
}
|
723
|
+
)
|
724
|
+
end
|
725
|
+
context 'without secret key' do
|
726
|
+
context 'without cipher_key' do
|
727
|
+
context 'via http' do
|
728
|
+
context 'and it\'s asynchronous' do
|
729
|
+
before(:each) do
|
730
|
+
@http_sync = false
|
731
|
+
end
|
732
|
+
it 'fires given callback on response envelope and retry' do
|
733
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
734
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
735
|
+
until @after_callback do end
|
736
|
+
@output.seek(0)
|
737
|
+
@output.read.should match response_regex
|
738
|
+
end
|
739
|
+
|
740
|
+
it 'fires given block on response envelope and retry' do
|
741
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
742
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
743
|
+
until @after_callback do end
|
744
|
+
@output.seek(0)
|
745
|
+
@output.read.should match response_regex
|
746
|
+
end
|
747
|
+
end
|
748
|
+
|
749
|
+
context 'and it\'s synchronous' do
|
750
|
+
before(:each) do
|
751
|
+
@http_sync = true
|
752
|
+
end
|
753
|
+
it 'fires given callback on response envelope and retry' do
|
754
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
755
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
756
|
+
until @after_callback do end
|
757
|
+
@output.seek(0)
|
758
|
+
@output.read.should match response_regex
|
759
|
+
end
|
760
|
+
|
761
|
+
it 'fires given block on response envelope and retry' do
|
762
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
763
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
764
|
+
until @after_callback do end
|
765
|
+
@output.seek(0)
|
766
|
+
@output.read.should match response_regex
|
767
|
+
end
|
768
|
+
end
|
769
|
+
end
|
770
|
+
|
771
|
+
context 'via https' do
|
772
|
+
before do
|
773
|
+
@pn.ssl = true
|
774
|
+
end
|
775
|
+
context 'and it\'s asynchronous' do
|
776
|
+
before(:each) do
|
777
|
+
@http_sync = false
|
778
|
+
end
|
779
|
+
context 'and it\'s asynchronous' do
|
780
|
+
before(:each) do
|
781
|
+
@http_sync = false
|
782
|
+
end
|
783
|
+
it 'fires given callback on response envelope and retry' do
|
784
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
785
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
786
|
+
until @after_callback do end
|
787
|
+
@output.seek(0)
|
788
|
+
@output.read.should match response_regex
|
789
|
+
end
|
790
|
+
|
791
|
+
it 'fires given block on response envelope and retry' do
|
792
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
793
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
794
|
+
until @after_callback do end
|
795
|
+
@output.seek(0)
|
796
|
+
@output.read.should match response_regex
|
797
|
+
end
|
798
|
+
end
|
799
|
+
|
800
|
+
context 'and it\'s synchronous' do
|
801
|
+
before(:each) do
|
802
|
+
@http_sync = true
|
803
|
+
end
|
804
|
+
it 'fires given callback on response envelope and retry' do
|
805
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
806
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
807
|
+
until @after_callback do end
|
808
|
+
@output.seek(0)
|
809
|
+
@output.read.should match response_regex
|
810
|
+
end
|
811
|
+
|
812
|
+
it 'fires given block on response envelope and retry' do
|
813
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
814
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
815
|
+
until @after_callback do end
|
816
|
+
@output.seek(0)
|
817
|
+
@output.read.should match response_regex
|
818
|
+
end
|
819
|
+
end
|
820
|
+
end
|
821
|
+
end
|
822
|
+
end
|
823
|
+
|
824
|
+
context 'using cipher_key' do
|
825
|
+
before do
|
826
|
+
@pn.cipher_key = 'enigma'
|
827
|
+
|
828
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/subscribe\/demo\/demo\/0\/\d+/).
|
829
|
+
to_return(lambda { |request|
|
830
|
+
{
|
831
|
+
:body => [["E8VOcbfrYqLyHMtoVGv9UQ==","E8VOcbfrYqLyHMtoVGv9UQ=="],"#{/\d+$/.match(request.uri.path).to_s.to_i + 1}"].to_json,
|
832
|
+
:status => 200,
|
833
|
+
:headers => {
|
834
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
835
|
+
}
|
836
|
+
}
|
837
|
+
}
|
838
|
+
)
|
839
|
+
|
840
|
+
stub_request(:get, /http[s]?:\/\/pubsub.pubnub.com\/time\/0/).
|
841
|
+
to_return(
|
842
|
+
{
|
843
|
+
:body => '[13804562752311765]',
|
844
|
+
:status => 200,
|
845
|
+
:headers => {
|
846
|
+
'Content-Type' => 'text/javascript; charset="UTF-8"'
|
847
|
+
}
|
848
|
+
}
|
849
|
+
)
|
850
|
+
end
|
851
|
+
context 'via http' do
|
852
|
+
context 'and it\'s synchronous' do
|
853
|
+
before(:each) do
|
854
|
+
@http_sync = true
|
855
|
+
end
|
856
|
+
it 'fires given callback on response envelope and retry' do
|
857
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
858
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
859
|
+
until @after_callback do end
|
860
|
+
@msg_output.seek(0)
|
861
|
+
@msg_output.read.should match response_regex
|
862
|
+
end
|
863
|
+
|
864
|
+
it 'fires given block on response envelope and retry' do
|
865
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
866
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
867
|
+
until @after_callback do end
|
868
|
+
@msg_output.seek(0)
|
869
|
+
@msg_output.read.should match response_regex
|
870
|
+
end
|
871
|
+
end
|
872
|
+
|
873
|
+
context 'and it\'s asynchronous' do
|
874
|
+
before(:each) do
|
875
|
+
@http_sync = false
|
876
|
+
end
|
877
|
+
it 'fires given callback on response envelope and retry' do
|
878
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
879
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
880
|
+
until @after_callback do end
|
881
|
+
@msg_output.seek(0)
|
882
|
+
@msg_output.read.should match response_regex
|
883
|
+
end
|
884
|
+
|
885
|
+
it 'fires given block on response envelope and retry' do
|
886
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
887
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
888
|
+
until @after_callback do end
|
889
|
+
@msg_output.seek(0)
|
890
|
+
@msg_output.read.should match response_regex
|
891
|
+
end
|
892
|
+
end
|
893
|
+
end
|
894
|
+
|
895
|
+
context 'via https' do
|
896
|
+
before do
|
897
|
+
@pn.ssl = true
|
898
|
+
end
|
899
|
+
context 'and it\'s asynchronous' do
|
900
|
+
before(:each) do
|
901
|
+
@http_sync = false
|
902
|
+
end
|
903
|
+
it 'fires given callback on response envelope and retry' do
|
904
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
905
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
906
|
+
until @after_callback do end
|
907
|
+
@msg_output.seek(0)
|
908
|
+
@msg_output.read.should match response_regex
|
909
|
+
end
|
910
|
+
|
911
|
+
it 'fires given block on response envelope and retry' do
|
912
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
913
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
914
|
+
until @after_callback do end
|
915
|
+
@msg_output.seek(0)
|
916
|
+
@msg_output.read.should match response_regex
|
917
|
+
end
|
918
|
+
end
|
919
|
+
|
920
|
+
context 'and it\'s synchronous' do
|
921
|
+
before(:each) do
|
922
|
+
@http_sync = true
|
923
|
+
end
|
924
|
+
it 'fires given callback on response envelope and retry' do
|
925
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
926
|
+
@pn.subscribe(:channel => 'demo', :callback => @callback, :http_sync => @http_sync)
|
927
|
+
until @after_callback do end
|
928
|
+
@msg_output.seek(0)
|
929
|
+
@msg_output.read.should match response_regex
|
930
|
+
end
|
931
|
+
|
932
|
+
it 'fires given block on response envelope and retry' do
|
933
|
+
response_regex = /text\W*hey\W*text\W*hey/
|
934
|
+
@pn.subscribe(:channel => 'demo', :http_sync => @http_sync, &@callback)
|
935
|
+
until @after_callback do end
|
936
|
+
@msg_output.seek(0)
|
937
|
+
@msg_output.read.should match response_regex
|
938
|
+
end
|
939
|
+
end
|
940
|
+
end
|
941
|
+
end
|
942
|
+
end
|
943
|
+
end
|
944
|
+
end
|