pubnub 3.5.1 → 3.5.3

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 (127) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +6 -0
  3. data/README.md +11 -0
  4. data/VERSION +1 -1
  5. data/examples/demo_console.rb +0 -1
  6. data/fixtures/vcr_cassettes/auth_key_flow_auth_publish.yml +45 -0
  7. data/fixtures/vcr_cassettes/auth_key_flow_empty_auth_audit.yml +44 -0
  8. data/fixtures/vcr_cassettes/auth_key_flow_instead_auth_audit.yml +44 -0
  9. data/fixtures/vcr_cassettes/auth_key_flow_no_auth_publish.yml +45 -0
  10. data/fixtures/vcr_cassettes/auth_key_flow_non_auth_audit.yml +44 -0
  11. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-many-channels-array.yml +2 -2
  12. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-many-channels-hash.yml +2 -2
  13. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-many-channels-integer.yml +2 -2
  14. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-many-channels-mix.yml +2 -2
  15. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-many-channels-multi-mix.yml +2 -2
  16. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-many-channels-string.yml +2 -2
  17. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-one-channel-array.yml +2 -2
  18. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-one-channel-hash.yml +2 -2
  19. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-one-channel-integer.yml +2 -2
  20. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-one-channel-mix.yml +2 -2
  21. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-one-channel-string.yml +2 -2
  22. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-many-channels-array.yml +2 -2
  23. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-many-channels-hash.yml +2 -2
  24. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-many-channels-integer.yml +2 -2
  25. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-many-channels-mix.yml +2 -2
  26. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-many-channels-multi-mix.yml +2 -2
  27. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-many-channels-string.yml +2 -2
  28. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-one-channel-array.yml +2 -2
  29. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-one-channel-hash.yml +2 -2
  30. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-one-channel-integer.yml +2 -2
  31. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-one-channel-mix.yml +2 -2
  32. data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-one-channel-string.yml +2 -2
  33. data/fixtures/vcr_cassettes/heartbeat-non200.yml +519 -0
  34. data/fixtures/vcr_cassettes/heartbeat-test.yml +91 -0
  35. data/fixtures/vcr_cassettes/heartbeated-subscribe.yml +136 -0
  36. data/fixtures/vcr_cassettes/here_now_global-nonssl-block-invalid-200-sync.yml +49 -0
  37. data/fixtures/vcr_cassettes/here_now_global-nonssl-block-invalid-non-200-sync.yml +49 -0
  38. data/fixtures/vcr_cassettes/here_now_global-nonssl-block-valid-200-sync.yml +49 -0
  39. data/fixtures/vcr_cassettes/here_now_global-nonssl-block-valid-non-200-sync.yml +49 -0
  40. data/fixtures/vcr_cassettes/here_now_global-nonssl-parameter-invalid-200-sync.yml +49 -0
  41. data/fixtures/vcr_cassettes/here_now_global-nonssl-parameter-invalid-non-200-sync.yml +49 -0
  42. data/fixtures/vcr_cassettes/here_now_global-nonssl-parameter-valid-200-sync.yml +49 -0
  43. data/fixtures/vcr_cassettes/here_now_global-nonssl-parameter-valid-non-200-sync.yml +49 -0
  44. data/fixtures/vcr_cassettes/here_now_global-ssl-block-invalid-200-sync.yml +49 -0
  45. data/fixtures/vcr_cassettes/here_now_global-ssl-block-invalid-non-200-sync.yml +49 -0
  46. data/fixtures/vcr_cassettes/here_now_global-ssl-block-valid-200-async.yml +49 -0
  47. data/fixtures/vcr_cassettes/here_now_global-ssl-block-valid-200-sync.yml +49 -0
  48. data/fixtures/vcr_cassettes/here_now_global-ssl-block-valid-non-200-sync.yml +49 -0
  49. data/fixtures/vcr_cassettes/here_now_global-ssl-parameter-invalid-200-sync.yml +49 -0
  50. data/fixtures/vcr_cassettes/here_now_global-ssl-parameter-invalid-non-200-sync.yml +49 -0
  51. data/fixtures/vcr_cassettes/here_now_global-ssl-parameter-valid-200-sync.yml +49 -0
  52. data/fixtures/vcr_cassettes/here_now_global-ssl-parameter-valid-non-200-sync.yml +49 -0
  53. data/fixtures/vcr_cassettes/new_ones/multiplexed_subscribe.yml +854 -0
  54. data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-array-of-hashes.yml +1 -1
  55. data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-http-200-invalid.yml +1 -1
  56. data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-http-200-valid.yml +1 -1
  57. data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-http-non200-invalid.yml +1 -1
  58. data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-http-non200-valid.yml +1 -1
  59. data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-https-200-invalid.yml +1 -1
  60. data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-https-200-valid.yml +1 -1
  61. data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-https-non200-invalid.yml +1 -1
  62. data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-https-non200-valid.yml +1 -1
  63. data/fixtures/vcr_cassettes/new_ones/publish/publish-http-200-invalid.yml +1 -1
  64. data/fixtures/vcr_cassettes/new_ones/publish/publish-http-200-valid.yml +1 -1
  65. data/fixtures/vcr_cassettes/new_ones/publish/publish-http-non200-invalid.yml +1 -1
  66. data/fixtures/vcr_cassettes/new_ones/publish/publish-http-non200-valid.yml +1 -1
  67. data/fixtures/vcr_cassettes/new_ones/publish/publish-https-200-invalid.yml +1 -1
  68. data/fixtures/vcr_cassettes/new_ones/publish/publish-https-200-valid.yml +1 -1
  69. data/fixtures/vcr_cassettes/new_ones/publish/publish-https-non200-invalid.yml +1 -1
  70. data/fixtures/vcr_cassettes/new_ones/publish/publish-https-non200-valid.yml +1 -1
  71. data/fixtures/vcr_cassettes/new_ones/publish/publish-plain-array-of-hashes.yml +1 -1
  72. data/fixtures/vcr_cassettes/non-heartbeated-subscribe.yml +44 -0
  73. data/fixtures/vcr_cassettes/pam20.yml +1 -1
  74. data/fixtures/vcr_cassettes/single-event-invalid-json.yml +15 -138
  75. data/fixtures/vcr_cassettes/v3-presence-nonssl-block-invalid-200-async.yml +86 -0
  76. data/fixtures/vcr_cassettes/v3-presence-nonssl-block-invalid-200-sync.yml +86 -0
  77. data/fixtures/vcr_cassettes/v3-presence-nonssl-block-invalid-non-200-async.yml +86 -0
  78. data/fixtures/vcr_cassettes/v3-presence-nonssl-block-invalid-non-200-sync.yml +86 -0
  79. data/fixtures/vcr_cassettes/v3-presence-nonssl-block-valid-200-async.yml +86 -0
  80. data/fixtures/vcr_cassettes/v3-presence-nonssl-block-valid-200-sync.yml +86 -0
  81. data/fixtures/vcr_cassettes/v3-presence-nonssl-block-valid-non-200-async.yml +86 -0
  82. data/fixtures/vcr_cassettes/v3-presence-nonssl-block-valid-non-200-sync.yml +86 -0
  83. data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-invalid-200-async.yml +86 -0
  84. data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-invalid-200-sync.yml +86 -0
  85. data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-invalid-non-200-async.yml +86 -0
  86. data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-invalid-non-200-sync.yml +86 -0
  87. data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-valid-200-async.yml +86 -0
  88. data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-valid-200-sync.yml +86 -0
  89. data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-valid-non-200-async.yml +86 -0
  90. data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-valid-non-200-sync.yml +86 -0
  91. data/fixtures/vcr_cassettes/v3-presence-ssl-block-invalid-200-async.yml +86 -0
  92. data/fixtures/vcr_cassettes/v3-presence-ssl-block-invalid-200-sync.yml +86 -0
  93. data/fixtures/vcr_cassettes/v3-presence-ssl-block-invalid-non-200-async.yml +86 -0
  94. data/fixtures/vcr_cassettes/v3-presence-ssl-block-invalid-non-200-sync.yml +86 -0
  95. data/fixtures/vcr_cassettes/v3-presence-ssl-block-valid-200-async.yml +86 -0
  96. data/fixtures/vcr_cassettes/v3-presence-ssl-block-valid-200-sync.yml +86 -0
  97. data/fixtures/vcr_cassettes/v3-presence-ssl-block-valid-non-200-async.yml +86 -0
  98. data/fixtures/vcr_cassettes/v3-presence-ssl-block-valid-non-200-sync.yml +86 -0
  99. data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-invalid-200-async.yml +86 -0
  100. data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-invalid-200-sync.yml +86 -0
  101. data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-invalid-non-200-async.yml +86 -0
  102. data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-invalid-non-200-sync.yml +86 -0
  103. data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-valid-200-async.yml +86 -0
  104. data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-valid-200-sync.yml +86 -0
  105. data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-valid-non-200-async.yml +86 -0
  106. data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-valid-non-200-sync.yml +86 -0
  107. data/lib/pubnub/client.rb +57 -31
  108. data/lib/pubnub/crypto.rb +6 -6
  109. data/lib/pubnub/event.rb +64 -45
  110. data/lib/pubnub/events/heartbeat.rb +59 -0
  111. data/lib/pubnub/events/here_now.rb +19 -10
  112. data/lib/pubnub/events/leave.rb +17 -9
  113. data/lib/pubnub/exceptions.rb +1 -1
  114. data/lib/pubnub/formatter.rb +1 -0
  115. data/lib/pubnub/pam.rb +5 -0
  116. data/lib/version.rb +1 -1
  117. data/pubnub.gemspec +2 -2
  118. data/spec/lib/auth_key_flow_spec.rb +60 -0
  119. data/spec/lib/heartbeat_spec.rb +110 -0
  120. data/spec/lib/integration/global_here_now_spec.rb +541 -0
  121. data/spec/lib/integration/multiplexed_subscribe_flow_spec.rb +44 -0
  122. data/spec/lib/integration/publish_spec.rb +1699 -373
  123. data/spec/lib/integration/publish_spec_old.rb +541 -0
  124. data/spec/lib/integration/v3_presence_spec.rb +557 -0
  125. metadata +68 -4
  126. data/examples/demo_console.rb~ +0 -307
  127. data/spec/lib/new_integration/publish_spec.rb +0 -1867
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'multiplexed subscribe flow' do
4
+ it 'works as decribed' do
5
+ VCR.use_cassette('new_ones/multiplexed_subscribe', :record => :new_episodes) do
6
+ @pn = Pubnub.new(:subscribe_key => :demo, :publish_key => :demo, :uuid => 'rubytest', :origin => 'pubsub.pubnub.com')
7
+
8
+ @pn.subscribe(:channel => 'rubya'){ |e| puts e.channel; puts e.msg }
9
+ # 1 subs on 1 connection
10
+ eventually do
11
+ @pn.env[:subscriptions].size.should eq 1
12
+ @pn.env[:subscriptions]['pubsub.pubnub.com'].get_channels.size.should eq 1
13
+ end
14
+
15
+ @pn.subscribe(:channel => 'rubya-pnpres'){ |e| puts e.channel; puts e.msg }
16
+ # 2 subs on 1 connection
17
+ eventually do
18
+ @pn.env[:subscriptions].size.should eq 1
19
+ @pn.env[:subscriptions]['pubsub.pubnub.com'].get_channels.size.should eq 2
20
+ end
21
+
22
+ @pn.subscribe(:channel => 'rubyb'){ |e| puts e.channel; puts e.msg }
23
+ # 3 subs on 1 connection
24
+ eventually do
25
+ @pn.env[:subscriptions].size.should eq 1
26
+ @pn.env[:subscriptions]['pubsub.pubnub.com'].get_channels.size.should eq 3
27
+ end
28
+
29
+ @pn.leave(:channel => 'rubyb'){ |e| puts e.channel; puts e.msg }
30
+ # 2 subs on 1 connection
31
+ eventually do
32
+ @pn.env[:subscriptions].size.should eq 1
33
+ @pn.env[:subscriptions]['pubsub.pubnub.com'].get_channels.size.should eq 2
34
+ end
35
+
36
+ @pn.leave(:channel => 'rubya,rubya-pnpres'){ |e| puts e.channel; puts e.msg }
37
+ # 0 subs on 0 connections
38
+
39
+ eventually do
40
+ @pn.env[:subscriptions].size.should eq 0
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,154 +1,455 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "#publish" do
3
+ describe '#publish' do
4
4
  before(:each) do
