pubnub 4.0.19 → 4.0.20
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pubnub might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.pubnub.yml +30 -1
- data/.rubocop.yml +4 -1
- data/.travis.yml +7 -8
- data/Gemfile +1 -1
- data/README.md +2 -1
- data/VERSION +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/1.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/101.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/103.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/105.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/107.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/109.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/11.yml +4 -4
- data/fixtures/vcr_cassettes/examples/subscribe/111.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/113.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/115.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/117.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/119.yml +2 -2
- data/fixtures/vcr_cassettes/examples/subscribe/121.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/123.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/125.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/127.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/129.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/13.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/131.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/133.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/135.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/137.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/139.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/141.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/143.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/145.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/147.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/149.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/15.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/151.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/153.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/155.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/157.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/159.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/161.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/163.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/165.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/167.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/169.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/17.yml +3 -3
- data/fixtures/vcr_cassettes/examples/subscribe/171.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/173.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/175.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/177.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/179.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/181.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/183.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/185.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/187.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/189.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/19.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/191.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/193.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/195.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/197.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/199.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/201.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/203.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/205.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/207.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/209.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/21.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/211.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/213.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/215.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/217.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/219.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/221.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/223.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/225.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/227.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/229.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/23.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/231.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/233.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/235.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/237.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/239.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/241.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/243.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/245.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/247.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/249.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/25.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/251.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/253.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/255.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/257.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/259.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/261.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/263.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/265.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/267.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/269.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/27.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/271.yml +2 -2
- data/fixtures/vcr_cassettes/examples/subscribe/273.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/275.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/277.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/279.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/281.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/283.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/285.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/287.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/289.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/29.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/291.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/293.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/295.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/297.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/299.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/3.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/301.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/303.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/305.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/307.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/309.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/31.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/311.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/313.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/315.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/317.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/319.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/321.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/323.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/325.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/327.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/329.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/33.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/331.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/333.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/335.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/337.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/339.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/341.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/343.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/345.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/347.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/349.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/35.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/351.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/353.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/355.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/357.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/359.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/361.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/363.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/365.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/367.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/369.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/37.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/371.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/379.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/381.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/383.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/385.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/387.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/389.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/39.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/397.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/399.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/401.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/403.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/405.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/407.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/41.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/415.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/417.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/419.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/421.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/423.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/425.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/43.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/433.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/435.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/437.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/439.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/441.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/443.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/45.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/47.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/49.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/5.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/51.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/53.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/55.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/57.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/59.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/61.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/63.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/65.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/67.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/69.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/7.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/71.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/73.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/75.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/77.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/79.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/81.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/83.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/85.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/87.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/89.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/9.yml +2 -2
- data/fixtures/vcr_cassettes/examples/subscribe/91.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/93.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/95.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/97.yml +1 -1
- data/fixtures/vcr_cassettes/examples/subscribe/99.yml +1 -1
- data/fixtures/vcr_cassettes/lib/callable_cipher_key.yml +78 -0
- data/fixtures/vcr_cassettes/lib/events/heartbeat-sub.yml +46 -3
- data/fixtures/vcr_cassettes/lib/events/presence_delta.yml +193 -0
- data/fixtures/vcr_cassettes/lib/multiple_ciphers.yml +188 -0
- data/fixtures/vcr_cassettes/lib/multiple_ciphers_history.yml +163 -0
- data/lib/pubnub/client/getters_setters.rb +127 -0
- data/lib/pubnub/client.rb +3 -112
- data/lib/pubnub/configuration.rb +1 -1
- data/lib/pubnub/constants.rb +5 -2
- data/lib/pubnub/crypto.rb +5 -5
- data/lib/pubnub/event/formatter.rb +45 -0
- data/lib/pubnub/event/signature.rb +41 -0
- data/lib/pubnub/event.rb +41 -97
- data/lib/pubnub/events/history.rb +4 -3
- data/lib/pubnub/events/publish.rb +37 -37
- data/lib/pubnub/formatter.rb +1 -1
- data/lib/pubnub/pam.rb +9 -9
- data/lib/pubnub/single_event.rb +1 -1
- data/lib/pubnub/subscribe_event/formatter.rb +4 -4
- data/lib/pubnub/subscriber.rb +28 -28
- data/lib/pubnub/validators/client.rb +1 -1
- data/lib/pubnub/validators/common_validator.rb +2 -2
- data/lib/pubnub/version.rb +1 -1
- data/pubnub.gemspec +0 -2
- data/spec/examples/presence_examples_spec.rb +2 -1
- data/spec/examples/subscribe_examples_spec.rb +1080 -1080
- data/spec/lib/client_spec.rb +5 -5
- data/spec/lib/events/presence_delta_spec.rb +38 -0
- data/spec/lib/multiple_ciphers_spec.rb +145 -0
- data/spec/spec_helper.rb +2 -2
- metadata +15 -7
@@ -0,0 +1,45 @@
|
|
1
|
+
# Toplevel Pubnub module.
|
2
|
+
module Pubnub
|
3
|
+
# Event class lib/pubnub/event.rb
|
4
|
+
class Event
|
5
|
+
# Module that holds formatters for events
|
6
|
+
module EFormatter
|
7
|
+
def format_envelopes(response, request)
|
8
|
+
if response.is_a? HTTPClient::ReceiveTimeoutError
|
9
|
+
return error_envelope(nil, response, request: request, response: response)
|
10
|
+
elsif response.is_a? OpenSSL::SSL::SSLError
|
11
|
+
return error_envelope(nil, response, request: request, response: response)
|
12
|
+
else
|
13
|
+
parsed_response, error = Formatter.parse_json(response.body)
|
14
|
+
end
|
15
|
+
|
16
|
+
error = response if parsed_response && response.code.to_i != 200
|
17
|
+
|
18
|
+
if error
|
19
|
+
error_envelope(parsed_response, error, request: request, response: response)
|
20
|
+
else
|
21
|
+
valid_envelope(parsed_response, request: request, response: response)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def format_channels
|
26
|
+
@channel = Formatter.format_channel(@channel || @channels)
|
27
|
+
@channel += Formatter.format_presence_channel(@presence)
|
28
|
+
@channel += Formatter.format_presence_channel(@channel || @channels) if @with_presence
|
29
|
+
@wildcard_channel = @channel.select { |e| e.index('.*') } || []
|
30
|
+
end
|
31
|
+
|
32
|
+
def format_group
|
33
|
+
@group = (@channel_group || @channel_groups) if (@channel_group || @channel_groups) && @group.blank?
|
34
|
+
@group = Formatter.format_group(@group)
|
35
|
+
|
36
|
+
if @group.first.to_s.count(':') > 0
|
37
|
+
@namespace_id, @group_id = @group.first.to_s.split(':')
|
38
|
+
else
|
39
|
+
@namespace_id = nil
|
40
|
+
@group_id = @group.first.to_s
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Toplevel Pubnub module.
|
2
|
+
module Pubnub
|
3
|
+
# Event class lib/pubnub/event.rb
|
4
|
+
class Event
|
5
|
+
# Module that holds signature computing code
|
6
|
+
module Signature
|
7
|
+
private
|
8
|
+
|
9
|
+
def super_admin_signature
|
10
|
+
return unless @app.env[:secret_key]
|
11
|
+
|
12
|
+
message = [
|
13
|
+
@app.env[:subscribe_key],
|
14
|
+
@app.env[:publish_key],
|
15
|
+
path,
|
16
|
+
variables_for_signature
|
17
|
+
].join("\n")
|
18
|
+
|
19
|
+
message = message.gsub(/[!~*'()]/) { |char| '%' + char.ord.to_s(16).upcase }
|
20
|
+
|
21
|
+
URI.encode_www_form_component(Base64.encode64(
|
22
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'),
|
23
|
+
@app.env[:secret_key].to_s, message)
|
24
|
+
).strip).gsub('+', '%20')
|
25
|
+
end
|
26
|
+
|
27
|
+
def variables_for_signature
|
28
|
+
parameters(true).map do |k, v|
|
29
|
+
if %w(meta ortt).include?(k.to_s)
|
30
|
+
encoded_value = URI.encode_www_form_component(v.to_json).gsub('+', '%20')
|
31
|
+
"#{k}=#{encoded_value}"
|
32
|
+
elsif %w(t state filter-expr).include?(k.to_s)
|
33
|
+
"#{k}=#{v}"
|
34
|
+
else
|
35
|
+
"#{k}=#{URI.encode_www_form_component(v.to_s).gsub('+', '%20')}"
|
36
|
+
end
|
37
|
+
end.sort.join('&')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/pubnub/event.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'pubnub/event/signature'
|
2
|
+
require 'pubnub/event/formatter'
|
3
|
+
|
1
4
|
# Toplevel Pubnub module.
|
2
5
|
module Pubnub
|
3
6
|
# Event module holds most basic and required infrastructure for every pubnub
|
@@ -11,6 +14,9 @@ module Pubnub
|
|
11
14
|
alias_method :channels, :channel
|
12
15
|
alias_method :channel_groups, :channel_group
|
13
16
|
|
17
|
+
include Signature
|
18
|
+
include EFormatter
|
19
|
+
|
14
20
|
def initialize(options, app)
|
15
21
|
@app = app
|
16
22
|
@given_options = options
|
@@ -74,50 +80,12 @@ module Pubnub
|
|
74
80
|
|
75
81
|
private
|
76
82
|
|
77
|
-
def super_admin_signature
|
78
|
-
return unless @app.env[:secret_key]
|
79
|
-
|
80
|
-
message = [
|
81
|
-
@app.env[:subscribe_key],
|
82
|
-
@app.env[:publish_key],
|
83
|
-
path,
|
84
|
-
variables_for_signature
|
85
|
-
].join("\n")
|
86
|
-
|
87
|
-
message = message.gsub(/[!~*'()]/) { |char| '%' + char.ord.to_s(16).upcase }
|
88
|
-
|
89
|
-
URI.encode_www_form_component(Base64.encode64(
|
90
|
-
OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'),
|
91
|
-
@app.env[:secret_key].to_s, message)
|
92
|
-
).strip).gsub('+', '%20')
|
93
|
-
end
|
94
|
-
|
95
|
-
def variables_for_signature
|
96
|
-
parameters(true).map do |k, v|
|
97
|
-
if %w(meta ortt).include?(k.to_s)
|
98
|
-
encoded_value = URI.encode_www_form_component(v.to_json).gsub('+', '%20')
|
99
|
-
"#{k}=#{encoded_value}"
|
100
|
-
elsif %w(t state filter-expr).include?(k.to_s)
|
101
|
-
"#{k}=#{v}"
|
102
|
-
else
|
103
|
-
"#{k}=#{URI.encode_www_form_component(v.to_s).gsub('+', '%20')}"
|
104
|
-
end
|
105
|
-
end.sort.join('&')
|
106
|
-
end
|
107
|
-
|
108
83
|
def secure_call(cb, arg)
|
109
84
|
cb.call arg
|
110
85
|
rescue => error
|
111
86
|
Pubnub.logger.error('Pubnub::Event') { "Error while calling callback #{error.inspect}" }
|
112
87
|
end
|
113
88
|
|
114
|
-
def format_channels
|
115
|
-
@channel = Formatter.format_channel(@channel || @channels)
|
116
|
-
@channel += Formatter.format_presence_channel(@presence)
|
117
|
-
@channel += Formatter.format_presence_channel(@channel || @channels) if @with_presence
|
118
|
-
@wildcard_channel = @channel.select { |e| e.index('.*') } || []
|
119
|
-
end
|
120
|
-
|
121
89
|
def fire_callbacks(envelope)
|
122
90
|
Pubnub.logger.debug('Pubnub::Event') { "Firing callbacks for #{self.class}" }
|
123
91
|
secure_call @callback, envelope if @callback
|
@@ -134,7 +102,7 @@ module Pubnub
|
|
134
102
|
uuid: @app.env[:uuid]
|
135
103
|
}
|
136
104
|
|
137
|
-
required.merge!(
|
105
|
+
required.merge!(timestamp: @timestamp) if @app.env[:secret_key] && ![:grant, :revoke, :audit].include?(@event)
|
138
106
|
|
139
107
|
empty_if_blank.delete_if { |_k, v| v.blank? }
|
140
108
|
|
@@ -146,24 +114,6 @@ module Pubnub
|
|
146
114
|
@envelopes = format_envelopes response, request
|
147
115
|
end
|
148
116
|
|
149
|
-
def format_envelopes(response, request)
|
150
|
-
if response.is_a? HTTPClient::ReceiveTimeoutError
|
151
|
-
return error_envelope(nil, response, request: request, response: response)
|
152
|
-
elsif response.is_a? OpenSSL::SSL::SSLError
|
153
|
-
return error_envelope(nil, response, request: request, response: response)
|
154
|
-
else
|
155
|
-
parsed_response, error = Formatter.parse_json(response.body)
|
156
|
-
end
|
157
|
-
|
158
|
-
error = response if parsed_response && response.code.to_i != 200
|
159
|
-
|
160
|
-
if error
|
161
|
-
error_envelope(parsed_response, error, request: request, response: response)
|
162
|
-
else
|
163
|
-
valid_envelope(parsed_response, request: request, response: response)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
117
|
def create_variables_from_options(options)
|
168
118
|
variables = %w(channel channels message http_sync callback
|
169
119
|
ssl cipher_key secret_key auth_key
|
@@ -172,7 +122,7 @@ module Pubnub
|
|
172
122
|
group action read write manage ttl presence start
|
173
123
|
end count reverse presence_callback store skip_validate
|
174
124
|
state channel_group channel_groups compressed meta customs include_token
|
175
|
-
replicate with_presence)
|
125
|
+
replicate with_presence cipher_key_selector)
|
176
126
|
|
177
127
|
options = options.each_with_object({}) { |option, obj| obj[option.first.to_sym] = option.last }
|
178
128
|
|
@@ -185,18 +135,6 @@ module Pubnub
|
|
185
135
|
@idle_timeout = options[:s_idle_timeout]
|
186
136
|
end
|
187
137
|
|
188
|
-
def format_group
|
189
|
-
@group = (@channel_group || @channel_groups) if (@channel_group || @channel_groups) && @group.blank?
|
190
|
-
@group = Formatter.format_group(@group)
|
191
|
-
|
192
|
-
if @group.first.to_s.count(':') > 0
|
193
|
-
@namespace_id, @group_id = @group.first.to_s.split(':')
|
194
|
-
else
|
195
|
-
@namespace_id = nil
|
196
|
-
@group_id = @group.first.to_s
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
138
|
def set_timestamp
|
201
139
|
@timestamp = current_time
|
202
140
|
end
|
@@ -210,6 +148,12 @@ module Pubnub
|
|
210
148
|
URI.encode_www_form_component(parameter).gsub('+', '%20')
|
211
149
|
end
|
212
150
|
|
151
|
+
def compute_cipher_key(data)
|
152
|
+
ck = @compute_cipher_key || @cipher_key || @app.env[:cipher_key_selector] || @app.env[:cipher_key].to_s
|
153
|
+
return ck unless ck.respond_to?(:call)
|
154
|
+
ck.call(data)
|
155
|
+
end
|
156
|
+
|
213
157
|
def error_message(parsed_response)
|
214
158
|
parsed_response['message']
|
215
159
|
rescue
|
@@ -227,36 +171,36 @@ module Pubnub
|
|
227
171
|
|
228
172
|
def error_envelope(_parsed_response, error, req_res_objects)
|
229
173
|
case error
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
174
|
+
when JSON::ParserError
|
175
|
+
error_category = Pubnub::Constants::STATUS_NON_JSON_RESPONSE
|
176
|
+
code = req_res_objects[:response].code
|
177
|
+
when HTTPClient::ReceiveTimeoutError
|
178
|
+
error_category = Pubnub::Constants::STATUS_TIMEOUT
|
179
|
+
code = 408
|
180
|
+
when OpenSSL::SSL::SSLError
|
181
|
+
error_category = Pubnub::Constants::SSL_ERROR
|
182
|
+
code = nil
|
183
|
+
else
|
184
|
+
error_category = Pubnub::Constants::STATUS_ERROR
|
185
|
+
code = req_res_objects[:response].code
|
242
186
|
end
|
243
187
|
|
244
188
|
Pubnub::ErrorEnvelope.new(
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
189
|
+
event: @event,
|
190
|
+
event_options: @given_options,
|
191
|
+
timetoken: nil,
|
192
|
+
status: {
|
193
|
+
code: code,
|
194
|
+
operation: current_operation,
|
195
|
+
client_request: req_res_objects[:request],
|
196
|
+
server_response: req_res_objects[:response],
|
197
|
+
data: nil,
|
198
|
+
category: error_category,
|
199
|
+
error: true,
|
200
|
+
auto_retried: false,
|
201
|
+
|
202
|
+
config: get_config
|
203
|
+
}
|
260
204
|
)
|
261
205
|
end
|
262
206
|
end
|
@@ -58,9 +58,10 @@ module Pubnub
|
|
58
58
|
def valid_envelope(parsed_response, req_res_objects)
|
59
59
|
messages = parsed_response[0]
|
60
60
|
|
61
|
-
if @app.env[:cipher_key] && messages
|
62
|
-
|
63
|
-
|
61
|
+
if (@cipher_key || @app.env[:cipher_key] || @cipher_key_selector || @app.env[:cipher_key_selector]) && messages
|
62
|
+
cipher_key = compute_cipher_key(parsed_response)
|
63
|
+
crypto = Crypto.new(cipher_key)
|
64
|
+
messages = messages.map { |message| JSON.parse(crypto.decrypt(message), quirks_mode: true) }
|
64
65
|
end
|
65
66
|
|
66
67
|
start = parsed_response[1]
|
@@ -14,11 +14,11 @@ module Pubnub
|
|
14
14
|
@origination_time_token = @app.generate_ortt
|
15
15
|
|
16
16
|
case @store
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
when false
|
18
|
+
@store = 0
|
19
|
+
@ttl = nil
|
20
|
+
when true
|
21
|
+
@store = 1
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -49,31 +49,31 @@ module Pubnub
|
|
49
49
|
params = super
|
50
50
|
|
51
51
|
empty_if_blank = {
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
store: @store,
|
53
|
+
meta: @meta,
|
54
|
+
ttl: @ttl
|
55
55
|
}
|
56
56
|
|
57
|
-
replication = @replicate == false ? {norep: true} : {}
|
57
|
+
replication = @replicate == false ? { norep: true } : {}
|
58
58
|
|
59
59
|
empty_if_blank.delete_if { |_k, v| v.blank? }
|
60
60
|
|
61
61
|
params = params.merge(empty_if_blank)
|
62
62
|
params = params.merge(replication)
|
63
63
|
params = params.merge(seqn: @sequence_number,
|
64
|
-
ortt: {t: @origination_time_token})
|
64
|
+
ortt: { t: @origination_time_token })
|
65
65
|
params
|
66
66
|
end
|
67
67
|
|
68
68
|
def path
|
69
69
|
rpath = [
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
'publish',
|
71
|
+
@publish_key,
|
72
|
+
@subscribe_key,
|
73
|
+
'0',
|
74
|
+
@channel,
|
75
|
+
'0',
|
76
|
+
Formatter.format_message(@message, @cipher_key)
|
77
77
|
]
|
78
78
|
|
79
79
|
rpath.pop if @compressed
|
@@ -99,26 +99,26 @@ module Pubnub
|
|
99
99
|
|
100
100
|
def valid_envelope(parsed_response, req_res_objects)
|
101
101
|
Pubnub::Envelope.new(
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
102
|
+
event: @event,
|
103
|
+
event_options: @given_options,
|
104
|
+
timetoken: timetoken(parsed_response),
|
105
|
+
status: {
|
106
|
+
code: req_res_objects[:response].code,
|
107
|
+
operation: Pubnub::Constants::OPERATION_PUBLISH,
|
108
|
+
client_request: req_res_objects[:request],
|
109
|
+
server_response: req_res_objects[:response],
|
110
|
+
data: nil,
|
111
|
+
category: Pubnub::Constants::STATUS_ACK,
|
112
|
+
error: false,
|
113
|
+
auto_retried: false,
|
114
|
+
|
115
|
+
current_timetoken: nil,
|
116
|
+
last_timetoken: nil,
|
117
|
+
subscribed_channels: nil,
|
118
|
+
subscribed_channel_groups: nil,
|
119
|
+
|
120
|
+
config: get_config
|
121
|
+
}
|
122
122
|
)
|
123
123
|
end
|
124
124
|
end
|
data/lib/pubnub/formatter.rb
CHANGED
@@ -78,7 +78,7 @@ module Pubnub
|
|
78
78
|
# Formats hash to params string
|
79
79
|
def params_hash_to_url_params(hash)
|
80
80
|
params = ''
|
81
|
-
hash.sort_by { |k,_v| k.to_s}.to_h.each do |key, value|
|
81
|
+
hash.sort_by { |k, _v| k.to_s }.to_h.each do |key, value|
|
82
82
|
if %w(meta ortt).include?(key.to_s)
|
83
83
|
encoded_value = URI.encode_www_form_component(value.to_json).gsub('+', '%20')
|
84
84
|
params << "#{key}=#{encoded_value}&"
|
data/lib/pubnub/pam.rb
CHANGED
@@ -85,15 +85,15 @@ module Pubnub
|
|
85
85
|
|
86
86
|
def error_envelope(parsed_response, error, req_res_objects)
|
87
87
|
case error
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
88
|
+
when JSON::ParserError
|
89
|
+
error_category = Pubnub::Constants::STATUS_NON_JSON_RESPONSE
|
90
|
+
code = req_res_objects[:response].code
|
91
|
+
when HTTPClient::ReceiveTimeoutError
|
92
|
+
error_category = Pubnub::Constants::STATUS_TIMEOUT
|
93
|
+
code = 408
|
94
|
+
else
|
95
|
+
error_category = Pubnub::Constants::STATUS_ERROR
|
96
|
+
code = req_res_objects[:response].code
|
97
97
|
end
|
98
98
|
|
99
99
|
ErrorEnvelope.new(
|
data/lib/pubnub/single_event.rb
CHANGED
@@ -5,7 +5,7 @@ module Pubnub
|
|
5
5
|
private
|
6
6
|
|
7
7
|
def request_dispatcher
|
8
|
-
Pubnub.logger.debug('Pubnub::SingleEvent'){ '#request_dispatcher called' }
|
8
|
+
Pubnub.logger.debug('Pubnub::SingleEvent') { '#request_dispatcher called' }
|
9
9
|
@app.request_dispatcher(@origin, :single_event, @http_sync)
|
10
10
|
end
|
11
11
|
|
@@ -33,16 +33,16 @@ module Pubnub
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def decipher_payload(message)
|
36
|
-
return message[:payload] if message[:channel].end_with?('-pnpres') || @app.env[:cipher_key].nil?
|
37
|
-
|
38
|
-
crypto = Pubnub::Crypto.new(
|
36
|
+
return message[:payload] if message[:channel].end_with?('-pnpres') || (@app.env[:cipher_key].nil? && @cipher_key.nil? && @cipher_key_selector.nil? && @env[:cipher_key_selector].nil?)
|
37
|
+
cipher_key = compute_cipher_key(message.reject { |k, _v| k == :payload })
|
38
|
+
crypto = Pubnub::Crypto.new(cipher_key)
|
39
39
|
JSON.parse(crypto.decrypt(message[:payload]), quirks_mode: true)
|
40
40
|
rescue
|
41
41
|
message[:payload]
|
42
42
|
end
|
43
43
|
|
44
44
|
def build_non_error_envelopes(parsed_response, req_res_objects)
|
45
|
-
Pubnub.logger.debug('Pubnub::SubscribeEvent::Formatter') { 'Formatting non-
|
45
|
+
Pubnub.logger.debug('Pubnub::SubscribeEvent::Formatter') { 'Formatting non-error envelopes' }
|
46
46
|
timetoken = parsed_response['t']
|
47
47
|
messages = expand_messages_keys(parsed_response['m'])
|
48
48
|
|
data/lib/pubnub/subscriber.rb
CHANGED
@@ -153,34 +153,34 @@ module Pubnub
|
|
153
153
|
)
|
154
154
|
when Pubnub::Constants::STATUS_REQUEST_MESSAGE_COUNT_EXCEEDED
|
155
155
|
envelope = Pubnub::Envelope.new(
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
156
|
+
event: event,
|
157
|
+
event_options: given_options,
|
158
|
+
timetoken: nil,
|
159
|
+
status: {
|
160
|
+
code: nil,
|
161
|
+
client_request: request,
|
162
|
+
server_response: nil,
|
163
|
+
data: nil,
|
164
|
+
category: Pubnub::Constants::STATUS_REQUEST_MESSAGE_COUNT_EXCEEDED,
|
165
|
+
error: false,
|
166
|
+
auto_retried: true,
|
167
|
+
|
168
|
+
current_timetoken: @app.env[:timetoken].to_i,
|
169
|
+
last_timetoken: @app.env[:timetoken].to_i,
|
170
|
+
subscribed_channels: @app.subscribed_channels,
|
171
|
+
subscribed_channel_groups: @app.subscribed_groups,
|
172
|
+
|
173
|
+
config: get_config
|
174
|
+
|
175
|
+
},
|
176
|
+
result: {
|
177
|
+
code: nil,
|
178
|
+
operation: nil,
|
179
|
+
client_request: request,
|
180
|
+
server_response: nil,
|
181
|
+
|
182
|
+
data: nil
|
183
|
+
}
|
184
184
|
)
|
185
185
|
else
|
186
186
|
Pubnub.logger.warn('Unknown announcement type.')
|
@@ -7,7 +7,7 @@ module Pubnub
|
|
7
7
|
class << self
|
8
8
|
include CommonValidator
|
9
9
|
def validate!(parameters)
|
10
|
-
validate_origin parameters[:
|
10
|
+
validate_origin parameters[:origin], true
|
11
11
|
validate_subscribe_key parameters[:subscribe_key], true
|
12
12
|
validate_publish_key parameters[:publish_key]
|
13
13
|
end
|
@@ -14,8 +14,8 @@ module Pubnub
|
|
14
14
|
fail(
|
15
15
|
InitializationError.new,
|
16
16
|
'origins_pool parameter is not valid. \
|
17
|
-
Should be type of
|
18
|
-
) unless origin.is_a?(
|
17
|
+
Should be type of String.'
|
18
|
+
) unless origin.is_a?(String) || origin.blank?
|
19
19
|
end
|
20
20
|
|
21
21
|
# Validates given subscribe key
|
data/lib/pubnub/version.rb
CHANGED
data/pubnub.gemspec
CHANGED
@@ -13,8 +13,6 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = 'http://github.com/pubnub/ruby'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.post_install_message = %(-----\nUPGRADE NOTICE: Pubnub 3.8.0 and higher versions are using Celluloid instead of EventMachine for asynchronous processing.\n-----)
|
17
|
-
|
18
16
|
spec.files = `git ls-files -z`.split("\x0")
|
19
17
|
spec.executables = spec.files.grep(%r{^bin\/}) { |f| File.basename(f) }
|
20
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)\/})
|
@@ -12,7 +12,8 @@ describe Pubnub::Presence do
|
|
12
12
|
publish_key: 'pub-c-b42cec2f-f468-4784-8833-dd2b074538c4',
|
13
13
|
subscribe_key: 'sub-c-b7fb805a-1777-11e6-be83-0619f8945a4f',
|
14
14
|
uuid: 'ruby-test-uuid-client-one',
|
15
|
-
auth_key: 'ruby-test-auth-client-one'
|
15
|
+
auth_key: 'ruby-test-auth-client-one',
|
16
|
+
reconnect_interval: 0
|
16
17
|
)
|
17
18
|
|
18
19
|
Celluloid.boot
|