pubnub-ruby 3.3.0.7 → 3.4

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