5
+ @envelopes = Array.new
6
+ @error_envelopes = Array.new
5
7
 
6
- EM.stop if EM.reactor_running?
7
- while EM.reactor_running? do end
8
- sleep(0.1)
8
+ @callback = lambda do |envelope|
9
+ @envelopes << envelope
10
+ end
9
11
 
10
- @response_output = StringIO.new
11
- @message_output = StringIO.new
12
+ @error_callback = lambda do |envelope|
13
+ @error_envelopes << envelope
14
+ end
15
+ end
12
16
 
13
- @callback = lambda { |envelope|
14
- $logger.debug 'FIRING CALLBACK FROM TEST'
15
- @response_output.write envelope.response
16
- @message_output.write envelope.msg
17
- @after_callback = true
18
- }
17
+ context 'uses http' do
18
+ context 'with auth_key provided' do
19
+ context 'without encrypting message' do
19
20
 
20
- @error_callback = lambda { |envelope|
21
- $logger.debug 'FIRING ERROR CALLBACK FROM TEST'
22
- @response_output.write envelope.response
23
- @message_output.write envelope.msg
24
- @after_error_callback = true
25
- }
21
+ before(:each) do
22
+ @pubnub = Pubnub.new(
23
+ :max_retries => 0,
24
+ :subscribe_key => :demo,
25
+ :publish_key => :demo,
26
+ :auth_key => :demoish_authkey,
27
+ :secret_key => 'some_secret_key',
28
+ :error_callback => @error_callback
29
+ )
26
30
 
27
- @pn = Pubnub.new(:max_retries => 0, :subscribe_key => :demo, :publish_key => :demo, :auth_key => :demoish_authkey, :secret_key => 'some_secret_key', :error_callback => @error_callback)
28
- @pn.uuid = 'rubytests'
31
+ @pubnub.uuid = 'tester'
32
+ end
29
33
 
30
- end
31
- context "uses ssl" do
32
- before(:each) { @ssl = true }
33
- context "passess callback as block" do
34
- context "gets valid json in response" do
35
- context "gets status 200 in response" do
36
- context "uses sync connection" do
37
- it 'works fine' do
38
- VCR.use_cassette("publish-ssl-block-valid-200-sync", :record => :none) do
39
- @pn.publish(:ssl => true, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, &@callback)
40
-
41
- @after_callback.should eq true
42
- @response_output.seek 0
43
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
44
- @message_output.seek 0
45
- @message_output.read.should eq "{:text=>\"hey\"}"
34
+ context 'gets status 200 response' do
35
+ context 'with valid json' do
36
+ context 'its asynchronous' do
37
+ it 'publishes valid message' do
38
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-200-valid', :record => :none) do
39
+
40
+ @pubnub.publish(
41
+ :message => {:text => 'sometext'},
42
+ :channel => 'ruby_demo_channel',
43
+ :callback => @callback
44
+ )
45
+
46
+ eventually do
47
+ @envelopes.size.should eq 1
48
+ @envelopes.first.response_message.should eq 'Sent'
49
+ @envelopes.first.status.should eq 200
50
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
51
+ @envelopes.first.message.should eq({:text => 'sometext'})
52
+ @envelopes.first.timetoken.blank?.should eq false
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+
59
+ context 'its synchronous' do
60
+ it 'publishes valid message' do
61
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-200-valid', :record => :none) do
62
+
63
+ @pubnub.publish(
64
+ :message => {:text => 'sometext'},
65
+ :channel => 'ruby_demo_channel',
66
+ :callback => @callback,
67
+ :http_sync => true
68
+ )
69
+
70
+ @envelopes.size.should eq 1
71
+ @envelopes.first.response_message.should eq 'Sent'
72
+ @envelopes.first.status.should eq 200
73
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
74
+ @envelopes.first.message.should eq({:text => 'sometext'})
75
+ @envelopes.first.timetoken.blank?.should eq false
76
+
77
+ end
46
78
  end
47
79
  end
48
80
  end
49
- context "uses async connection" do
50
- it 'works fine' do
51
- VCR.use_cassette("publish-ssl-block-valid-200-async", :record => :none) do
52
- @pn.publish(:ssl => true, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, &@callback)
53
81
 
54
- eventually do
55
- @after_callback.should eq true
56
- @response_output.seek 0
57
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
58
- @message_output.seek 0
59
- @message_output.read.should eq "{:text=>\"hey\"}"
82
+ context 'with invalid json' do
83
+ context 'its asynchronous' do
84
+ it 'handles invalid json gracefully' do
85
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-200-invalid', :record => :none) do
86
+
87
+ @pubnub.publish(
88
+ :message => {:text => 'sometext'},
89
+ :channel => 'ruby_demo_channel',
90
+ :callback => @callback
91
+ )
92
+
93
+ eventually do
94
+ @envelopes.size.should eq 0
95
+ @error_envelopes.size.should eq 1
96
+ @error_envelopes.first.response_message.should eq nil
97
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
98
+ @error_envelopes.first.status.should eq 200
99
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
100
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
101
+ @error_envelopes.first.timetoken.blank?.should eq true
102
+ end
103
+
104
+ end
105
+ end
106
+ end
107
+
108
+ context 'its synchronous' do
109
+ it 'handles invalid json gracefully' do
110
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-200-invalid', :record => :none) do
111
+
112
+ @pubnub.publish(
113
+ :message => {:text => 'sometext'},
114
+ :channel => 'ruby_demo_channel',
115
+ :callback => @callback,
116
+ :http_sync => true
117
+ )
118
+
119
+ @envelopes.size.should eq 0
120
+ @error_envelopes.size.should eq 1
121
+ @error_envelopes.first.response_message.should eq nil
122
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
123
+ @error_envelopes.first.status.should eq 200
124
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
125
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
126
+ @error_envelopes.first.timetoken.blank?.should eq true
127
+
60
128
  end
61
129
  end
62
130
  end
63
131
  end
64
132
  end
65
- context "gets status non-200 in response" do
66
- context "uses sync connection" do
67
- it 'works fine' do
68
- VCR.use_cassette("publish-ssl-block-valid-non-200-sync", :record => :none) do
69
- @pn.publish(:ssl => true, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, &@callback)
70
-
71
- @after_error_callback.should eq true
72
- @response_output.seek 0
73
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
74
- @message_output.seek 0
75
- @message_output.read.should eq '[0,"Non 2xx server response."]'
133
+
134
+ context 'gets status non200 response' do
135
+ context 'with valid json' do
136
+ context 'its asynchronous' do
137
+ it 'handles non200 response gracefully' do
138
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-non200-valid', :record => :none) do
139
+
140
+ @pubnub.publish(
141
+ :message => {:text => 'sometext'},
142
+ :channel => 'ruby_demo_channel',
143
+ :callback => @callback
144
+ )
145
+
146
+ eventually do
147
+ @envelopes.size.should eq 0
148
+ @error_envelopes.size.should eq 1
149
+ @error_envelopes.first.response_message.should eq 'Sent'
150
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
151
+ @error_envelopes.first.status.should eq 500
152
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
153
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
154
+ @error_envelopes.first.timetoken.blank?.should eq false
155
+ end
156
+
157
+ end
158
+ end
159
+ end
160
+
161
+ context 'its synchronous' do
162
+ it 'handles non200 response gracefully' do
163
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-non200-valid', :record => :none) do
164
+
165
+ @pubnub.publish(
166
+ :message => {:text => 'sometext'},
167
+ :channel => 'ruby_demo_channel',
168
+ :callback => @callback,
169
+ :http_sync => true
170
+ )
171
+
172
+ @envelopes.size.should eq 0
173
+ @error_envelopes.size.should eq 1
174
+ @error_envelopes.first.response_message.should eq 'Sent'
175
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
176
+ @error_envelopes.first.status.should eq 500
177
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
178
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
179
+ @error_envelopes.first.timetoken.blank?.should eq false
180
+
181
+ end
76
182
  end
77
183
  end
78
184
  end
79
- context "uses async connection" do
80
- it 'works fine' do
81
- VCR.use_cassette("publish-ssl-block-valid-non-200-async", :record => :none) do
82
- @pn.publish(:ssl => true, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, &@callback)
83
185
 
84
- eventually do
85
- @after_error_callback.should eq true
86
- @response_output.seek 0
87
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
88
- @message_output.seek 0
89
- @message_output.read.should eq '[0,"Non 2xx server response."]'
186
+ context 'with invalid json' do
187
+ context 'its asynchronous' do
188
+ it 'handles invalid json and non200 response gracefully' do
189
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-non200-invalid', :record => :none) do
190
+
191
+ @pubnub.publish(
192
+ :message => {:text => 'sometext'},
193
+ :channel => 'ruby_demo_channel',
194
+ :callback => @callback
195
+ )
196
+
197
+ eventually do
198
+ @envelopes.size.should eq 0
199
+ @error_envelopes.size.should eq 1
200
+ @error_envelopes.first.response_message.should eq nil
201
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
202
+ @error_envelopes.first.status.should eq 500
203
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
204
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
205
+ @error_envelopes.first.timetoken.blank?.should eq true
206
+ end
207
+
208
+ end
209
+ end
210
+ end
211
+
212
+ context 'its synchronous' do
213
+ it 'handles invalid json and non200 response gracefully' do
214
+ VCR.use_cassette('new_ones/publish/publish-http-auth_key-non200-invalid', :record => :none) do
215
+
216
+ @pubnub.publish(
217
+ :message => {:text => 'sometext'},
218
+ :channel => 'ruby_demo_channel',
219
+ :callback => @callback,
220
+ :http_sync => true
221
+ )
222
+
223
+ @envelopes.size.should eq 0
224
+ @error_envelopes.size.should eq 1
225
+ @error_envelopes.first.response_message.should eq nil
226
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
227
+ @error_envelopes.first.status.should eq 500
228
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
229
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
230
+ @error_envelopes.first.timetoken.blank?.should eq true
231
+
90
232
  end
