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.

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
@@ -0,0 +1,24 @@
1
+ module Pubnub
2
+ class Subscription
3
+ attr_accessor :channel, :callback
4
+
5
+ def initialize(options)
6
+ @channel = options[:channel]
7
+ @callback = options[:callback]
8
+ end
9
+
10
+ def fire_callback_for(envelope)
11
+ $log.debug "CALLING SUBSCRIPTION CALLBACK FOR CHANNEL #{@channel}" if envelope.channel == @channel
12
+ @callback.call envelope if envelope.channel == @channel
13
+ $log.debug "AFTER CALLING SUBSCRIPTION CALLBACK FOR CHANNEL #{@channel}"
14
+ end
15
+
16
+ def ==(other)
17
+ (@channel == other.get_channel && @callback == other.callback && @error_callback == other.error_callback)
18
+ end
19
+
20
+ def get_channel
21
+ @channel
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,39 @@
1
+ require 'pubnub'
2
+
3
+ namespace :examples do
4
+
5
+ desc "PubNub Subscribe (Receive Messages)"
6
+ task :subscribe, :channel do |task, args|
7
+
8
+ pn = Pubnub.new(:publish_key => "demo", :subscribe_key => "demo")
9
+
10
+ # if my_callback returns false, return immediately, otherwise, keep going...
11
+ my_callback = lambda{ |message| puts(message.inspect); return false; }
12
+
13
+
14
+ pn.subscribe(:channel => args.channel, :callback => my_callback)
15
+ end
16
+
17
+ task :re_subscribe, :channel do |task, args|
18
+
19
+ pn = Pubnub.new(:publish_key => "demo", :subscribe_key => "demo")
20
+
21
+ time_callback = lambda{ |timetoken| @timetoken = timetoken }
22
+ my_callback = lambda{ |message| puts(message.inspect); }
23
+
24
+ pn.time(:callback => time_callback)
25
+ pn.subscribe(:channel => args.channel, :callback => my_callback, :override_timetoken => @timetoken)
26
+ end
27
+
28
+ desc "Realtime see who channel events, such as joins, leaves, and occupancy"
29
+ task :presence, :channel do |task, args|
30
+
31
+ pn = Pubnub.new(:publish_key => "demo", :subscribe_key => "demo")
32
+
33
+ # if my_callback returns false, return immediately, otherwise, keep going...
34
+ my_callback = lambda{ |message| puts(message.inspect); return false; }
35
+
36
+ pn.presence(:channel => args.channel, :callback => my_callback)
37
+ end
38
+
39
+ end
@@ -0,0 +1 @@
1
+ PUBNUB_VERSION = '3.4'
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'pubnub'
5
+ s.version = '3.4'
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
8
+ s.authors = ['PubNub']
9
+ s.date = '2013-10-19'
10
+ s.description = 'Ruby anywhere in the world in 250ms with PubNub!'
11
+ s.email = 'support@pubnub.com'
12
+ s.files = `git ls-files`.split("\n")
13
+ s.homepage = 'http://github.com/pubnub/ruby'
14
+ s.licenses = ['MIT']
15
+ s.require_paths = ['lib']
16
+ s.rubygems_version = '1.7.2'
17
+ s.summary = 'PubNub Official Ruby gem'
18
+
19
+ s.add_dependency 'eventmachine'
20
+ s.add_dependency 'httparty'
21
+ s.add_dependency 'persistent_httparty'
22
+ s.add_dependency 'em-http-request'
23
+ s.add_dependency 'uuid', '~> 2.3.5'
24
+ s.add_dependency 'json'
25
+
26
+ end
@@ -0,0 +1,346 @@
1
+ require 'spec_helper'
2
+ require 'rr'
3
+ require 'vcr'
4
+
5
+ describe Pubnub::Client do
6
+
7
+ describe '#uuid' do
8
+ it 'should return a UUID' do
9
+ end
10
+ end
11
+
12
+ describe '.initialize' do
13
+
14
+ before do
15
+ @publish_key = 'demo_pub_key'
16
+ @subscribe_key = 'demo_sub_key'
17
+ @secret_key = 'demo_md5_key'
18
+ @cipher_key = 'demo_cipher_key'
19
+ @ssl = false
20
+ @channel = 'pn_test'
21
+ end
22
+
23
+ shared_examples_for 'successful initialization' do
24
+
25
+ it 'should initialize' do
26
+ @pn.publish_key.should == @publish_key
27
+ @pn.subscribe_key.should == @subscribe_key
28
+ @pn.secret_key.should == @secret_key
29
+ @pn.cipher_key.should == @cipher_key
30
+ @pn.ssl.should == @ssl_enabled
31
+ end
32
+ end
33
+
34
+ context 'when initialized' do
35
+ it 'should set a sessionUUID' do
36
+ Pubnub.new(:subscribe_key => :demo).session_uuid.should_not == nil
37
+ end
38
+ end
39
+
40
+ context 'when named' do
41
+ context 'and there are more than one arguments' do
42
+ it 'should throw an error' do
43
+ lambda { Pubnub::Client.new('arg1', 'arg2', 'arg3') }.should raise_error
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'when passed with optional parameters in a hash' do
49
+ context 'when the hash key is a symbol' do
50
+ before do
51
+ @pn = Pubnub::Client.new(:publish_key => @publish_key,
52
+ :subscribe_key => @subscribe_key,
53
+ :secret_key => @secret_key,
54
+ :cipher_key => @cipher_key,
55
+ :ssl => @ssl_enabled)
56
+ end
57
+ it_behaves_like 'successful initialization'
58
+ end
59
+ end
60
+
61
+ describe '.verify_config' do
62
+ context 'subscribe_key' do
63
+ it 'should not throw an exception if present' do
64
+ lambda { pn = Pubnub::Client.new(:subscribe_key => 'demo') }.should_not raise_error
65
+ end
66
+
67
+ it 'should not throw an exception if present' do
68
+ lambda { pn = Pubnub::Client.new(:subscribe_key => :bar) }.should_not raise_error
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ describe 'public methods' do
75
+ describe '.time' do
76
+ before do
77
+
78
+ @my_callback = lambda { |message| Rails.logger.debug(message) }
79
+ @my_pub_key = 'demo'
80
+ @my_sub_key = 'demo'
81
+ @my_message = 'hello_world!'
82
+ @my_channel = 'hello_world'
83
+
84
+ @my_cipher_key = 'my_cipher_key'
85
+ @my_sec_key = 'my_sec_key'
86
+ @alt_sec_key = 'alt_sec_key'
87
+ end
88
+
89
+ context 'required parameters' do
90
+
91
+ before do
92
+ @pn = Pubnub.new(:subscribe_key => @my_sub_key)
93
+ end
94
+
95
+ it 'should raise when callback or block is missing' do
96
+ lambda { @pn.time }.
97
+ should raise_error(ArgumentError, 'time() require, if async, callback parameter or block given.')
98
+ end
99
+
100
+ it 'should raise when callback is invalid' do
101
+ lambda { @pn.time(:callback => :blah) }.
102
+ should raise_error('callback is invalid.')
103
+ end
104
+
105
+ end
106
+ end
107
+
108
+ describe '.publish' do
109
+ before do
110
+
111
+ @my_callback = lambda { |message| Rails.logger.debug(message) }
112
+ @my_pub_key = 'demo'
113
+ @my_sub_key = 'demo'
114
+ @my_message = 'hello_world!'
115
+ @my_channel = 'hello_world'
116
+
117
+ @my_cipher_key = 'my_cipher_key'
118
+ @my_sec_key = 'my_sec_key'
119
+ @alt_sec_key = 'alt_sec_key'
120
+ end
121
+
122
+ context 'required parameters' do
123
+
124
+ before do
125
+ @pn = Pubnub.new(:subscribe_key => @my_sub_key)
126
+ end
127
+
128
+ it 'should raise when channel is missing' do
129
+ lambda { @pn.publish(:callback => @my_callback, :message => @my_message) }.
130
+ should raise_error(ArgumentError, 'publish() requires :channel, :message parameters and, if async, callback parameter or block given.')
131
+ end
132
+
133
+ it 'should raise when callback is missing' do
134
+ lambda { @pn.publish(:message => @my_message, :channel => @my_channel) }.
135
+ should raise_error(ArgumentError, 'publish() requires :channel, :message parameters and, if async, callback parameter or block given.')
136
+ end
137
+
138
+ it 'should raise when message is missing' do
139
+ lambda { @pn.publish(:channel => @my_channel, :callback => @my_callback) }.
140
+ should raise_error(ArgumentError, 'publish() requires :channel, :message parameters and, if async, callback parameter or block given.')
141
+ end
142
+
143
+ it 'should raise when callback is invalid' do
144
+ lambda { @pn.presence(:channel => @my_channel, :callback => :blah) }.
145
+ should raise_error('callback is invalid.')
146
+ end
147
+
148
+ end
149
+ end
150
+
151
+ describe '.subscribe' do
152
+ before do
153
+
154
+ @my_callback = lambda { |message| Rails.logger.debug(message) }
155
+ @my_pub_key = 'demo'
156
+ @my_sub_key = 'demo'
157
+ @my_message = 'hello_world!'
158
+ @my_channel = 'hello_world'
159
+
160
+ @my_cipher_key = 'my_cipher_key'
161
+ @my_sec_key = 'my_sec_key'
162
+ @alt_sec_key = 'alt_sec_key'
163
+ end
164
+
165
+ context 'required parameters' do
166
+
167
+ before do
168
+ @pn = Pubnub.new(:subscribe_key => @my_sub_key)
169
+ end
170
+
171
+ it 'should raise when channel is missing' do
172
+ lambda { @pn.subscribe(:foo => :bar, :callback => @my_callback) }.
173
+ should raise_error(ArgumentError, 'subscribe() requires :channel parameters and, if async, callback parameter or block given.')
174
+ end
175
+
176
+ it 'should raise when callback is missing' do
177
+ lambda { @pn.subscribe(:channel => @my_channel) }.
178
+ should raise_error(ArgumentError, 'subscribe() requires :channel parameters and, if async, callback parameter or block given.')
179
+ end
180
+
181
+ it 'should raise when callback is invalid' do
182
+ lambda { @pn.subscribe(:channel => @my_channel, :callback => :blah) }.
183
+ should raise_error('callback is invalid.')
184
+ end
185
+
186
+ end
187
+ end
188
+
189
+ describe '.here_now' do
190
+ before do
191
+
192
+ @my_callback = lambda { |message| Rails.logger.debug(message) }
193
+ @my_pub_key = 'demo'
194
+ @my_sub_key = 'demo'
195
+ @my_message = 'hello_world!'
196
+ @my_channel = 'hello_world'
197
+
198
+ @my_cipher_key = 'my_cipher_key'
199
+ @my_sec_key = 'my_sec_key'
200
+ @alt_sec_key = 'alt_sec_key'
201
+ end
202
+
203
+ context 'required parameters' do
204
+
205
+ before do
206
+ @pn = Pubnub.new(:subscribe_key => @my_sub_key)
207
+ end
208
+
209
+ it 'should raise when channel is missing' do
210
+ lambda { @pn.here_now(:foo => :bar) }.
211
+ should raise_error(ArgumentError, 'here_now() requires :channel parameters and, if async, callback parameter or block given.')
212
+ end
213
+
214
+ it 'should raise when callback is missing' do
215
+ lambda { @pn.here_now(:channel => @my_channel) }.
216
+ should raise_error(ArgumentError, 'here_now() requires :channel parameters and, if async, callback parameter or block given.')
217
+ end
218
+
219
+ it 'should raise when callback is invalid' do
220
+ lambda { @pn.here_now(:channel => @my_channel, :callback => :blah) }.
221
+ should raise_error('callback is invalid.')
222
+ end
223
+
224
+ end
225
+ end
226
+
227
+ describe '.presence' do
228
+ before do
229
+
230
+ @my_callback = lambda { |message| Rails.logger.debug(message) }
231
+ @my_pub_key = 'demo'
232
+ @my_sub_key = 'demo'
233
+ @my_message = 'hello_world!'
234
+ @my_channel = 'hello_world'
235
+
236
+ @my_cipher_key = 'my_cipher_key'
237
+ @my_sec_key = 'my_sec_key'
238
+ @alt_sec_key = 'alt_sec_key'
239
+ end
240
+
241
+ context 'required parameters' do
242
+
243
+ before do
244
+ @pn = Pubnub.new(:subscribe_key => @my_sub_key)
245
+ end
246
+
247
+ it 'should raise when channel is missing' do
248
+ lambda { @pn.presence(:foo => :bar) }.
249
+ should raise_error(ArgumentError, 'presence() requires :channel parameters and, if async, callback parameter or block given.')
250
+ end
251
+
252
+ it 'should raise when callback is missing' do
253
+ lambda { @pn.presence(:channel => @my_channel) }.
254
+ should raise_error(ArgumentError, 'presence() requires :channel parameters and, if async, callback parameter or block given.')
255
+ end
256
+
257
+ it 'should raise when callback is invalid' do
258
+ lambda { @pn.presence(:channel => @my_channel, :callback => :blah) }.
259
+ should raise_error('callback is invalid.')
260
+ end
261
+
262
+ end
263
+ end
264
+
265
+ describe '.hisotry' do
266
+ before do
267
+
268
+ @my_callback = lambda { |message| Rails.logger.debug(message) }
269
+ @my_pub_key = 'demo'
270
+ @my_sub_key = 'demo'
271
+ @my_message = 'hello_world!'
272
+ @my_channel = 'hello_world'
273
+
274
+ @my_cipher_key = 'my_cipher_key'
275
+ @my_sec_key = 'my_sec_key'
276
+ @alt_sec_key = 'alt_sec_key'
277
+ end
278
+
279
+ context 'required parameters' do
280
+
281
+ before do
282
+ @pn = Pubnub.new(:subscribe_key => @my_sub_key)
283
+ end
284
+
285
+ it 'should raise when channel is missing' do
286
+ lambda { @pn.history(:count => 10, :callback => @my_callback) }.
287
+ should raise_error(ArgumentError, 'history() requires :channel, :count parameters and, if async, callback parameter or block given.')
288
+ end
289
+
290
+ it 'should raise when callback is missing' do
291
+ lambda { @pn.history(:channel => @my_channel, :count => 10) }.
292
+ should raise_error(ArgumentError, 'history() requires :channel, :count parameters and, if async, callback parameter or block given.')
293
+ end
294
+
295
+ it 'should raise when count is missing' do
296
+ lambda { @pn.history(:channel => @my_channel, :callback => @my_callback) }.
297
+ should raise_error(ArgumentError, 'history() requires :channel, :count parameters and, if async, callback parameter or block given.')
298
+ end
299
+
300
+ it 'should raise when callback is invalid' do
301
+ lambda { @pn.history(:channel => @my_channel, :count => 10, :callback => :blah) }.
302
+ should raise_error('callback is invalid.')
303
+ end
304
+
305
+ end
306
+ end
307
+
308
+ describe '.leave' do
309
+ before do
310
+
311
+ @my_callback = lambda { |message| Rails.logger.debug(message) }
312
+ @my_pub_key = 'demo'
313
+ @my_sub_key = 'demo'
314
+ @my_message = 'hello_world!'
315
+ @my_channel = 'hello_world'
316
+
317
+ @my_cipher_key = 'my_cipher_key'
318
+ @my_sec_key = 'my_sec_key'
319
+ @alt_sec_key = 'alt_sec_key'
320
+ end
321
+
322
+ context 'required parameters' do
323
+
324
+ before do
325
+ @pn = Pubnub.new(:subscribe_key => @my_sub_key)
326
+ end
327
+
328
+ it 'should raise when channel is missing' do
329
+ lambda { @pn.leave(:callback => @my_callback) }.
330
+ should raise_error(ArgumentError, 'leave() requires :channel parameters and, if async, callback parameter or block given.')
331
+ end
332
+
333
+ it 'should raise when callback is missing' do
334
+ lambda { @pn.leave(:channel => @my_channel) }.
335
+ should raise_error(ArgumentError, 'leave() requires :channel parameters and, if async, callback parameter or block given.')
336
+ end
337
+
338
+ it 'should raise when callback is invalid' do
339
+ lambda { @pn.leave(:channel => @my_channel, :callback => :blah) }.
340
+ should raise_error('callback is invalid.')
341
+ end
342
+
343
+ end
344
+ end
345
+ end
346
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+ require 'rr'
3
+ require 'vcr'
4
+
5
+ describe Pubnub::Crypto do
6
+
7
+ before do
8
+ @cipher_key = "enigma"
9
+
10
+ @plain_string = %^Pubnub Messaging API 1^
11
+ @cipher_string = "f42pIQcWZ9zbTbH8cyLwByD/GsviOE0vcREIEVPARR0="
12
+
13
+ @plain_hash = {"foo" => {"bar" => "foobar"}}
14
+ @encrypted_hash = "GsvkCYZoYylL5a7/DKhysDjNbwn+BtBtHj2CvzC4Y4g="
15
+
16
+ @cipher_empty_hash = "IDjZE9BHSjcX67RddfCYYg=="
17
+
18
+ @cipher_object = %^yLUdgdHs2Fsd5MUYXO7cJH2ciXPC8S3zVrmQHV00sxU=^
19
+
20
+ @cipher_empty_object = "IDjZE9BHSjcX67RddfCYYg=="
21
+
22
+ @cipher_empty_array = "Ns4TB41JjT2NCXaGLWSPAQ=="
23
+ @cipher_array = "bz1jaOW3wT/MBPMN8SI0GvWPKT2PUfj2TD/Rg746jSc="
24
+
25
+ end
26
+
27
+ describe "#when there is a message encrypted on PHP AES256" do
28
+
29
+ context "pubnub standard tests" do
30
+ it "should encrypt" do
31
+ crypto = Pubnub::Crypto.new(@cipher_key)
32
+ crypto.encrypt(@plain_string).should == @cipher_string
33
+ end
34
+
35
+ it "should decrypt" do
36
+ crypto = Pubnub::Crypto.new(@cipher_key)
37
+ crypto.decrypt(@cipher_string).should == @plain_string
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ describe "encrypt array" do
44
+ it "should not blow up on an empty array" do
45
+ Pubnub::Crypto.new(@cipher_key).encrypt([]).should == @cipher_empty_array
46
+ end
47
+
48
+ it "should encrypt an array with a single message" do
49
+ Pubnub::Crypto.new(@cipher_key).encrypt([@plain_string]).should == @cipher_array
50
+ end
51
+
52
+ end
53
+
54
+ describe "decrypt array" do
55
+ it "should not blow up on an empty array" do
56
+ Pubnub::Crypto.new(@cipher_key).decrypt(@cipher_empty_array).should == []
57
+ end
58
+
59
+ it "should decrypt an array with a single message" do
60
+ Pubnub::Crypto.new(@cipher_key).decrypt(@cipher_array).should == [@plain_string]
61
+ end
62
+
63
+ end
64
+
65
+
66
+ describe "encrypt Hash" do
67
+ it "should not blow up on an empty hash" do
68
+ Pubnub::Crypto.new(@cipher_key).encrypt({}).should == @cipher_empty_hash
69
+ end
70
+
71
+ it "should encrypt a hash with a single message" do
72
+ Pubnub::Crypto.new(@cipher_key).encrypt(@plain_hash).should == @encrypted_hash
73
+ end
74
+ end
75
+
76
+ describe "decrypt Hash" do
77
+ it "should not blow up on an empty hash" do
78
+ Pubnub::Crypto.new(@cipher_key).decrypt(@cipher_empty_hash).should == {}
79
+ end
80
+
81
+ it "should decrypt an hash with a single message" do
82
+ Pubnub::Crypto.new(@cipher_key).decrypt(@encrypted_hash).should == @plain_hash
83
+ end
84
+ end
85
+
86
+
87
+ end
88
+
89
+