pubnub 3.5.1 → 3.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/README.md +11 -0
- data/VERSION +1 -1
- data/examples/demo_console.rb +0 -1
- data/fixtures/vcr_cassettes/auth_key_flow_auth_publish.yml +45 -0
- data/fixtures/vcr_cassettes/auth_key_flow_empty_auth_audit.yml +44 -0
- data/fixtures/vcr_cassettes/auth_key_flow_instead_auth_audit.yml +44 -0
- data/fixtures/vcr_cassettes/auth_key_flow_no_auth_publish.yml +45 -0
- data/fixtures/vcr_cassettes/auth_key_flow_non_auth_audit.yml +44 -0
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-many-channels-array.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-many-channels-hash.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-many-channels-integer.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-many-channels-mix.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-many-channels-multi-mix.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-many-channels-string.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-one-channel-array.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-one-channel-hash.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-one-channel-integer.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-one-channel-mix.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-cipherkey-one-channel-string.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-many-channels-array.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-many-channels-hash.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-many-channels-integer.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-many-channels-mix.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-many-channels-multi-mix.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-many-channels-string.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-one-channel-array.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-one-channel-hash.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-one-channel-integer.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-one-channel-mix.yml +2 -2
- data/fixtures/vcr_cassettes/formatting-envelope-subscribe-without-cipherkey-one-channel-string.yml +2 -2
- data/fixtures/vcr_cassettes/heartbeat-non200.yml +519 -0
- data/fixtures/vcr_cassettes/heartbeat-test.yml +91 -0
- data/fixtures/vcr_cassettes/heartbeated-subscribe.yml +136 -0
- data/fixtures/vcr_cassettes/here_now_global-nonssl-block-invalid-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-nonssl-block-invalid-non-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-nonssl-block-valid-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-nonssl-block-valid-non-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-nonssl-parameter-invalid-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-nonssl-parameter-invalid-non-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-nonssl-parameter-valid-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-nonssl-parameter-valid-non-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-ssl-block-invalid-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-ssl-block-invalid-non-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-ssl-block-valid-200-async.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-ssl-block-valid-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-ssl-block-valid-non-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-ssl-parameter-invalid-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-ssl-parameter-invalid-non-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-ssl-parameter-valid-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/here_now_global-ssl-parameter-valid-non-200-sync.yml +49 -0
- data/fixtures/vcr_cassettes/new_ones/multiplexed_subscribe.yml +854 -0
- data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-array-of-hashes.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-http-200-invalid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-http-200-valid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-http-non200-invalid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-http-non200-valid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-https-200-invalid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-https-200-valid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-https-non200-invalid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-encrypted-https-non200-valid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-http-200-invalid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-http-200-valid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-http-non200-invalid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-http-non200-valid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-https-200-invalid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-https-200-valid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-https-non200-invalid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-https-non200-valid.yml +1 -1
- data/fixtures/vcr_cassettes/new_ones/publish/publish-plain-array-of-hashes.yml +1 -1
- data/fixtures/vcr_cassettes/non-heartbeated-subscribe.yml +44 -0
- data/fixtures/vcr_cassettes/pam20.yml +1 -1
- data/fixtures/vcr_cassettes/single-event-invalid-json.yml +15 -138
- data/fixtures/vcr_cassettes/v3-presence-nonssl-block-invalid-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-block-invalid-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-block-invalid-non-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-block-invalid-non-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-block-valid-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-block-valid-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-block-valid-non-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-block-valid-non-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-invalid-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-invalid-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-invalid-non-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-invalid-non-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-valid-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-valid-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-valid-non-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-nonssl-parameter-valid-non-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-block-invalid-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-block-invalid-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-block-invalid-non-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-block-invalid-non-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-block-valid-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-block-valid-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-block-valid-non-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-block-valid-non-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-invalid-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-invalid-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-invalid-non-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-invalid-non-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-valid-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-valid-200-sync.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-valid-non-200-async.yml +86 -0
- data/fixtures/vcr_cassettes/v3-presence-ssl-parameter-valid-non-200-sync.yml +86 -0
- data/lib/pubnub/client.rb +57 -31
- data/lib/pubnub/crypto.rb +6 -6
- data/lib/pubnub/event.rb +64 -45
- data/lib/pubnub/events/heartbeat.rb +59 -0
- data/lib/pubnub/events/here_now.rb +19 -10
- data/lib/pubnub/events/leave.rb +17 -9
- data/lib/pubnub/exceptions.rb +1 -1
- data/lib/pubnub/formatter.rb +1 -0
- data/lib/pubnub/pam.rb +5 -0
- data/lib/version.rb +1 -1
- data/pubnub.gemspec +2 -2
- data/spec/lib/auth_key_flow_spec.rb +60 -0
- data/spec/lib/heartbeat_spec.rb +110 -0
- data/spec/lib/integration/global_here_now_spec.rb +541 -0
- data/spec/lib/integration/multiplexed_subscribe_flow_spec.rb +44 -0
- data/spec/lib/integration/publish_spec.rb +1699 -373
- data/spec/lib/integration/publish_spec_old.rb +541 -0
- data/spec/lib/integration/v3_presence_spec.rb +557 -0
- metadata +68 -4
- data/examples/demo_console.rb~ +0 -307
- data/spec/lib/new_integration/publish_spec.rb +0 -1867
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Pubnub
|
|
2
|
+
class Heartbeat
|
|
3
|
+
include Pubnub::Event
|
|
4
|
+
include Pubnub::SingleEvent
|
|
5
|
+
include Pubnub::Formatter
|
|
6
|
+
include Pubnub::Validator
|
|
7
|
+
|
|
8
|
+
def initialize(options, app)
|
|
9
|
+
super
|
|
10
|
+
@event = 'heartbeat'
|
|
11
|
+
@allow_multiple_channels = true
|
|
12
|
+
@doesnt_require_callback = true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def fire(app)
|
|
16
|
+
super
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def path(app)
|
|
22
|
+
'/' + [
|
|
23
|
+
'v2',
|
|
24
|
+
'presence',
|
|
25
|
+
'sub-key',
|
|
26
|
+
@subscribe_key,
|
|
27
|
+
'channel',
|
|
28
|
+
@channel.join(','),
|
|
29
|
+
'heartbeat'
|
|
30
|
+
].join('/')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def parameters(app)
|
|
34
|
+
params = super(app)
|
|
35
|
+
params.merge!({ :state => URI.encode_www_form_component({}) })
|
|
36
|
+
params
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def format_envelopes(response, app, error)
|
|
40
|
+
|
|
41
|
+
parsed_response = Parser.parse_json(response.body) if Parser.valid_json?(response.body)
|
|
42
|
+
|
|
43
|
+
envelopes = Array.new
|
|
44
|
+
envelopes << Envelope.new(
|
|
45
|
+
{
|
|
46
|
+
:message => parsed_response,
|
|
47
|
+
:response_message => parsed_response
|
|
48
|
+
},
|
|
49
|
+
app
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
envelopes = add_common_data_to_envelopes(envelopes, response, app, error)
|
|
53
|
+
|
|
54
|
+
envelopes
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -16,22 +16,31 @@ module Pubnub
|
|
|
16
16
|
super
|
|
17
17
|
|
|
18
18
|
# check channel
|
|
19
|
-
raise ArgumentError.new(:object => self, :message => '
|
|
20
|
-
raise ArgumentError.new(:object => self, :message => 'Invalid channel format! Should be type of: String, Symbol') unless [String, Symbol].include?(@channel.class)
|
|
19
|
+
raise ArgumentError.new(:object => self, :message => 'Invalid channel format! Should be type of: String, Symbol') unless [String, Symbol, NilClass].include?(@channel.class)
|
|
21
20
|
|
|
22
21
|
end
|
|
23
22
|
|
|
24
23
|
private
|
|
25
24
|
|
|
26
25
|
def path(app)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
unless @channel.blank?
|
|
27
|
+
'/' + [
|
|
28
|
+
'v2',
|
|
29
|
+
'presence',
|
|
30
|
+
'sub-key',
|
|
31
|
+
@subscribe_key,
|
|
32
|
+
'channel',
|
|
33
|
+
@channel
|
|
34
|
+
].join('/')
|
|
35
|
+
else
|
|
36
|
+
$logger.debug('Pubnub'){'Global here_now'}
|
|
37
|
+
'/' + [
|
|
38
|
+
'v2',
|
|
39
|
+
'presence',
|
|
40
|
+
'sub-key',
|
|
41
|
+
@subscribe_key
|
|
42
|
+
].join('/')
|
|
43
|
+
end
|
|
35
44
|
end
|
|
36
45
|
|
|
37
46
|
def format_envelopes(response, app, error)
|
data/lib/pubnub/events/leave.rb
CHANGED
|
@@ -24,15 +24,23 @@ module Pubnub
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def fire(app)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
$logger.debug('Pubnub'){"Pubnub::Leave#fire"}
|
|
28
|
+
unless @left
|
|
29
|
+
app.update_timetoken(0)
|
|
30
|
+
if app.env[:subscriptions][@origin].nil?
|
|
31
|
+
$logger.error('Pubnub'){'There\'s no subscription for that origin'}
|
|
32
|
+
raise ArgumentError.new(:object => self, :message => 'You cannot leave channel that is not subscribed')
|
|
33
|
+
else
|
|
34
|
+
@channel.each do |channel|
|
|
35
|
+
$logger.debug('Pubnub'){"#{app.env[:subscriptions][@origin].get_channels.to_s}.include? #{channel}"}
|
|
36
|
+
raise ArgumentError.new(:object => self, :message => 'You cannot leave channel that is not subscribed') unless app.env[:subscriptions][@origin].get_channels.include?(channel)
|
|
37
|
+
end
|
|
38
|
+
end unless @force
|
|
39
|
+
@channel.each do |channel|
|
|
40
|
+
app.env[:subscriptions][@origin].remove_channel(channel, app) if app.env[:subscriptions][@origin]
|
|
41
|
+
@left = true
|
|
42
|
+
end unless @skip_remove
|
|
43
|
+
end
|
|
36
44
|
super
|
|
37
45
|
end
|
|
38
46
|
|
data/lib/pubnub/exceptions.rb
CHANGED
data/lib/pubnub/formatter.rb
CHANGED
data/lib/pubnub/pam.rb
CHANGED
data/lib/version.rb
CHANGED
data/pubnub.gemspec
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = 'pubnub'
|
|
5
|
-
s.version = '3.5.
|
|
5
|
+
s.version = '3.5.3'
|
|
6
6
|
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
|
8
8
|
s.authors = ['PubNub']
|
|
9
|
-
s.date = '2014-
|
|
9
|
+
s.date = '2014-04-14'
|
|
10
10
|
s.description = 'Ruby anywhere in the world in 250ms with PubNub!'
|
|
11
11
|
s.email = 'support@pubnub.com'
|
|
12
12
|
s.files = `git ls-files`.split("\n")
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
# If VCR would fail, that means auth_key isn't set as desired in params
|
|
4
|
+
describe 'auth_key flow' do
|
|
5
|
+
|
|
6
|
+
before(:each) do
|
|
7
|
+
origin = 'pubsub.pubnub.com'
|
|
8
|
+
sub_key = 'sub-c-a478dd2a-c33d-11e2-883f-02ee2ddab7fe'
|
|
9
|
+
pub_key = 'pub-c-a2650a22-deb1-44f5-aa87-1517049411d5'
|
|
10
|
+
sec_key = 'sec-c-YjFmNzYzMGMtYmI3NC00NzJkLTlkYzYtY2MwMzI4YTJhNDVh'
|
|
11
|
+
@pn = Pubnub.new(:subscribe_key => sub_key, :publish_key => pub_key, :secret_key => sec_key, :error_callback => lambda {|e|})
|
|
12
|
+
|
|
13
|
+
Pubnub::Audit.any_instance.stub(:current_time).and_return 1234567890
|
|
14
|
+
Pubnub::Audit.any_instance.stub(:signature).and_return 'kdDh/sFC3rSR%2Bt5AEymIc57d1velIr562V7usa5M4k0='
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context 'non-pam' do
|
|
18
|
+
it 'isn\'t appened to params if isn\'t set' do
|
|
19
|
+
VCR.use_cassette("auth_key_flow_no_auth_publish", :record => :none) do
|
|
20
|
+
enve = @pn.publish(:channel => :ruby_test, :http_sync => true, :message => :whatever)
|
|
21
|
+
enve.size.should eq 1
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'appears in params if set' do
|
|
26
|
+
VCR.use_cassette("auth_key_flow_auth_publish", :record => :none) do
|
|
27
|
+
@pn.auth_key = 'ruby_client_123'
|
|
28
|
+
enve = @pn.publish(:channel => :ruby_test, :http_sync => true, :message => :whatever)
|
|
29
|
+
enve.size.should eq 1
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context 'PAM' do
|
|
35
|
+
it 'doesn\'t care if it\'s set in client' do
|
|
36
|
+
VCR.use_cassette("auth_key_flow_non_auth_audit", :record => :none) do
|
|
37
|
+
@pn.auth_key = 'ruby_client_123'
|
|
38
|
+
enve = @pn.audit(:channel => :ruby_test, :http_sync => true)
|
|
39
|
+
enve.size.should eq 1
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'uses passed auth_key insted of client auth_key' do
|
|
44
|
+
VCR.use_cassette("auth_key_flow_instead_auth_audit", :record => :none) do
|
|
45
|
+
@pn.auth_key = 'ruby_client_123'
|
|
46
|
+
enve = @pn.audit(:channel => :ruby_test, :http_sync => true, :auth_key => 'omg_so_key')
|
|
47
|
+
enve.size.should eq 1
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'uses passed auth_key when client auth_key is blank' do
|
|
52
|
+
VCR.use_cassette("auth_key_flow_empty_auth_audit", :record => :none) do
|
|
53
|
+
enve = @pn.audit(:channel => :ruby_test, :http_sync => true, :auth_key => 'omg_so_key')
|
|
54
|
+
enve.size.should eq 1
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'hearbeat' do
|
|
4
|
+
|
|
5
|
+
it 'default should be nil' do
|
|
6
|
+
@pn = Pubnub.new(:subscribe_key => :test)
|
|
7
|
+
@pn.env[:heartbeat].should eq nil
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it 'is present in subscribe request when set, also fires leave after sync subscribe' do
|
|
11
|
+
@pn = Pubnub.new(:subscribe_key => 'demo-36', :heartbeat => 100)
|
|
12
|
+
|
|
13
|
+
VCR.use_cassette("heartbeated-subscribe", :record => :none) do
|
|
14
|
+
enve = @pn.subscribe(:channel => :ruby_test, :http_sync => true) # request would file if heartbeat would not be present
|
|
15
|
+
enve.size.should eq 1
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'isn\'t present in subscribe request when not set' do
|
|
21
|
+
@pn = Pubnub.new(:subscribe_key => 'demo-36')
|
|
22
|
+
|
|
23
|
+
VCR.use_cassette("non-heartbeated-subscribe", :record => :none) do
|
|
24
|
+
enve = @pn.subscribe(:channel => :ruby_test, :http_sync => true) # request would file if heartbeat would be present
|
|
25
|
+
enve.size.should eq 1
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'is called every heartbeat/2 - 1 seconds' do
|
|
31
|
+
@pn = Pubnub.new(:subscribe_key => 'demo-36', :heartbeat => '12')
|
|
32
|
+
|
|
33
|
+
VCR.use_cassette("heartbeat-test", :record => :all) do
|
|
34
|
+
@pn.subscribe(:channel => 'rubyheartbeatdemo'){|e| }
|
|
35
|
+
eventually do
|
|
36
|
+
@pn.env[:heartbeat].to_i.should eq 12
|
|
37
|
+
@pn.env[:respirator].interval.should eq 5
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'calls error_callback if get\'s non-200 response' do
|
|
43
|
+
@error = false
|
|
44
|
+
error_callback = lambda do |error|
|
|
45
|
+
@error = true
|
|
46
|
+
EM.stop
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
@pn = Pubnub.new(:subscribe_key => 'demo-36', :heartbeat => '4', :error_callback => error_callback)
|
|
50
|
+
VCR.use_cassette("heartbeat-non200", :record => :new_episodes) do
|
|
51
|
+
@pn.subscribe(:channel => 'rubyheartbeatdemo'){|e| }
|
|
52
|
+
eventually do
|
|
53
|
+
@error.should eq true
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
context 'is settable' do
|
|
59
|
+
before(:each) do
|
|
60
|
+
@pn = Pubnub.new(:subscribe_key => :test)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'at init time' do
|
|
64
|
+
@pn = Pubnub.new(:subscribe_key => :test, :heartbeat => 100)
|
|
65
|
+
@pn.env[:heartbeat].should eq 100
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'via heartbeat=' do
|
|
69
|
+
@pn.heartbeat = 100
|
|
70
|
+
@pn.env[:heartbeat].should eq 100
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'via set_heartbeat(value)' do
|
|
74
|
+
@pn.set_heartbeat 100
|
|
75
|
+
@pn.env[:heartbeat].should eq 100
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context 'is updateable' do
|
|
80
|
+
before(:each) do
|
|
81
|
+
@pn = Pubnub.new(:subscribe_key => :test)
|
|
82
|
+
@pn.heartbeat = 100
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'via heartbeat=' do
|
|
86
|
+
@pn.heartbeat = 200
|
|
87
|
+
@pn.env[:heartbeat].should eq 200
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'via set_heartbeat(value)' do
|
|
91
|
+
@pn.set_heartbeat 200
|
|
92
|
+
@pn.env[:heartbeat].should eq 200
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
context 'is gettable' do
|
|
97
|
+
before(:each) do
|
|
98
|
+
@pn = Pubnub.new(:subscribe_key => :test)
|
|
99
|
+
@pn.heartbeat = 100
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it 'via get_heartbeat' do
|
|
103
|
+
@pn.get_heartbeat.should eq 100
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
it 'via .env' do
|
|
107
|
+
@pn.env[:heartbeat].should eq 100
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "#here_now" do
|
|
4
|
+
before(:each) do
|
|
5
|
+
|
|
6
|
+
EM.stop if EM.reactor_running?
|
|
7
|
+
while EM.reactor_running? do end
|
|
8
|
+
sleep(0.1)
|
|
9
|
+
|
|
10
|
+
@response_output = StringIO.new
|
|
11
|
+
@message_output = StringIO.new
|
|
12
|
+
|
|
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
|
+
}
|
|
19
|
+
|
|
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
|
+
}
|
|
26
|
+
|
|
27
|
+
@pn = Pubnub.new(:max_retries => 0, :subscribe_key => 'demo-36', :publish_key => 'demo-36', :auth_key => :demoish_authkey, :secret_key => 'some_secret_key', :error_callback => @error_callback)
|
|
28
|
+
@pn.uuid = 'rubytests'
|
|
29
|
+
|
|
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("here_now_global-ssl-block-valid-200-sync", :record => :none) do
|
|
39
|
+
@pn.here_now(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
|
|
40
|
+
|
|
41
|
+
@after_callback.should eq true
|
|
42
|
+
@response_output.seek 0
|
|
43
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
44
|
+
@message_output.seek 0
|
|
45
|
+
@message_output.read.should eq '{"status"=>200, "message"=>"OK", "service"=>"Presence", "uuids"=>[], "occupancy"=>0}'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
context "uses async connection" do
|
|
50
|
+
it 'works fine' do
|
|
51
|
+
VCR.use_cassette("here_now_global-ssl-block-valid-200-async", :record => :none) do
|
|
52
|
+
@pn.here_now(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
|
|
53
|
+
|
|
54
|
+
eventually do
|
|
55
|
+
@after_callback.should eq true
|
|
56
|
+
@response_output.seek 0
|
|
57
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
58
|
+
@message_output.seek 0
|
|
59
|
+
@message_output.read.should eq '{"status"=>200, "message"=>"OK", "service"=>"Presence", "uuids"=>[], "occupancy"=>0}'
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
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("here_now_global-ssl-block-valid-non-200-sync", :record => :none) do
|
|
69
|
+
@pn.here_now(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
|
|
70
|
+
|
|
71
|
+
@after_error_callback.should eq true
|
|
72
|
+
@response_output.seek 0
|
|
73
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
74
|
+
@message_output.seek 0
|
|
75
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
context "uses async connection" do
|
|
80
|
+
it 'works fine' do
|
|
81
|
+
VCR.use_cassette("here_now_global-ssl-block-valid-non-200-sync", :record => :none) do
|
|
82
|
+
@pn.here_now(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
|
|
83
|
+
|
|
84
|
+
eventually do
|
|
85
|
+
@after_error_callback.should eq true
|
|
86
|
+
@response_output.seek 0
|
|
87
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
88
|
+
@message_output.seek 0
|
|
89
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
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("here_now_global-ssl-block-invalid-200-sync", :record => :none) do
|
|
101
|
+
@pn.here_now(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
|
|
102
|
+
|
|
103
|
+
@after_error_callback.should eq true
|
|
104
|
+
@response_output.seek 0
|
|
105
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
106
|
+
@message_output.seek 0
|
|
107
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
context "uses async connection" do
|
|
112
|
+
it 'works fine' do
|
|
113
|
+
VCR.use_cassette("here_now_global-ssl-block-invalid-200-sync", :record => :none) do
|
|
114
|
+
@pn.here_now(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
|
|
115
|
+
|
|
116
|
+
eventually do
|
|
117
|
+
@after_error_callback.should eq true
|
|
118
|
+
@response_output.seek 0
|
|
119
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
120
|
+
@message_output.seek 0
|
|
121
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
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("here_now_global-ssl-block-invalid-non-200-sync", :record => :none) do
|
|
131
|
+
@pn.here_now(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
|
|
132
|
+
|
|
133
|
+
@after_error_callback.should eq true
|
|
134
|
+
@response_output.seek 0
|
|
135
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
136
|
+
@message_output.seek 0
|
|
137
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
context "uses async connection" do
|
|
142
|
+
it 'works fine' do
|
|
143
|
+
VCR.use_cassette("here_now_global-ssl-block-invalid-non-200-sync", :record => :none) do
|
|
144
|
+
@pn.here_now(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
|
|
145
|
+
|
|
146
|
+
eventually do
|
|
147
|
+
@after_error_callback.should eq true
|
|
148
|
+
@response_output.seek 0
|
|
149
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
150
|
+
@message_output.seek 0
|
|
151
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
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("here_now_global-ssl-block-valid-200-sync", :record => :none) do
|
|
165
|
+
@pn.here_now(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
|
|
166
|
+
|
|
167
|
+
@after_callback.should eq true
|
|
168
|
+
@response_output.seek 0
|
|
169
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
170
|
+
@message_output.seek 0
|
|
171
|
+
@message_output.read.should eq '{"status"=>200, "message"=>"OK", "service"=>"Presence", "uuids"=>[], "occupancy"=>0}'
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
context "uses async connection" do
|
|
176
|
+
it 'works fine' do
|
|
177
|
+
VCR.use_cassette("here_now_global-ssl-block-valid-200-async", :record => :none) do
|
|
178
|
+
@pn.here_now(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
|
|
179
|
+
|
|
180
|
+
eventually do
|
|
181
|
+
@after_callback.should eq true
|
|
182
|
+
@response_output.seek 0
|
|
183
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
184
|
+
@message_output.seek 0
|
|
185
|
+
@message_output.read.should eq '{"status"=>200, "message"=>"OK", "service"=>"Presence", "uuids"=>[], "occupancy"=>0}'
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
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("here_now_global-ssl-block-valid-non-200-sync", :record => :none) do
|
|
195
|
+
@pn.here_now(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
|
|
196
|
+
|
|
197
|
+
@after_error_callback.should eq true
|
|
198
|
+
@response_output.seek 0
|
|
199
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
200
|
+
@message_output.seek 0
|
|
201
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
context "uses async connection" do
|
|
206
|
+
it 'works fine' do
|
|
207
|
+
VCR.use_cassette("here_now_global-ssl-block-valid-non-200-sync", :record => :none) do
|
|
208
|
+
@pn.here_now(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
|
|
209
|
+
|
|
210
|
+
eventually do
|
|
211
|
+
@after_error_callback.should eq true
|
|
212
|
+
@response_output.seek 0
|
|
213
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
214
|
+
@message_output.seek 0
|
|
215
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
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("here_now_global-ssl-block-invalid-200-sync", :record => :none) do
|
|
227
|
+
@pn.here_now(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
|
|
228
|
+
|
|
229
|
+
@after_error_callback.should eq true
|
|
230
|
+
@response_output.seek 0
|
|
231
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
232
|
+
@message_output.seek 0
|
|
233
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
context "uses async connection" do
|
|
238
|
+
it 'works fine' do
|
|
239
|
+
VCR.use_cassette("here_now_global-ssl-block-invalid-200-sync", :record => :none) do
|
|
240
|
+
@pn.here_now(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
|
|
241
|
+
|
|
242
|
+
eventually do
|
|
243
|
+
@after_error_callback.should eq true
|
|
244
|
+
@response_output.seek 0
|
|
245
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
246
|
+
@message_output.seek 0
|
|
247
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
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("here_now_global-ssl-block-invalid-non-200-sync", :record => :none) do
|
|
257
|
+
@pn.here_now(:ssl => true, :http_sync => true, :channel => "demo", :callback => @callback)
|
|
258
|
+
|
|
259
|
+
@after_error_callback.should eq true
|
|
260
|
+
@response_output.seek 0
|
|
261
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
262
|
+
@message_output.seek 0
|
|
263
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
context "uses async connection" do
|
|
268
|
+
it 'works fine' do
|
|
269
|
+
VCR.use_cassette("here_now_global-ssl-block-invalid-non-200-sync", :record => :none) do
|
|
270
|
+
@pn.here_now(:ssl => true, :http_sync => false, :channel => "demo", :callback => @callback)
|
|
271
|
+
|
|
272
|
+
eventually do
|
|
273
|
+
@after_error_callback.should eq true
|
|
274
|
+
@response_output.seek 0
|
|
275
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
276
|
+
@message_output.seek 0
|
|
277
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
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("here_now_global-nonssl-block-valid-200-sync", :record => :none) do
|
|
294
|
+
@pn.here_now(:http_sync => true, :channel => "demo", :callback => @callback)
|
|
295
|
+
|
|
296
|
+
@after_callback.should eq true
|
|
297
|
+
@response_output.seek 0
|
|
298
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
299
|
+
@message_output.seek 0
|
|
300
|
+
@message_output.read.should eq '{"status"=>200, "message"=>"OK", "service"=>"Presence", "uuids"=>[], "occupancy"=>0}'
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
context "uses async connection" do
|
|
305
|
+
it 'works fine' do
|
|
306
|
+
VCR.use_cassette("here_now_global-nonssl-block-valid-200-sync", :record => :none) do
|
|
307
|
+
@pn.here_now(:http_sync => false, :channel => "demo", :callback => @callback)
|
|
308
|
+
|
|
309
|
+
eventually do
|
|
310
|
+
@after_callback.should eq true
|
|
311
|
+
@response_output.seek 0
|
|
312
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
313
|
+
@message_output.seek 0
|
|
314
|
+
@message_output.read.should eq '{"status"=>200, "message"=>"OK", "service"=>"Presence", "uuids"=>[], "occupancy"=>0}'
|
|
315
|
+
end
|
|
316
|
+
end
|
|
317
|
+
end
|
|
318
|
+
end
|
|
319
|
+
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("here_now_global-nonssl-block-valid-non-200-sync", :record => :none) do
|
|
324
|
+
@pn.here_now(:http_sync => true, :channel => "demo", :callback => @callback)
|
|
325
|
+
|
|
326
|
+
@after_error_callback.should eq true
|
|
327
|
+
@response_output.seek 0
|
|
328
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
329
|
+
@message_output.seek 0
|
|
330
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
context "uses async connection" do
|
|
335
|
+
it 'works fine' do
|
|
336
|
+
VCR.use_cassette("here_now_global-nonssl-block-valid-non-200-sync", :record => :none) do
|
|
337
|
+
@pn.here_now(:http_sync => false, :channel => "demo", :callback => @callback)
|
|
338
|
+
|
|
339
|
+
eventually do
|
|
340
|
+
@after_error_callback.should eq true
|
|
341
|
+
@response_output.seek 0
|
|
342
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
343
|
+
@message_output.seek 0
|
|
344
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
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("here_now_global-nonssl-block-invalid-200-sync", :record => :none) do
|
|
356
|
+
@pn.here_now(:http_sync => true, :channel => "demo", :callback => @callback)
|
|
357
|
+
|
|
358
|
+
@after_error_callback.should eq true
|
|
359
|
+
@response_output.seek 0
|
|
360
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
361
|
+
@message_output.seek 0
|
|
362
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
context "uses async connection" do
|
|
367
|
+
it 'works fine' do
|
|
368
|
+
VCR.use_cassette("here_now_global-nonssl-block-invalid-200-sync", :record => :none) do
|
|
369
|
+
@pn.here_now(:http_sync => false, :channel => "demo", :callback => @callback)
|
|
370
|
+
|
|
371
|
+
eventually do
|
|
372
|
+
@after_error_callback.should eq true
|
|
373
|
+
@response_output.seek 0
|
|
374
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
375
|
+
@message_output.seek 0
|
|
376
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
377
|
+
end
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
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("here_now_global-nonssl-block-invalid-non-200-sync", :record => :none) do
|
|
386
|
+
@pn.here_now(:http_sync => true, :channel => "demo", :callback => @callback)
|
|
387
|
+
|
|
388
|
+
@after_error_callback.should eq true
|
|
389
|
+
@response_output.seek 0
|
|
390
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
391
|
+
@message_output.seek 0
|
|
392
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
393
|
+
end
|
|
394
|
+
end
|
|
395
|
+
end
|
|
396
|
+
context "uses async connection" do
|
|
397
|
+
it 'works fine' do
|
|
398
|
+
VCR.use_cassette("here_now_global-nonssl-block-invalid-non-200-sync", :record => :none) do
|
|
399
|
+
@pn.here_now(:http_sync => false, :channel => "demo", :callback => @callback)
|
|
400
|
+
|
|
401
|
+
eventually do
|
|
402
|
+
@after_error_callback.should eq true
|
|
403
|
+
@response_output.seek 0
|
|
404
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
405
|
+
@message_output.seek 0
|
|
406
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
407
|
+
end
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
end
|
|
411
|
+
end
|
|
412
|
+
end
|
|
413
|
+
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("here_now_global-nonssl-block-valid-200-sync", :record => :none) do
|
|
420
|
+
@pn.here_now(:http_sync => true, :channel => "demo", :callback => @callback)
|
|
421
|
+
|
|
422
|
+
@after_callback.should eq true
|
|
423
|
+
@response_output.seek 0
|
|
424
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
425
|
+
@message_output.seek 0
|
|
426
|
+
@message_output.read.should eq '{"status"=>200, "message"=>"OK", "service"=>"Presence", "uuids"=>[], "occupancy"=>0}'
|
|
427
|
+
end
|
|
428
|
+
end
|
|
429
|
+
end
|
|
430
|
+
context "uses async connection" do
|
|
431
|
+
it 'works fine' do
|
|
432
|
+
VCR.use_cassette("here_now_global-nonssl-block-valid-200-sync", :record => :none) do
|
|
433
|
+
@pn.here_now(:http_sync => false, :channel => "demo", :callback => @callback)
|
|
434
|
+
|
|
435
|
+
eventually do
|
|
436
|
+
@after_callback.should eq true
|
|
437
|
+
@response_output.seek 0
|
|
438
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
439
|
+
@message_output.seek 0
|
|
440
|
+
@message_output.read.should eq '{"status"=>200, "message"=>"OK", "service"=>"Presence", "uuids"=>[], "occupancy"=>0}'
|
|
441
|
+
end
|
|
442
|
+
end
|
|
443
|
+
end
|
|
444
|
+
end
|
|
445
|
+
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("here_now_global-nonssl-block-valid-non-200-sync", :record => :none) do
|
|
450
|
+
@pn.here_now(:http_sync => true, :channel => "demo", :callback => @callback)
|
|
451
|
+
|
|
452
|
+
@after_error_callback.should eq true
|
|
453
|
+
@response_output.seek 0
|
|
454
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
455
|
+
@message_output.seek 0
|
|
456
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
|
457
|
+
end
|
|
458
|
+
end
|
|
459
|
+
end
|
|
460
|
+
context "uses async connection" do
|
|
461
|
+
it 'works fine' do
|
|
462
|
+
VCR.use_cassette("here_now_global-nonssl-block-valid-non-200-sync", :record => :none) do
|
|
463
|
+
@pn.here_now(:http_sync => false, :channel => "demo", :callback => @callback)
|
|
464
|
+
|
|
465
|
+
eventually do
|
|
466
|
+
@after_error_callback.should eq true
|
|
467
|
+
@response_output.seek 0
|
|
468
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0}'
|
|
469
|
+
@message_output.seek 0
|
|
470
|
+
@message_output.read.should eq '[0,"Non 2xx server response."]'
|
|
471
|
+
end
|
|
472
|
+
end
|
|
473
|
+
end
|
|
474
|
+
end
|
|
475
|
+
end
|
|
476
|
+
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("here_now_global-nonssl-block-invalid-200-sync", :record => :none) do
|
|
482
|
+
@pn.here_now(:http_sync => true, :channel => "demo", :callback => @callback)
|
|
483
|
+
|
|
484
|
+
@after_error_callback.should eq true
|
|
485
|
+
@response_output.seek 0
|
|
486
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
487
|
+
@message_output.seek 0
|
|
488
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
489
|
+
end
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
context "uses async connection" do
|
|
493
|
+
it 'works fine' do
|
|
494
|
+
VCR.use_cassette("here_now_global-nonssl-block-invalid-200-sync", :record => :none) do
|
|
495
|
+
@pn.here_now(:http_sync => false, :channel => "demo", :callback => @callback)
|
|
496
|
+
|
|
497
|
+
eventually do
|
|
498
|
+
@after_error_callback.should eq true
|
|
499
|
+
@response_output.seek 0
|
|
500
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
501
|
+
@message_output.seek 0
|
|
502
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
503
|
+
end
|
|
504
|
+
end
|
|
505
|
+
end
|
|
506
|
+
end
|
|
507
|
+
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("here_now_global-nonssl-block-invalid-non-200-sync", :record => :none) do
|
|
512
|
+
@pn.here_now(:http_sync => true, :channel => "demo", :callback => @callback)
|
|
513
|
+
|
|
514
|
+
@after_error_callback.should eq true
|
|
515
|
+
@response_output.seek 0
|
|
516
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
517
|
+
@message_output.seek 0
|
|
518
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
519
|
+
end
|
|
520
|
+
end
|
|
521
|
+
end
|
|
522
|
+
context "uses async connection" do
|
|
523
|
+
it 'works fine' do
|
|
524
|
+
VCR.use_cassette("here_now_global-nonssl-block-invalid-non-200-sync", :record => :none) do
|
|
525
|
+
@pn.here_now(:http_sync => false, :channel => "demo", :callback => @callback)
|
|
526
|
+
|
|
527
|
+
eventually do
|
|
528
|
+
@after_error_callback.should eq true
|
|
529
|
+
@response_output.seek 0
|
|
530
|
+
@response_output.read.should eq '{"status": 200, "message": "OK", "service": "Presence", "uuids": [], "occupancy": 0'
|
|
531
|
+
@message_output.seek 0
|
|
532
|
+
@message_output.read.should eq '[0,"Invalid JSON in response."]'
|
|
533
|
+
end
|
|
534
|
+
end
|
|
535
|
+
end
|
|
536
|
+
end
|
|
537
|
+
end
|
|
538
|
+
end
|
|
539
|
+
end
|
|
540
|
+
end
|
|
541
|
+
end
|