91
233
  end
92
234
  end
93
235
  end
94
236
  end
95
237
  end
96
- context "gets invalid json in response" do
97
- context "gets status 200 in response" do
98
- context "uses sync connection" do
99
- it 'works fine' do
100
- VCR.use_cassette("publish-ssl-block-invalid-200-sync", :record => :none) do
101
- @pn.publish(:ssl => true, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, &@callback)
102
-
103
- @after_error_callback.should eq true
104
- @response_output.seek 0
105
- @response_output.read.should eq '[1,"Sent","'
106
- @message_output.seek 0
107
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
238
+
239
+ context 'with encrypting message' do
240
+
241
+ before(:each) do
242
+ @pubnub = Pubnub.new(
243
+ :max_retries => 0,
244
+ :subscribe_key => :demo,
245
+ :publish_key => :demo,
246
+ :auth_key => :demoish_authkey,
247
+ :secret_key => 'some_secret_key',
248
+ :cipher_key => 'secret',
249
+ :error_callback => @error_callback
250
+ )
251
+
252
+ @pubnub.uuid = 'tester'
253
+ end
254
+
255
+ context 'gets status 200 response' do
256
+ context 'with valid json' do
257
+ context 'its asynchronous' do
258
+ it 'publishes valid message' do
259
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-200-valid', :record => :none) do
260
+
261
+ @pubnub.publish(
262
+ :message => {:text => 'sometext'},
263
+ :channel => 'ruby_demo_channel',
264
+ :callback => @callback
265
+ )
266
+
267
+ eventually do
268
+ @envelopes.size.should eq 1
269
+ @envelopes.first.response_message.should eq 'Sent'
270
+ @envelopes.first.status.should eq 200
271
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
272
+ @envelopes.first.message.should eq({:text => 'sometext'})
273
+ @envelopes.first.timetoken.blank?.should eq false
274
+ end
275
+
276
+ end
277
+ end
278
+ end
279
+
280
+ context 'its synchronous' do
281
+ it 'publishes valid message' do
282
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-200-valid', :record => :none) do
283
+
284
+ @pubnub.publish(
285
+ :message => {:text => 'sometext'},
286
+ :channel => 'ruby_demo_channel',
287
+ :callback => @callback,
288
+ :http_sync => true
289
+ )
290
+
291
+ @envelopes.size.should eq 1
292
+ @envelopes.first.response_message.should eq 'Sent'
293
+ @envelopes.first.status.should eq 200
294
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
295
+ @envelopes.first.message.should eq({:text => 'sometext'})
296
+ @envelopes.first.timetoken.blank?.should eq false
297
+
298
+ end
108
299
  end
109
300
  end
110
301
  end
111
- context "uses async connection" do
112
- it 'works fine' do
113
- VCR.use_cassette("publish-ssl-block-invalid-200-async", :record => :none) do
114
- @pn.publish(:ssl => true, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, &@callback)
115
302
 
116
- eventually do
117
- @after_error_callback.should eq true
118
- @response_output.seek 0
119
- @response_output.read.should eq '[1,"Sent","'
120
- @message_output.seek 0
121
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
303
+ context 'with invalid json' do
304
+ context 'its asynchronous' do
305
+ it 'handles invalid json gracefully' do
306
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-200-invalid', :record => :none) do
307
+
308
+ @pubnub.publish(
309
+ :message => {:text => 'sometext'},
310
+ :channel => 'ruby_demo_channel',
311
+ :callback => @callback
312
+ )
313
+
314
+ eventually do
315
+ @envelopes.size.should eq 0
316
+ @error_envelopes.size.should eq 1
317
+ @error_envelopes.first.response_message.should eq nil
318
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
319
+ @error_envelopes.first.status.should eq 200
320
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
321
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
322
+ @error_envelopes.first.timetoken.blank?.should eq true
323
+ end
324
+
325
+ end
326
+ end
327
+ end
328
+
329
+ context 'its synchronous' do
330
+ it 'handles invalid json gracefully' do
331
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-200-invalid', :record => :none) do
332
+
333
+ @pubnub.publish(
334
+ :message => {:text => 'sometext'},
335
+ :channel => 'ruby_demo_channel',
336
+ :callback => @callback,
337
+ :http_sync => true
338
+ )
339
+
340
+ @envelopes.size.should eq 0
341
+ @error_envelopes.size.should eq 1
342
+ @error_envelopes.first.response_message.should eq nil
343
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
344
+ @error_envelopes.first.status.should eq 200
345
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
346
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
347
+ @error_envelopes.first.timetoken.blank?.should eq true
348
+
122
349
  end
123
350
  end
124
351
  end
125
352
  end
126
353
  end
127
- context "gets status non-200 in response" do
128
- context "uses sync connection" do
129
- it 'works fine' do
130
- VCR.use_cassette("publish-ssl-block-invalid-non-200-sync", :record => :none) do
131
- @pn.publish(:ssl => true, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, &@callback)
132
-
133
- @after_error_callback.should eq true
134
- @response_output.seek 0
135
- @response_output.read.should eq '[1,"Sent","'
136
- @message_output.seek 0
137
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
354
+
355
+ context 'gets status non200 response' do
356
+ context 'with valid json' do
357
+ context 'its asynchronous' do
358
+ it 'handles non200 response gracefully' do
359
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-non200-valid', :record => :none) do
360
+
361
+ @pubnub.publish(
362
+ :message => {:text => 'sometext'},
363
+ :channel => 'ruby_demo_channel',
364
+ :callback => @callback
365
+ )
366
+
367
+ eventually do
368
+ @envelopes.size.should eq 0
369
+ @error_envelopes.size.should eq 1
370
+ @error_envelopes.first.response_message.should eq 'Sent'
371
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
372
+ @error_envelopes.first.status.should eq 500
373
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
374
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
375
+ @error_envelopes.first.timetoken.blank?.should eq false
376
+ end
377
+
378
+ end
379
+ end
380
+ end
381
+
382
+ context 'its synchronous' do
383
+ it 'handles non200 response gracefully' do
384
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-non200-valid', :record => :none) do
385
+
386
+ @pubnub.publish(
387
+ :message => {:text => 'sometext'},
388
+ :channel => 'ruby_demo_channel',
389
+ :callback => @callback,
390
+ :http_sync => true
391
+ )
392
+
393
+ @envelopes.size.should eq 0
394
+ @error_envelopes.size.should eq 1
395
+ @error_envelopes.first.response_message.should eq 'Sent'
396
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
397
+ @error_envelopes.first.status.should eq 500
398
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
399
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
400
+ @error_envelopes.first.timetoken.blank?.should eq false
401
+
402
+ end
138
403
  end
139
404
  end
140
405
  end
141
- context "uses async connection" do
142
- it 'works fine' do
143
- VCR.use_cassette("publish-ssl-block-invalid-non-200-async", :record => :none) do
144
- @pn.publish(:ssl => true, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, &@callback)
145
406
 
146
- eventually do
147
- @after_error_callback.should eq true
148
- @response_output.seek 0
149
- @response_output.read.should eq '[1,"Sent","'
150
- @message_output.seek 0
151
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
407
+ context 'with invalid json' do
408
+ context 'its asynchronous' do
409
+ it 'handles invalid json and non200 response gracefully' do
410
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-non200-invalid', :record => :none) do
411
+
412
+ @pubnub.publish(
413
+ :message => {:text => 'sometext'},
414
+ :channel => 'ruby_demo_channel',
415
+ :callback => @callback
416
+ )
417
+
418
+ eventually do
419
+ @envelopes.size.should eq 0
420
+ @error_envelopes.size.should eq 1
421
+ @error_envelopes.first.response_message.should eq nil
422
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
423
+ @error_envelopes.first.status.should eq 500
424
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
425
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
426
+ @error_envelopes.first.timetoken.blank?.should eq true
427
+ end
428
+
429
+ end
430
+ end
431
+ end
432
+
433
+ context 'its synchronous' do
434
+ it 'handles invalid json and non200 response gracefully' do
435
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-auth_key-non200-invalid', :record => :none) do
436
+
437
+ @pubnub.publish(
438
+ :message => {:text => 'sometext'},
439
+ :channel => 'ruby_demo_channel',
440
+ :callback => @callback,
441
+ :http_sync => true
442
+ )
443
+
444
+ @envelopes.size.should eq 0
445
+ @error_envelopes.size.should eq 1
446
+ @error_envelopes.first.response_message.should eq nil
447
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
448
+ @error_envelopes.first.status.should eq 500
449
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
450
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
451
+ @error_envelopes.first.timetoken.blank?.should eq true
452
+
152
453
  end
153
454
  end
154
455
  end
@@ -156,125 +457,440 @@ describe "#publish" do
156
457
  end
157
458
  end
158
459
  end
159
- context "passess callback as parameter" do
160
- context "gets valid json in response" do
161
- context "gets status 200 in response" do
162
- context "uses sync connection" do
163
- it 'works fine' do
164
- VCR.use_cassette("publish-ssl-parameter-valid-200-sync", :record => :none) do
165
- @pn.publish(:ssl => true, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
166
-
167
- @after_callback.should eq true
168
- @response_output.seek 0
169
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
170
- @message_output.seek 0
171
- @message_output.read.should eq "{:text=>\"hey\"}"
460
+
461
+ context 'without auth_key provided' do
462
+ context 'without encrypting message' do
463
+
464
+ before(:each) do
465
+ @pubnub = Pubnub.new(
466
+ :max_retries => 0,
467
+ :subscribe_key => :demo,
468
+ :publish_key => :demo,
469
+ :secret_key => 'some_secret_key',
470
+ :error_callback => @error_callback
471
+ )
472
+
473
+ @pubnub.uuid = 'tester'
474
+ end
475
+
476
+ context 'gets status 200 response' do
477
+ context 'with valid json' do
478
+ context 'its asynchronous' do
479
+ it 'publishes valid message' do
480
+ VCR.use_cassette('new_ones/publish/publish-http-200-valid', :record => :none) do
481
+
482
+ @pubnub.publish(
483
+ :message => {:text => 'sometext'},
484
+ :channel => 'ruby_demo_channel',
485
+ :callback => @callback
486
+ )
487
+
488
+ eventually do
489
+ @envelopes.size.should eq 1
490
+ @envelopes.first.response_message.should eq 'Sent'
491
+ @envelopes.first.status.should eq 200
492
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
493
+ @envelopes.first.message.should eq({:text => 'sometext'})
494
+ @envelopes.first.timetoken.blank?.should eq false
495
+ end
496
+
497
+ end
498
+ end
499
+ end
500
+
501
+ context 'its synchronous' do
502
+ it 'publishes valid message' do
503
+ VCR.use_cassette('new_ones/publish/publish-http-200-valid', :record => :none) do
504
+
505
+ @pubnub.publish(
506
+ :message => {:text => 'sometext'},
507
+ :channel => 'ruby_demo_channel',
508
+ :callback => @callback,
509
+ :http_sync => true
510
+ )
511
+
512
+ @envelopes.size.should eq 1
513
+ @envelopes.first.response_message.should eq 'Sent'
514
+ @envelopes.first.status.should eq 200
515
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
516
+ @envelopes.first.message.should eq({:text => 'sometext'})
517
+ @envelopes.first.timetoken.blank?.should eq false
518
+
519
+ end
172
520
  end
173
521
  end
174
522
  end
175
- context "uses async connection" do
176
- it 'works fine' do
177
- VCR.use_cassette("publish-ssl-parameter-valid-200-async", :record => :none) do
178
- @pn.publish(:ssl => true, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
179
523
 
180
- eventually do
181
- @after_callback.should eq true
182
- @response_output.seek 0
183
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
184
- @message_output.seek 0
185
- @message_output.read.should eq "{:text=>\"hey\"}"
524
+ context 'with invalid json' do
525
+ context 'its asynchronous' do
526
+ it 'handles invalid json gracefully' do
527
+ VCR.use_cassette('new_ones/publish/publish-http-200-invalid', :record => :none) do
528
+
529
+ @pubnub.publish(
530
+ :message => {:text => 'sometext'},
531
+ :channel => 'ruby_demo_channel',
532
+ :callback => @callback
533
+ )
534
+
535
+ eventually do
536
+ @envelopes.size.should eq 0
537
+ @error_envelopes.size.should eq 1
538
+ @error_envelopes.first.response_message.should eq nil
539
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
540
+ @error_envelopes.first.status.should eq 200
541
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
542
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
543
+ @error_envelopes.first.timetoken.blank?.should eq true
544
+ end
545
+
546
+ end
547
+ end
548
+ end
549
+
550
+ context 'its synchronous' do
551
+ it 'handles invalid json gracefully' do
552
+ VCR.use_cassette('new_ones/publish/publish-http-200-invalid', :record => :none) do
553
+
554
+ @pubnub.publish(
555
+ :message => {:text => 'sometext'},
556
+ :channel => 'ruby_demo_channel',
557
+ :callback => @callback,
558
+ :http_sync => true
559
+ )
560
+
561
+ @envelopes.size.should eq 0
562
+ @error_envelopes.size.should eq 1
563
+ @error_envelopes.first.response_message.should eq nil
564
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
565
+ @error_envelopes.first.status.should eq 200
566
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
567
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
568
+ @error_envelopes.first.timetoken.blank?.should eq true
569
+
186
570
  end
187
571
  end
188
572
  end
189
573
  end
190
574
  end
191
- context "gets status non-200 in response" do
192
- context "uses sync connection" do
193
- it 'works fine' do
194
- VCR.use_cassette("publish-ssl-parameter-valid-non-200-sync", :record => :none) do
195
- @pn.publish(:ssl => true, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
196
575
 
197
- @after_error_callback.should eq true
198
- @response_output.seek 0
199
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
200
- @message_output.seek 0
201
- @message_output.read.should eq '[0,"Non 2xx server response."]'
576
+ context 'gets status non200 response' do
577
+ context 'with valid json' do
578
+ context 'its asynchronous' do
579
+ it 'handles non200 response gracefully' do
580
+ VCR.use_cassette('new_ones/publish/publish-http-non200-valid', :record => :none) do
581
+
582
+ @pubnub.publish(
583
+ :message => {:text => 'sometext'},
584
+ :channel => 'ruby_demo_channel',
585
+ :callback => @callback
586
+ )
587
+
588
+ eventually do
589
+ @envelopes.size.should eq 0
590
+ @error_envelopes.size.should eq 1
591
+ @error_envelopes.first.response_message.should eq 'Sent'
592
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
593
+ @error_envelopes.first.status.should eq 500
594
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
595
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
596
+ @error_envelopes.first.timetoken.blank?.should eq false
597
+ end
598
+
599
+ end
600
+ end
601
+ end
602
+
603
+ context 'its synchronous' do
604
+ it 'handles non200 response gracefully' do
605
+ VCR.use_cassette('new_ones/publish/publish-http-non200-valid', :record => :none) do
606
+
607
+ @pubnub.publish(
608
+ :message => {:text => 'sometext'},
609
+ :channel => 'ruby_demo_channel',
610
+ :callback => @callback,
611
+ :http_sync => true
612
+ )
613
+
614
+ @envelopes.size.should eq 0
615
+ @error_envelopes.size.should eq 1
616
+ @error_envelopes.first.response_message.should eq 'Sent'
617
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
618
+ @error_envelopes.first.status.should eq 500
619
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
620
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
621
+ @error_envelopes.first.timetoken.blank?.should eq false
622
+
623
+ end
202
624
  end
203
625
  end
204
626
  end
205
- context "uses async connection" do
206
- it 'works fine' do
207
- VCR.use_cassette("publish-ssl-parameter-valid-non-200-async", :record => :none) do
208
- @pn.publish(:ssl => true, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
209
627
 
210
- eventually do
211
- @after_error_callback.should eq true
212
- @response_output.seek 0
213
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
214
- @message_output.seek 0
215
- @message_output.read.should eq '[0,"Non 2xx server response."]'
628
+ context 'with invalid json' do
629
+ context 'its asynchronous' do
630
+ it 'handles invalid json and non200 response gracefully' do
631
+ VCR.use_cassette('new_ones/publish/publish-http-non200-invalid', :record => :none) do
632
+
633
+ @pubnub.publish(
634
+ :message => {:text => 'sometext'},
635
+ :channel => 'ruby_demo_channel',
636
+ :callback => @callback
637
+ )
638
+
639
+ eventually do
640
+ @envelopes.size.should eq 0
641
+ @error_envelopes.size.should eq 1
642
+ @error_envelopes.first.response_message.should eq nil
643
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
644
+ @error_envelopes.first.status.should eq 500
645
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
646
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
647
+ @error_envelopes.first.timetoken.blank?.should eq true
648
+ end
649
+
650
+ end
651
+ end
652
+ end
653
+
654
+ context 'its synchronous' do
655
+ it 'handles invalid json and non200 response gracefully' do
656
+ VCR.use_cassette('new_ones/publish/publish-http-non200-invalid', :record => :none) do
657
+
658
+ @pubnub.publish(
659
+ :message => {:text => 'sometext'},
660
+ :channel => 'ruby_demo_channel',
661
+ :callback => @callback,
662
+ :http_sync => true
663
+ )
664
+
665
+ @envelopes.size.should eq 0
666
+ @error_envelopes.size.should eq 1
667
+ @error_envelopes.first.response_message.should eq nil
668
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
669
+ @error_envelopes.first.status.should eq 500
670
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
671
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
672
+ @error_envelopes.first.timetoken.blank?.should eq true
673
+
216
674
  end
217
675
  end
218
676
  end
219
677
  end
220
678
  end
221
679
  end
222
- context "gets invalid json in response" do
223
- context "gets status 200 in response" do
224
- context "uses sync connection" do
225
- it 'works fine' do
226
- VCR.use_cassette("publish-ssl-parameter-invalid-200-sync", :record => :none) do
227
- @pn.publish(:ssl => true, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
228
-
229
- @after_error_callback.should eq true
230
- @response_output.seek 0
231
- @response_output.read.should eq '[1,"Sent","'
232
- @message_output.seek 0
233
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
680
+
681
+ context 'with encrypting message' do
682
+
683
+ before(:each) do
684
+ @pubnub = Pubnub.new(
685
+ :max_retries => 0,
686
+ :subscribe_key => :demo,
687
+ :publish_key => :demo,
688
+ :secret_key => 'some_secret_key',
689
+ :cipher_key => 'secret',
690
+ :error_callback => @error_callback
691
+ )
692
+
693
+ @pubnub.uuid = 'tester'
694
+ end
695
+
696
+ context 'gets status 200 response' do
697
+ context 'with valid json' do
698
+ context 'its asynchronous' do
699
+ it 'publishes valid message' do
700
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-200-valid', :record => :none) do
701
+
702
+ @pubnub.publish(
703
+ :message => {:text => 'sometext'},
704
+ :channel => 'ruby_demo_channel',
705
+ :callback => @callback
706
+ )
707
+
708
+ eventually do
709
+ @envelopes.size.should eq 1
710
+ @envelopes.first.response_message.should eq 'Sent'
711
+ @envelopes.first.status.should eq 200
712
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
713
+ @envelopes.first.message.should eq({:text => 'sometext'})
714
+ @envelopes.first.timetoken.blank?.should eq false
715
+ end
716
+
717
+ end
718
+ end
719
+ end
720
+
721
+ context 'its synchronous' do
722
+ it 'publishes valid message' do
723
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-200-valid', :record => :none) do
724
+
725
+ @pubnub.publish(
726
+ :message => {:text => 'sometext'},
727
+ :channel => 'ruby_demo_channel',
728
+ :callback => @callback,
729
+ :http_sync => true
730
+ )
731
+
732
+ @envelopes.size.should eq 1
733
+ @envelopes.first.response_message.should eq 'Sent'
734
+ @envelopes.first.status.should eq 200
735
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
736
+ @envelopes.first.message.should eq({:text => 'sometext'})
737
+ @envelopes.first.timetoken.blank?.should eq false
738
+
739
+ end
234
740
  end
235
741
  end
236
742
  end
237
- context "uses async connection" do
238
- it 'works fine' do
239
- VCR.use_cassette("publish-ssl-parameter-invalid-200-async", :record => :none) do
240
- @pn.publish(:ssl => true, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
241
743
 
242
- eventually do
243
- @after_error_callback.should eq true
244
- @response_output.seek 0
245
- @response_output.read.should eq '[1,"Sent","'
246
- @message_output.seek 0
247
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
744
+ context 'with invalid json' do
745
+ context 'its asynchronous' do
746
+ it 'handles invalid json gracefully' do
747
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-200-invalid', :record => :none) do
748
+
749
+ @pubnub.publish(
750
+ :message => {:text => 'sometext'},
751
+ :channel => 'ruby_demo_channel',
752
+ :callback => @callback
753
+ )
754
+
755
+ eventually do
756
+ @envelopes.size.should eq 0
757
+ @error_envelopes.size.should eq 1
758
+ @error_envelopes.first.response_message.should eq nil
759
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
760
+ @error_envelopes.first.status.should eq 200
761
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
762
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
763
+ @error_envelopes.first.timetoken.blank?.should eq true
764
+ end
765
+
766
+ end
767
+ end
768
+ end
769
+
770
+ context 'its synchronous' do
771
+ it 'handles invalid json gracefully' do
772
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-200-invalid', :record => :none) do
773
+
774
+ @pubnub.publish(
775
+ :message => {:text => 'sometext'},
776
+ :channel => 'ruby_demo_channel',
777
+ :callback => @callback,
778
+ :http_sync => true
779
+ )
780
+
781
+ @envelopes.size.should eq 0
782
+ @error_envelopes.size.should eq 1
783
+ @error_envelopes.first.response_message.should eq nil
784
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
785
+ @error_envelopes.first.status.should eq 200
786
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
787
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
788
+ @error_envelopes.first.timetoken.blank?.should eq true
789
+
248
790
  end
249
791
  end
250
792
  end
251
793
  end
252
794
  end
253
- context "gets status non-200 in response" do
254
- context "uses sync connection" do
255
- it 'works fine' do
256
- VCR.use_cassette("publish-ssl-parameter-invalid-non-200-sync", :record => :none) do
257
- @pn.publish(:ssl => true, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
258
-
259
- @after_error_callback.should eq true
260
- @response_output.seek 0
261
- @response_output.read.should eq '[1,"Sent","'
262
- @message_output.seek 0
263
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
795
+
796
+ context 'gets status non200 response' do
797
+ context 'with valid json' do
798
+ context 'its asynchronous' do
799
+ it 'handles non200 response gracefully' do
800
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-non200-valid', :record => :none) do
801
+
802
+ @pubnub.publish(
803
+ :message => {:text => 'sometext'},
804
+ :channel => 'ruby_demo_channel',
805
+ :callback => @callback
806
+ )
807
+
808
+ eventually do
809
+ @envelopes.size.should eq 0
810
+ @error_envelopes.size.should eq 1
811
+ @error_envelopes.first.response_message.should eq 'Sent'
812
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
813
+ @error_envelopes.first.status.should eq 500
814
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
815
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
816
+ @error_envelopes.first.timetoken.blank?.should eq false
817
+ end
818
+
819
+ end
820
+ end
821
+ end
822
+
823
+ context 'its synchronous' do
824
+ it 'handles non200 response gracefully' do
825
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-non200-valid', :record => :none) do
826
+
827
+ @pubnub.publish(
828
+ :message => {:text => 'sometext'},
829
+ :channel => 'ruby_demo_channel',
830
+ :callback => @callback,
831
+ :http_sync => true
832
+ )
833
+
834
+ @envelopes.size.should eq 0
835
+ @error_envelopes.size.should eq 1
836
+ @error_envelopes.first.response_message.should eq 'Sent'
837
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
838
+ @error_envelopes.first.status.should eq 500
839
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
840
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
841
+ @error_envelopes.first.timetoken.blank?.should eq false
842
+
843
+ end
264
844
  end
265
845
  end
266
846
  end
267
- context "uses async connection" do
268
- it 'works fine' do
269
- VCR.use_cassette("publish-ssl-parameter-invalid-non-200-async", :record => :none) do
270
- @pn.publish(:ssl => true, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
271
847
 
272
- eventually do
273
- @after_error_callback.should eq true
274
- @response_output.seek 0
275
- @response_output.read.should eq '[1,"Sent","'
276
- @message_output.seek 0
277
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
848
+ context 'with invalid json' do
849
+ context 'its asynchronous' do
850
+ it 'handles invalid json and non200 response gracefully' do
851
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-non200-invalid', :record => :none) do
852
+
853
+ @pubnub.publish(
854
+ :message => {:text => 'sometext'},
855
+ :channel => 'ruby_demo_channel',
856
+ :callback => @callback
857
+ )
858
+
859
+ eventually do
860
+ @envelopes.size.should eq 0
861
+ @error_envelopes.size.should eq 1
862
+ @error_envelopes.first.response_message.should eq nil
863
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
864
+ @error_envelopes.first.status.should eq 500
865
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
866
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
867
+ @error_envelopes.first.timetoken.blank?.should eq true
868
+ end
869
+
870
+ end
871
+ end
872
+ end
873
+
874
+ context 'its synchronous' do
875
+ it 'handles invalid json and non200 response gracefully' do
876
+ VCR.use_cassette('new_ones/publish/publish-encrypted-http-non200-invalid', :record => :none) do
877
+
878
+ @pubnub.publish(
879
+ :message => {:text => 'sometext'},
880
+ :channel => 'ruby_demo_channel',
881
+ :callback => @callback,
882
+ :http_sync => true
883
+ )
884
+
885
+ @envelopes.size.should eq 0
886
+ @error_envelopes.size.should eq 1
887
+ @error_envelopes.first.response_message.should eq nil
888
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
889
+ @error_envelopes.first.status.should eq 500
890
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
891
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
892
+ @error_envelopes.first.timetoken.blank?.should eq true
893
+
278
894
  end
279
895
  end
280
896
  end
@@ -283,127 +899,445 @@ describe "#publish" do
283
899
  end
284
900
  end
285
901
  end
286
- context "uses non-ssl" do
287
- before(:each) { @ssl = false }
288
- context "passess callback as block" do
289
- context "gets valid json in response" do
290
- context "gets status 200 in response" do
291
- context "uses sync connection" do
292
- it 'works fine' do
293
- VCR.use_cassette("publish-nonssl-block-valid-200-sync", :record => :none) do
294
- @pn.publish(:ssl => false, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, &@callback)
295
-
296
- @after_callback.should eq true
297
- @response_output.seek 0
298
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
299
- @message_output.seek 0
300
- @message_output.read.should eq "{:text=>\"hey\"}"
902
+
903
+ context 'uses https' do
904
+ context 'with auth_key provided' do
905
+ context 'without encrypting message' do
906
+
907
+ before(:each) do
908
+ @pubnub = Pubnub.new(
909
+ :max_retries => 0,
910
+ :subscribe_key => :demo,
911
+ :publish_key => :demo,
912
+ :auth_key => :demoish_authkey,
913
+ :secret_key => 'some_secret_key',
914
+ :error_callback => @error_callback,
915
+ :ssl => true
916
+ )
917
+
918
+ @pubnub.uuid = 'tester'
919
+ end
920
+
921
+ context 'gets status 200 response' do
922
+ context 'with valid json' do
923
+ context 'its asynchronous' do
924
+ it 'publishes valid message' do
925
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-200-valid', :record => :none) do
926
+
927
+ @pubnub.publish(
928
+ :message => {:text => 'sometext'},
929
+ :channel => 'ruby_demo_channel',
930
+ :callback => @callback
931
+ )
932
+
933
+ eventually do
934
+ @envelopes.size.should eq 1
935
+ @envelopes.first.response_message.should eq 'Sent'
936
+ @envelopes.first.status.should eq 200
937
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
938
+ @envelopes.first.message.should eq({:text => 'sometext'})
939
+ @envelopes.first.timetoken.blank?.should eq false
940
+ end
941
+
942
+ end
943
+ end
944
+ end
945
+
946
+ context 'its synchronous' do
947
+ it 'publishes valid message' do
948
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-200-valid', :record => :none) do
949
+
950
+ @pubnub.publish(
951
+ :message => {:text => 'sometext'},
952
+ :channel => 'ruby_demo_channel',
953
+ :callback => @callback,
954
+ :http_sync => true
955
+ )
956
+
957
+ @envelopes.size.should eq 1
958
+ @envelopes.first.response_message.should eq 'Sent'
959
+ @envelopes.first.status.should eq 200
960
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
961
+ @envelopes.first.message.should eq({:text => 'sometext'})
962
+ @envelopes.first.timetoken.blank?.should eq false
963
+
964
+ end
301
965
  end
302
966
  end
303
967
  end
304
- context "uses async connection" do
305
- it 'works fine' do
306
- VCR.use_cassette("publish-nonssl-block-valid-200-async", :record => :none) do
307
- @pn.publish(:ssl => false, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, &@callback)
308
968
 
309
- eventually do
310
- @after_callback.should eq true
311
- @response_output.seek 0
312
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
313
- @message_output.seek 0
314
- @message_output.read.should eq "{:text=>\"hey\"}"
969
+ context 'with invalid json' do
970
+ context 'its asynchronous' do
971
+ it 'handles invalid json gracefully' do
972
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-200-invalid', :record => :none) do
973
+
974
+ @pubnub.publish(
975
+ :message => {:text => 'sometext'},
976
+ :channel => 'ruby_demo_channel',
977
+ :callback => @callback
978
+ )
979
+
980
+ eventually do
981
+ @envelopes.size.should eq 0
982
+ @error_envelopes.size.should eq 1
983
+ @error_envelopes.first.response_message.should eq nil
984
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
985
+ @error_envelopes.first.status.should eq 200
986
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
987
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
988
+ @error_envelopes.first.timetoken.blank?.should eq true
989
+ end
990
+
991
+ end
992
+ end
993
+ end
994
+
995
+ context 'its synchronous' do
996
+ it 'handles invalid json gracefully' do
997
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-200-invalid', :record => :none) do
998
+
999
+ @pubnub.publish(
1000
+ :message => {:text => 'sometext'},
1001
+ :channel => 'ruby_demo_channel',
1002
+ :callback => @callback,
1003
+ :http_sync => true
1004
+ )
1005
+
1006
+ @envelopes.size.should eq 0
1007
+ @error_envelopes.size.should eq 1
1008
+ @error_envelopes.first.response_message.should eq nil
1009
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1010
+ @error_envelopes.first.status.should eq 200
1011
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1012
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1013
+ @error_envelopes.first.timetoken.blank?.should eq true
1014
+
315
1015
  end
316
1016
  end
317
1017
  end
318
1018
  end
319
1019
  end
320
- context "gets status non-200 in response" do
321
- context "uses sync connection" do
322
- it 'works fine' do
323
- VCR.use_cassette("publish-nonssl-block-valid-non-200-sync", :record => :none) do
324
- @pn.publish(:ssl => false, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, &@callback)
325
-
326
- @after_error_callback.should eq true
327
- @response_output.seek 0
328
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
329
- @message_output.seek 0
330
- @message_output.read.should eq '[0,"Non 2xx server response."]'
1020
+
1021
+ context 'gets status non200 response' do
1022
+ context 'with valid json' do
1023
+ context 'its asynchronous' do
1024
+ it 'handles non200 response gracefully' do
1025
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-non200-valid', :record => :none) do
1026
+
1027
+ @pubnub.publish(
1028
+ :message => {:text => 'sometext'},
1029
+ :channel => 'ruby_demo_channel',
1030
+ :callback => @callback
1031
+ )
1032
+
1033
+ eventually do
1034
+ @envelopes.size.should eq 0
1035
+ @error_envelopes.size.should eq 1
1036
+ @error_envelopes.first.response_message.should eq 'Sent'
1037
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
1038
+ @error_envelopes.first.status.should eq 500
1039
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1040
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1041
+ @error_envelopes.first.timetoken.blank?.should eq false
1042
+ end
1043
+
1044
+ end
1045
+ end
1046
+ end
1047
+
1048
+ context 'its synchronous' do
1049
+ it 'handles non200 response gracefully' do
1050
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-non200-valid', :record => :none) do
1051
+
1052
+ @pubnub.publish(
1053
+ :message => {:text => 'sometext'},
1054
+ :channel => 'ruby_demo_channel',
1055
+ :callback => @callback,
1056
+ :http_sync => true
1057
+ )
1058
+
1059
+ @envelopes.size.should eq 0
1060
+ @error_envelopes.size.should eq 1
1061
+ @error_envelopes.first.response_message.should eq 'Sent'
1062
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
1063
+ @error_envelopes.first.status.should eq 500
1064
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1065
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1066
+ @error_envelopes.first.timetoken.blank?.should eq false
1067
+
1068
+ end
331
1069
  end
332
1070
  end
333
1071
  end
334
- context "uses async connection" do
335
- it 'works fine' do
336
- VCR.use_cassette("publish-nonssl-block-valid-non-200-async", :record => :none) do
337
- @pn.publish(:ssl => false, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, &@callback)
338
1072
 
339
- eventually do
340
- @after_error_callback.should eq true
341
- @response_output.seek 0
342
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
343
- @message_output.seek 0
344
- @message_output.read.should eq '[0,"Non 2xx server response."]'
1073
+ context 'with invalid json' do
1074
+ context 'its asynchronous' do
1075
+ it 'handles invalid json and non200 response gracefully' do
1076
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-non200-invalid', :record => :none) do
1077
+
1078
+ @pubnub.publish(
1079
+ :message => {:text => 'sometext'},
1080
+ :channel => 'ruby_demo_channel',
1081
+ :callback => @callback
1082
+ )
1083
+
1084
+ eventually do
1085
+ @envelopes.size.should eq 0
1086
+ @error_envelopes.size.should eq 1
1087
+ @error_envelopes.first.response_message.should eq nil
1088
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1089
+ @error_envelopes.first.status.should eq 500
1090
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1091
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1092
+ @error_envelopes.first.timetoken.blank?.should eq true
1093
+ end
1094
+
1095
+ end
1096
+ end
1097
+ end
1098
+
1099
+ context 'its synchronous' do
1100
+ it 'handles invalid json and non200 response gracefully' do
1101
+ VCR.use_cassette('new_ones/publish/publish-https-auth_key-non200-invalid', :record => :none) do
1102
+
1103
+ @pubnub.publish(
1104
+ :message => {:text => 'sometext'},
1105
+ :channel => 'ruby_demo_channel',
1106
+ :callback => @callback,
1107
+ :http_sync => true
1108
+ )
1109
+
1110
+ @envelopes.size.should eq 0
1111
+ @error_envelopes.size.should eq 1
1112
+ @error_envelopes.first.response_message.should eq nil
1113
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1114
+ @error_envelopes.first.status.should eq 500
1115
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1116
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1117
+ @error_envelopes.first.timetoken.blank?.should eq true
1118
+
345
1119
  end
346
1120
  end
347
1121
  end
348
1122
  end
349
1123
  end
350
1124
  end
351
- context "gets invalid json in response" do
352
- context "gets status 200 in response" do
353
- context "uses sync connection" do
354
- it 'works fine' do
355
- VCR.use_cassette("publish-nonssl-block-invalid-200-sync", :record => :none) do
356
- @pn.publish(:ssl => false, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, &@callback)
357
-
358
- @after_error_callback.should eq true
359
- @response_output.seek 0
360
- @response_output.read.should eq '[1,"Sent","'
361
- @message_output.seek 0
362
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
1125
+
1126
+ context 'with encrypting message' do
1127
+
1128
+ before(:each) do
1129
+ @pubnub = Pubnub.new(
1130
+ :max_retries => 0,
1131
+ :subscribe_key => :demo,
1132
+ :publish_key => :demo,
1133
+ :auth_key => :demoish_authkey,
1134
+ :secret_key => 'some_secret_key',
1135
+ :cipher_key => 'secret',
1136
+ :error_callback => @error_callback,
1137
+ :ssl => true
1138
+ )
1139
+
1140
+ @pubnub.uuid = 'tester'
1141
+ end
1142
+
1143
+ context 'gets status 200 response' do
1144
+ context 'with valid json' do
1145
+ context 'its asynchronous' do
1146
+ it 'publishes valid message' do
1147
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-200-valid', :record => :none) do
1148
+
1149
+ @pubnub.publish(
1150
+ :message => {:text => 'sometext'},
1151
+ :channel => 'ruby_demo_channel',
1152
+ :callback => @callback
1153
+ )
1154
+
1155
+ eventually do
1156
+ @envelopes.size.should eq 1
1157
+ @envelopes.first.response_message.should eq 'Sent'
1158
+ @envelopes.first.status.should eq 200
1159
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1160
+ @envelopes.first.message.should eq({:text => 'sometext'})
1161
+ @envelopes.first.timetoken.blank?.should eq false
1162
+ end
1163
+
1164
+ end
1165
+ end
1166
+ end
1167
+
1168
+ context 'its synchronous' do
1169
+ it 'publishes valid message' do
1170
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-200-valid', :record => :none) do
1171
+
1172
+ @pubnub.publish(
1173
+ :message => {:text => 'sometext'},
1174
+ :channel => 'ruby_demo_channel',
1175
+ :callback => @callback,
1176
+ :http_sync => true
1177
+ )
1178
+
1179
+ @envelopes.size.should eq 1
1180
+ @envelopes.first.response_message.should eq 'Sent'
1181
+ @envelopes.first.status.should eq 200
1182
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1183
+ @envelopes.first.message.should eq({:text => 'sometext'})
1184
+ @envelopes.first.timetoken.blank?.should eq false
1185
+
1186
+ end
363
1187
  end
364
1188
  end
365
1189
  end
366
- context "uses async connection" do
367
- it 'works fine' do
368
- VCR.use_cassette("publish-nonssl-block-invalid-200-async", :record => :none) do
369
- @pn.publish(:ssl => false, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, &@callback)
370
1190
 
371
- eventually do
372
- @after_error_callback.should eq true
373
- @response_output.seek 0
374
- @response_output.read.should eq '[1,"Sent","'
375
- @message_output.seek 0
376
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
1191
+ context 'with invalid json' do
1192
+ context 'its asynchronous' do
1193
+ it 'handles invalid json gracefully' do
1194
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-200-invalid', :record => :none) do
1195
+
1196
+ @pubnub.publish(
1197
+ :message => {:text => 'sometext'},
1198
+ :channel => 'ruby_demo_channel',
1199
+ :callback => @callback
1200
+ )
1201
+
1202
+ eventually do
1203
+ @envelopes.size.should eq 0
1204
+ @error_envelopes.size.should eq 1
1205
+ @error_envelopes.first.response_message.should eq nil
1206
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1207
+ @error_envelopes.first.status.should eq 200
1208
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1209
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1210
+ @error_envelopes.first.timetoken.blank?.should eq true
1211
+ end
1212
+
1213
+ end
1214
+ end
1215
+ end
1216
+
1217
+ context 'its synchronous' do
1218
+ it 'handles invalid json gracefully' do
1219
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-200-invalid', :record => :none) do
1220
+
1221
+ @pubnub.publish(
1222
+ :message => {:text => 'sometext'},
1223
+ :channel => 'ruby_demo_channel',
1224
+ :callback => @callback,
1225
+ :http_sync => true
1226
+ )
1227
+
1228
+ @envelopes.size.should eq 0
1229
+ @error_envelopes.size.should eq 1
1230
+ @error_envelopes.first.response_message.should eq nil
1231
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1232
+ @error_envelopes.first.status.should eq 200
1233
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1234
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1235
+ @error_envelopes.first.timetoken.blank?.should eq true
1236
+
377
1237
  end
378
1238
  end
379
1239
  end
380
1240
  end
381
1241
  end
382
- context "gets status non-200 in response" do
383
- context "uses sync connection" do
384
- it 'works fine' do
385
- VCR.use_cassette("publish-nonssl-block-invalid-non-200-sync", :record => :none) do
386
- @pn.publish(:ssl => false, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, &@callback)
387
-
388
- @after_error_callback.should eq true
389
- @response_output.seek 0
390
- @response_output.read.should eq '[1,"Sent","'
391
- @message_output.seek 0
392
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
1242
+
1243
+ context 'gets status non200 response' do
1244
+ context 'with valid json' do
1245
+ context 'its asynchronous' do
1246
+ it 'handles non200 response gracefully' do
1247
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-non200-valid', :record => :none) do
1248
+
1249
+ @pubnub.publish(
1250
+ :message => {:text => 'sometext'},
1251
+ :channel => 'ruby_demo_channel',
1252
+ :callback => @callback
1253
+ )
1254
+
1255
+ eventually do
1256
+ @envelopes.size.should eq 0
1257
+ @error_envelopes.size.should eq 1
1258
+ @error_envelopes.first.response_message.should eq 'Sent'
1259
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
1260
+ @error_envelopes.first.status.should eq 500
1261
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1262
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1263
+ @error_envelopes.first.timetoken.blank?.should eq false
1264
+ end
1265
+
1266
+ end
1267
+ end
1268
+ end
1269
+
1270
+ context 'its synchronous' do
1271
+ it 'handles non200 response gracefully' do
1272
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-non200-valid', :record => :none) do
1273
+
1274
+ @pubnub.publish(
1275
+ :message => {:text => 'sometext'},
1276
+ :channel => 'ruby_demo_channel',
1277
+ :callback => @callback,
1278
+ :http_sync => true
1279
+ )
1280
+
1281
+ @envelopes.size.should eq 0
1282
+ @error_envelopes.size.should eq 1
1283
+ @error_envelopes.first.response_message.should eq 'Sent'
1284
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
1285
+ @error_envelopes.first.status.should eq 500
1286
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1287
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1288
+ @error_envelopes.first.timetoken.blank?.should eq false
1289
+
1290
+ end
393
1291
  end
394
1292
  end
395
1293
  end
396
- context "uses async connection" do
397
- it 'works fine' do
398
- VCR.use_cassette("publish-nonssl-block-invalid-non-200-async", :record => :none) do
399
- @pn.publish(:ssl => false, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, &@callback)
400
1294
 
401
- eventually do
402
- @after_error_callback.should eq true
403
- @response_output.seek 0
404
- @response_output.read.should eq '[1,"Sent","'
405
- @message_output.seek 0
406
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
1295
+ context 'with invalid json' do
1296
+ context 'its asynchronous' do
1297
+ it 'handles invalid json and non200 response gracefully' do
1298
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-non200-invalid', :record => :none) do
1299
+
1300
+ @pubnub.publish(
1301
+ :message => {:text => 'sometext'},
1302
+ :channel => 'ruby_demo_channel',
1303
+ :callback => @callback
1304
+ )
1305
+
1306
+ eventually do
1307
+ @envelopes.size.should eq 0
1308
+ @error_envelopes.size.should eq 1
1309
+ @error_envelopes.first.response_message.should eq nil
1310
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1311
+ @error_envelopes.first.status.should eq 500
1312
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1313
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1314
+ @error_envelopes.first.timetoken.blank?.should eq true
1315
+ end
1316
+
1317
+ end
1318
+ end
1319
+ end
1320
+
1321
+ context 'its synchronous' do
1322
+ it 'handles invalid json and non200 response gracefully' do
1323
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-auth_key-non200-invalid', :record => :none) do
1324
+
1325
+ @pubnub.publish(
1326
+ :message => {:text => 'sometext'},
1327
+ :channel => 'ruby_demo_channel',
1328
+ :callback => @callback,
1329
+ :http_sync => true
1330
+ )
1331
+
1332
+ @envelopes.size.should eq 0
1333
+ @error_envelopes.size.should eq 1
1334
+ @error_envelopes.first.response_message.should eq nil
1335
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1336
+ @error_envelopes.first.status.should eq 500
1337
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1338
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1339
+ @error_envelopes.first.timetoken.blank?.should eq true
1340
+
407
1341
  end
408
1342
  end
409
1343
  end
@@ -411,125 +1345,442 @@ describe "#publish" do
411
1345
  end
412
1346
  end
413
1347
  end
414
- context "passess callback as parameter" do
415
- context "gets valid json in response" do
416
- context "gets status 200 in response" do
417
- context "uses sync connection" do
418
- it 'works fine' do
419
- VCR.use_cassette("publish-nonssl-parameter-valid-200-sync", :record => :none) do
420
- @pn.publish(:ssl => false, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
421
-
422
- @after_callback.should eq true
423
- @response_output.seek 0
424
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
425
- @message_output.seek 0
426
- @message_output.read.should eq "{:text=>\"hey\"}"
1348
+
1349
+ context 'without auth_key provided' do
1350
+ context 'without encrypting message' do
1351
+
1352
+ before(:each) do
1353
+ @pubnub = Pubnub.new(
1354
+ :max_retries => 0,
1355
+ :subscribe_key => :demo,
1356
+ :publish_key => :demo,
1357
+ :secret_key => 'some_secret_key',
1358
+ :error_callback => @error_callback,
1359
+ :ssl => true
1360
+ )
1361
+
1362
+ @pubnub.uuid = 'tester'
1363
+ end
1364
+
1365
+ context 'gets status 200 response' do
1366
+ context 'with valid json' do
1367
+ context 'its asynchronous' do
1368
+ it 'publishes valid message' do
1369
+ VCR.use_cassette('new_ones/publish/publish-https-200-valid', :record => :none) do
1370
+
1371
+ @pubnub.publish(
1372
+ :message => {:text => 'sometext'},
1373
+ :channel => 'ruby_demo_channel',
1374
+ :callback => @callback
1375
+ )
1376
+
1377
+ eventually do
1378
+ @envelopes.size.should eq 1
1379
+ @envelopes.first.response_message.should eq 'Sent'
1380
+ @envelopes.first.status.should eq 200
1381
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1382
+ @envelopes.first.message.should eq({:text => 'sometext'})
1383
+ @envelopes.first.timetoken.blank?.should eq false
1384
+ end
1385
+
1386
+ end
1387
+ end
1388
+ end
1389
+
1390
+ context 'its synchronous' do
1391
+ it 'publishes valid message' do
1392
+ VCR.use_cassette('new_ones/publish/publish-https-200-valid', :record => :none) do
1393
+
1394
+ @pubnub.publish(
1395
+ :message => {:text => 'sometext'},
1396
+ :channel => 'ruby_demo_channel',
1397
+ :callback => @callback,
1398
+ :http_sync => true
1399
+ )
1400
+
1401
+ @envelopes.size.should eq 1
1402
+ @envelopes.first.response_message.should eq 'Sent'
1403
+ @envelopes.first.status.should eq 200
1404
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1405
+ @envelopes.first.message.should eq({:text => 'sometext'})
1406
+ @envelopes.first.timetoken.blank?.should eq false
1407
+
1408
+ end
427
1409
  end
428
1410
  end
429
1411
  end
430
- context "uses async connection" do
431
- it 'works fine' do
432
- VCR.use_cassette("publish-nonssl-parameter-valid-200-async", :record => :none) do
433
- @pn.publish(:ssl => false, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
434
1412
 
435
- eventually do
436
- @after_callback.should eq true
437
- @response_output.seek 0
438
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
439
- @message_output.seek 0
440
- @message_output.read.should eq "{:text=>\"hey\"}"
1413
+ context 'with invalid json' do
1414
+ context 'its asynchronous' do
1415
+ it 'handles invalid json gracefully' do
1416
+ VCR.use_cassette('new_ones/publish/publish-https-200-invalid', :record => :none) do
1417
+
1418
+ @pubnub.publish(
1419
+ :message => {:text => 'sometext'},
1420
+ :channel => 'ruby_demo_channel',
1421
+ :callback => @callback
1422
+ )
1423
+
1424
+ eventually do
1425
+ @envelopes.size.should eq 0
1426
+ @error_envelopes.size.should eq 1
1427
+ @error_envelopes.first.response_message.should eq nil
1428
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1429
+ @error_envelopes.first.status.should eq 200
1430
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1431
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1432
+ @error_envelopes.first.timetoken.blank?.should eq true
1433
+ end
1434
+
1435
+ end
1436
+ end
1437
+ end
1438
+
1439
+ context 'its synchronous' do
1440
+ it 'handles invalid json gracefully' do
1441
+ VCR.use_cassette('new_ones/publish/publish-https-200-invalid', :record => :none) do
1442
+
1443
+ @pubnub.publish(
1444
+ :message => {:text => 'sometext'},
1445
+ :channel => 'ruby_demo_channel',
1446
+ :callback => @callback,
1447
+ :http_sync => true
1448
+ )
1449
+
1450
+ @envelopes.size.should eq 0
1451
+ @error_envelopes.size.should eq 1
1452
+ @error_envelopes.first.response_message.should eq nil
1453
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1454
+ @error_envelopes.first.status.should eq 200
1455
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1456
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1457
+ @error_envelopes.first.timetoken.blank?.should eq true
1458
+
441
1459
  end
442
1460
  end
443
1461
  end
444
1462
  end
445
1463
  end
446
- context "gets status non-200 in response" do
447
- context "uses sync connection" do
448
- it 'works fine' do
449
- VCR.use_cassette("publish-nonssl-parameter-valid-non-200-sync", :record => :none) do
450
- @pn.publish(:ssl => false, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
451
-
452
- @after_error_callback.should eq true
453
- @response_output.seek 0
454
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
455
- @message_output.seek 0
456
- @message_output.read.should eq '[0,"Non 2xx server response."]'
1464
+
1465
+ context 'gets status non200 response' do
1466
+ context 'with valid json' do
1467
+ context 'its asynchronous' do
1468
+ it 'handles non200 response gracefully' do
1469
+ VCR.use_cassette('new_ones/publish/publish-https-non200-valid', :record => :none) do
1470
+
1471
+ @pubnub.publish(
1472
+ :message => {:text => 'sometext'},
1473
+ :channel => 'ruby_demo_channel',
1474
+ :callback => @callback
1475
+ )
1476
+
1477
+ eventually do
1478
+ @envelopes.size.should eq 0
1479
+ @error_envelopes.size.should eq 1
1480
+ @error_envelopes.first.response_message.should eq 'Sent'
1481
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
1482
+ @error_envelopes.first.status.should eq 500
1483
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1484
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1485
+ @error_envelopes.first.timetoken.blank?.should eq false
1486
+ end
1487
+
1488
+ end
1489
+ end
1490
+ end
1491
+
1492
+ context 'its synchronous' do
1493
+ it 'handles non200 response gracefully' do
1494
+ VCR.use_cassette('new_ones/publish/publish-https-non200-valid', :record => :none) do
1495
+
1496
+ @pubnub.publish(
1497
+ :message => {:text => 'sometext'},
1498
+ :channel => 'ruby_demo_channel',
1499
+ :callback => @callback,
1500
+ :http_sync => true
1501
+ )
1502
+
1503
+ @envelopes.size.should eq 0
1504
+ @error_envelopes.size.should eq 1
1505
+ @error_envelopes.first.response_message.should eq 'Sent'
1506
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"]')
1507
+ @error_envelopes.first.status.should eq 500
1508
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1509
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1510
+ @error_envelopes.first.timetoken.blank?.should eq false
1511
+
1512
+ end
457
1513
  end
458
1514
  end
459
1515
  end
460
- context "uses async connection" do
461
- it 'works fine' do
462
- VCR.use_cassette("publish-nonssl-parameter-valid-non-200-async", :record => :none) do
463
- @pn.publish(:ssl => false, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
464
1516
 
465
- eventually do
466
- @after_error_callback.should eq true
467
- @response_output.seek 0
468
- @response_output.read.should eq '[1,"Sent","13904299694449458"]'
469
- @message_output.seek 0
470
- @message_output.read.should eq '[0,"Non 2xx server response."]'
1517
+ context 'with invalid json' do
1518
+ context 'its asynchronous' do
1519
+ it 'handles invalid json and non200 response gracefully' do
1520
+ VCR.use_cassette('new_ones/publish/publish-https-non200-invalid', :record => :none) do
1521
+
1522
+ @pubnub.publish(
1523
+ :message => {:text => 'sometext'},
1524
+ :channel => 'ruby_demo_channel',
1525
+ :callback => @callback
1526
+ )
1527
+
1528
+ eventually do
1529
+ @envelopes.size.should eq 0
1530
+ @error_envelopes.size.should eq 1
1531
+ @error_envelopes.first.response_message.should eq nil
1532
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1533
+ @error_envelopes.first.status.should eq 500
1534
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1535
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1536
+ @error_envelopes.first.timetoken.blank?.should eq true
1537
+ end
1538
+
1539
+ end
1540
+ end
1541
+ end
1542
+
1543
+ context 'its synchronous' do
1544
+ it 'handles invalid json and non200 response gracefully' do
1545
+ VCR.use_cassette('new_ones/publish/publish-https-non200-invalid', :record => :none) do
1546
+
1547
+ @pubnub.publish(
1548
+ :message => {:text => 'sometext'},
1549
+ :channel => 'ruby_demo_channel',
1550
+ :callback => @callback,
1551
+ :http_sync => true
1552
+ )
1553
+
1554
+ @envelopes.size.should eq 0
1555
+ @error_envelopes.size.should eq 1
1556
+ @error_envelopes.first.response_message.should eq nil
1557
+ @error_envelopes.first.response.should eq('[1,"Sent","13936818988607190"')
1558
+ @error_envelopes.first.status.should eq 500
1559
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1560
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1561
+ @error_envelopes.first.timetoken.blank?.should eq true
1562
+
471
1563
  end
472
1564
  end
473
1565
  end
474
1566
  end
475
1567
  end
476
1568
  end
477
- context "gets invalid json in response" do
478
- context "gets status 200 in response" do
479
- context "uses sync connection" do
480
- it 'works fine' do
481
- VCR.use_cassette("publish-nonssl-parameter-invalid-200-sync", :record => :none) do
482
- @pn.publish(:ssl => false, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
483
-
484
- @after_error_callback.should eq true
485
- @response_output.seek 0
486
- @response_output.read.should eq '[1,"Sent","'
487
- @message_output.seek 0
488
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
1569
+
1570
+ context 'with encrypting message' do
1571
+
1572
+ before(:each) do
1573
+ @pubnub = Pubnub.new(
1574
+ :max_retries => 0,
1575
+ :subscribe_key => :demo,
1576
+ :publish_key => :demo,
1577
+ :secret_key => 'some_secret_key',
1578
+ :cipher_key => 'secret',
1579
+ :error_callback => @error_callback,
1580
+ :ssl => true
1581
+ )
1582
+
1583
+ @pubnub.uuid = 'tester'
1584
+ end
1585
+
1586
+ context 'gets status 200 response' do
1587
+ context 'with valid json' do
1588
+ context 'its asynchronous' do
1589
+ it 'publishes valid message' do
1590
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-200-valid', :record => :none) do
1591
+
1592
+ @pubnub.publish(
1593
+ :message => {:text => 'sometext'},
1594
+ :channel => 'ruby_demo_channel',
1595
+ :callback => @callback
1596
+ )
1597
+
1598
+ eventually do
1599
+ @envelopes.size.should eq 1
1600
+ @envelopes.first.response_message.should eq 'Sent'
1601
+ @envelopes.first.status.should eq 200
1602
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1603
+ @envelopes.first.message.should eq({:text => 'sometext'})
1604
+ @envelopes.first.timetoken.blank?.should eq false
1605
+ end
1606
+
1607
+ end
1608
+ end
1609
+ end
1610
+
1611
+ context 'its synchronous' do
1612
+ it 'publishes valid message' do
1613
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-200-valid', :record => :none) do
1614
+
1615
+ @pubnub.publish(
1616
+ :message => {:text => 'sometext'},
1617
+ :channel => 'ruby_demo_channel',
1618
+ :callback => @callback,
1619
+ :http_sync => true
1620
+ )
1621
+
1622
+ @envelopes.size.should eq 1
1623
+ @envelopes.first.response_message.should eq 'Sent'
1624
+ @envelopes.first.status.should eq 200
1625
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1626
+ @envelopes.first.message.should eq({:text => 'sometext'})
1627
+ @envelopes.first.timetoken.blank?.should eq false
1628
+
1629
+ end
489
1630
  end
490
1631
  end
491
1632
  end
492
- context "uses async connection" do
493
- it 'works fine' do
494
- VCR.use_cassette("publish-nonssl-parameter-invalid-200-async", :record => :none) do
495
- @pn.publish(:ssl => false, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
496
1633
 
497
- eventually do
498
- @after_error_callback.should eq true
499
- @response_output.seek 0
500
- @response_output.read.should eq '[1,"Sent","'
501
- @message_output.seek 0
502
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
1634
+ context 'with invalid json' do
1635
+ context 'its asynchronous' do
1636
+ it 'handles invalid json gracefully' do
1637
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-200-invalid', :record => :none) do
1638
+
1639
+ @pubnub.publish(
1640
+ :message => {:text => 'sometext'},
1641
+ :channel => 'ruby_demo_channel',
1642
+ :callback => @callback
1643
+ )
1644
+
1645
+ eventually do
1646
+ @envelopes.size.should eq 0
1647
+ @error_envelopes.size.should eq 1
1648
+ @error_envelopes.first.response_message.should eq nil
1649
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1650
+ @error_envelopes.first.status.should eq 200
1651
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1652
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1653
+ @error_envelopes.first.timetoken.blank?.should eq true
1654
+ end
1655
+
1656
+ end
1657
+ end
1658
+ end
1659
+
1660
+ context 'its synchronous' do
1661
+ it 'handles invalid json gracefully' do
1662
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-200-invalid', :record => :none) do
1663
+
1664
+ @pubnub.publish(
1665
+ :message => {:text => 'sometext'},
1666
+ :channel => 'ruby_demo_channel',
1667
+ :callback => @callback,
1668
+ :http_sync => true
1669
+ )
1670
+
1671
+ @envelopes.size.should eq 0
1672
+ @error_envelopes.size.should eq 1
1673
+ @error_envelopes.first.response_message.should eq nil
1674
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1675
+ @error_envelopes.first.status.should eq 200
1676
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1677
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1678
+ @error_envelopes.first.timetoken.blank?.should eq true
1679
+
503
1680
  end
504
1681
  end
505
1682
  end
506
1683
  end
507
1684
  end
508
- context "gets status non-200 in response" do
509
- context "uses sync connection" do
510
- it 'works fine' do
511
- VCR.use_cassette("publish-nonssl-parameter-invalid-non-200-sync", :record => :none) do
512
- @pn.publish(:ssl => false, :http_sync => true, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
513
-
514
- @after_error_callback.should eq true
515
- @response_output.seek 0
516
- @response_output.read.should eq '[1,"Sent","'
517
- @message_output.seek 0
518
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
1685
+
1686
+ context 'gets status non200 response' do
1687
+ context 'with valid json' do
1688
+ context 'its asynchronous' do
1689
+ it 'handles non200 response gracefully' do
1690
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-non200-valid', :record => :none) do
1691
+
1692
+ @pubnub.publish(
1693
+ :message => {:text => 'sometext'},
1694
+ :channel => 'ruby_demo_channel',
1695
+ :callback => @callback
1696
+ )
1697
+
1698
+ eventually do
1699
+ @envelopes.size.should eq 0
1700
+ @error_envelopes.size.should eq 1
1701
+ @error_envelopes.first.response_message.should eq 'Sent'
1702
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
1703
+ @error_envelopes.first.status.should eq 500
1704
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1705
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1706
+ @error_envelopes.first.timetoken.blank?.should eq false
1707
+ end
1708
+
1709
+ end
1710
+ end
1711
+ end
1712
+
1713
+ context 'its synchronous' do
1714
+ it 'handles non200 response gracefully' do
1715
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-non200-valid', :record => :none) do
1716
+
1717
+ @pubnub.publish(
1718
+ :message => {:text => 'sometext'},
1719
+ :channel => 'ruby_demo_channel',
1720
+ :callback => @callback,
1721
+ :http_sync => true
1722
+ )
1723
+
1724
+ @envelopes.size.should eq 0
1725
+ @error_envelopes.size.should eq 1
1726
+ @error_envelopes.first.response_message.should eq 'Sent'
1727
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"]')
1728
+ @error_envelopes.first.status.should eq 500
1729
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1730
+ @error_envelopes.first.message.should eq('[0,"Non 2xx server response."]')
1731
+ @error_envelopes.first.timetoken.blank?.should eq false
1732
+
1733
+ end
519
1734
  end
520
1735
  end
521
1736
  end
522
- context "uses async connection" do
523
- it 'works fine' do
524
- VCR.use_cassette("publish-nonssl-parameter-invalid-non-200-async", :record => :none) do
525
- @pn.publish(:ssl => false, :http_sync => false, :channel => "demo", :message => {:text => "hey"}, :callback => @callback)
526
1737
 
527
- eventually do
528
- @after_error_callback.should eq true
529
- @response_output.seek 0
530
- @response_output.read.should eq '[1,"Sent","'
531
- @message_output.seek 0
532
- @message_output.read.should eq '[0,"Invalid JSON in response."]'
1738
+ context 'with invalid json' do
1739
+ context 'its asynchronous' do
1740
+ it 'handles invalid json and non200 response gracefully' do
1741
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-non200-invalid', :record => :none) do
1742
+
1743
+ @pubnub.publish(
1744
+ :message => {:text => 'sometext'},
1745
+ :channel => 'ruby_demo_channel',
1746
+ :callback => @callback
1747
+ )
1748
+
1749
+ eventually do
1750
+ @envelopes.size.should eq 0
1751
+ @error_envelopes.size.should eq 1
1752
+ @error_envelopes.first.response_message.should eq nil
1753
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1754
+ @error_envelopes.first.status.should eq 500
1755
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1756
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1757
+ @error_envelopes.first.timetoken.blank?.should eq true
1758
+ end
1759
+
1760
+ end
1761
+ end
1762
+ end
1763
+
1764
+ context 'its synchronous' do
1765
+ it 'handles invalid json and non200 response gracefully' do
1766
+ VCR.use_cassette('new_ones/publish/publish-encrypted-https-non200-invalid', :record => :none) do
1767
+
1768
+ @pubnub.publish(
1769
+ :message => {:text => 'sometext'},
1770
+ :channel => 'ruby_demo_channel',
1771
+ :callback => @callback,
1772
+ :http_sync => true
1773
+ )
1774
+
1775
+ @envelopes.size.should eq 0
1776
+ @error_envelopes.size.should eq 1
1777
+ @error_envelopes.first.response_message.should eq nil
1778
+ @error_envelopes.first.response.should eq('[1,"Sent","13937904716672898"')
1779
+ @error_envelopes.first.status.should eq 500
1780
+ @error_envelopes.first.channel.should eq('ruby_demo_channel')
1781
+ @error_envelopes.first.message.should eq('[0,"Invalid JSON in response."]')
1782
+ @error_envelopes.first.timetoken.blank?.should eq true
1783
+
533
1784
  end
534
1785
  end
535
1786
  end
@@ -538,4 +1789,79 @@ describe "#publish" do
538
1789
  end
539
1790
  end
540
1791
  end
541
- end
1792
+
1793
+ context 'when gets message as' do
1794
+ context 'array of hashes' do
1795
+ context 'and its plain' do
1796
+ it 'publishes it correctly' do
1797
+ @pubnub = Pubnub.new(
1798
+ :max_retries => 0,
1799
+ :subscribe_key => :demo,
1800
+ :publish_key => :demo,
1801
+ :secret_key => 'some_secret_key',
1802
+ :error_callback => @error_callback
1803
+ )
1804
+
1805
+ @pubnub.uuid = 'tester'
1806
+
1807
+ msg = [{:a => 1}, {:b => 2}, :c => [1,2,3]]
1808
+
1809
+ VCR.use_cassette('new_ones/publish/publish-plain-array-of-hashes', :record => :none) do
1810
+
1811
+ @pubnub.publish(
1812
+ :message => msg,
1813
+ :channel => 'ruby_demo_channel',
1814
+ :callback => @callback
1815
+ )
1816
+
1817
+ eventually do
1818
+ @envelopes.size.should eq 1
1819
+ @envelopes.first.response_message.should eq 'Sent'
1820
+ @envelopes.first.status.should eq 200
1821
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1822
+ @envelopes.first.message.should eq(msg)
1823
+ @envelopes.first.timetoken.blank?.should eq false
1824
+ end
1825
+ end
1826
+
1827
+ end
1828
+ end
1829
+
1830
+ context 'and its encrypted' do
1831
+ it 'publishes it correctly' do
1832
+ @pubnub = Pubnub.new(
1833
+ :max_retries => 0,
1834
+ :subscribe_key => :demo,
1835
+ :publish_key => :demo,
1836
+ :secret_key => 'some_secret_key',
1837
+ :cipher_key => 'secret',
1838
+ :error_callback => @error_callback,
1839
+ :ssl => true
1840
+ )
1841
+
1842
+ @pubnub.uuid = 'tester'
1843
+
1844
+ msg = [{:a => 1}, {:b => 2}, :c => [1,2,3]]
1845
+
1846
+ VCR.use_cassette('new_ones/publish/publish-encrypted-array-of-hashes', :record => :none) do
1847
+
1848
+ @pubnub.publish(
1849
+ :message => msg,
1850
+ :channel => 'ruby_demo_channel',
1851
+ :callback => @callback
1852
+ )
1853
+
1854
+ eventually do
1855
+ @envelopes.size.should eq 1
1856
+ @envelopes.first.response_message.should eq 'Sent'
1857
+ @envelopes.first.status.should eq 200
1858
+ @envelopes.first.channel.should eq 'ruby_demo_channel'
1859
+ @envelopes.first.message.should eq(msg)
1860
+ @envelopes.first.timetoken.blank?.should eq false
1861
+ end
1862
+ end
1863
+ end
1864
+ end
1865
+ end
1866
+ end
1867
+ end