pusher-fake 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39d56e9bb6902ed10adbe4bca8166649d40749fc
4
- data.tar.gz: 5a8e70714a86266a036d0a56c31564fbf8972dd2
3
+ metadata.gz: d4567bf9d8226e1d07e7f93382ae2f414a62888e
4
+ data.tar.gz: 8524195e9f243534d9a85b3d7c0a09c61c4fc252
5
5
  SHA512:
6
- metadata.gz: 31ab418c7631fb803180cef6bca7eddac1ba06b5dc64be52cd35033412404b6e328cf631c962e11a1a8fe8f5a613dc7fa80d834004b2a0df6f3d4ea0eb62149e
7
- data.tar.gz: bac0c88bd45616f6dc8ef8a829d2fe4682be67879778c95786aca8cc77e4175679c578bbf958b13cf64e064fc059a4a7ac56d4c55963f10ee014997b7141f22d
6
+ metadata.gz: 90f3394b3891466ed3dd2b5c4dab7a6fba6d437608a7d8b4bf96702584b829a14fdb2d84ab614cf23dd74fb3fb118789f616326e259bae52ba07bff3302dfb6e
7
+ data.tar.gz: e67ed85fd2a1bec93104ab4102ca148b8d295f51056babd2a8b5c13e4396b80ab53663ad66567b21f2a83d2136e8709d44142a3b7e5df86f5d6d773f110fdb11
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Pusher JavaScript Library v2.1.2
2
+ * Pusher JavaScript Library v2.1.3
3
3
  * http://pusherapp.com/
4
4
  *
5
5
  * Copyright 2013, Pusher
@@ -509,7 +509,7 @@
509
509
  }).call(this);
510
510
 
511
511
  ;(function() {
512
- Pusher.VERSION = '2.1.2';
512
+ Pusher.VERSION = '2.1.3';
513
513
  Pusher.PROTOCOL = 6;
514
514
 
515
515
  // DEPRECATED: WS connection parameters
@@ -622,6 +622,7 @@
622
622
 
623
623
  /** Error classes used throughout pusher-js library. */
624
624
  Pusher.Errors = {
625
+ BadEventName: buildExceptionClass("BadEventName"),
625
626
  UnsupportedTransport: buildExceptionClass("UnsupportedTransport"),
626
627
  UnsupportedStrategy: buildExceptionClass("UnsupportedStrategy"),
627
628
  TransportPriorityTooLow: buildExceptionClass("TransportPriorityTooLow"),
@@ -1169,21 +1170,25 @@
1169
1170
  prototype.send = function(sendJSONP, callback) {
1170
1171
  var self = this;
1171
1172
 
1173
+ if (Pusher.Network.isOnline() === false) {
1174
+ return false;
1175
+ }
1176
+
1172
1177
  var data = {};
1173
- if (this.sent === 0) {
1178
+ if (self.sent === 0) {
1174
1179
  data = Pusher.Util.extend({
1175
- key: this.key,
1176
- features: this.options.features,
1177
- version: this.options.version
1178
- }, this.options.params || {});
1180
+ key: self.key,
1181
+ features: self.options.features,
1182
+ version: self.options.version
1183
+ }, self.options.params || {});
1179
1184
  }
1180
- data.session = this.session;
1181
- data.timeline = this.events;
1185
+ data.session = self.session;
1186
+ data.timeline = self.events;
1182
1187
  data = Pusher.Util.filterObject(data, function(v) {
1183
1188
  return v !== undefined;
1184
1189
  });
1185
1190
 
1186
- this.events = [];
1191
+ self.events = [];
1187
1192
  sendJSONP(data, function(error, result) {
1188
1193
  if (!error) {
1189
1194
  self.sent++;
@@ -1226,7 +1231,7 @@
1226
1231
  receiver: Pusher.JSONP
1227
1232
  };
1228
1233
  return Pusher.JSONPRequest.send(params, function(error, result) {
1229
- if (result.host) {
1234
+ if (result && result.host) {
1230
1235
  self.host = result.host;
1231
1236
  }
1232
1237
  if (callback) {
@@ -1385,9 +1390,13 @@
1385
1390
  function fetchTransportInfo() {
1386
1391
  var storage = Pusher.Util.getLocalStorage();
1387
1392
  if (storage) {
1388
- var info = storage.pusherTransport;
1389
- if (info) {
1390
- return JSON.parse(storage.pusherTransport);
1393
+ try {
1394
+ var info = storage.pusherTransport;
1395
+ if (info) {
1396
+ return JSON.parse(info);
1397
+ }
1398
+ } catch (e) {
1399
+ flushTransportInfo();
1391
1400
  }
1392
1401
  }
1393
1402
  return null;
@@ -1402,7 +1411,7 @@
1402
1411
  transport: transport,
1403
1412
  latency: latency
1404
1413
  });
1405
- } catch(e) {
1414
+ } catch (e) {
1406
1415
  // catch over quota exceptions raised by localStorage
1407
1416
  }
1408
1417
  }
@@ -1413,7 +1422,7 @@
1413
1422
  if (storage && storage.pusherTransport) {
1414
1423
  try {
1415
1424
  delete storage.pusherTransport;
1416
- } catch(e) {
1425
+ } catch (e) {
1417
1426
  storage.pusherTransport = undefined;
1418
1427
  }
1419
1428
  }
@@ -3361,6 +3370,11 @@
3361
3370
 
3362
3371
  /** Triggers an event */
3363
3372
  prototype.trigger = function(event, data) {
3373
+ if (event.indexOf("client-") !== 0) {
3374
+ throw new Pusher.Errors.BadEventName(
3375
+ "Event '" + event + "' does not start with 'client-'"
3376
+ );
3377
+ }
3364
3378
  return this.pusher.send_event(event, data, this.name);
3365
3379
  };
3366
3380
 
@@ -13,16 +13,13 @@
13
13
  <ul></ul>
14
14
  </section>
15
15
 
16
- <script src="/javascripts/vendor/pusher-2.1.2.js"></script>
16
+ <script src="/javascripts/vendor/pusher-2.1.3.js"></script>
17
17
  <script>
18
18
  window.addEventListener("DOMContentLoaded", function() {
19
19
  // Create the client instance using the PusherFake server.
20
20
  Pusher.instance = <%= PusherFake.javascript %>;
21
21
  Pusher.instance.events = {};
22
22
 
23
- // Force the connection to go unavailable after a single attempt.
24
- Pusher.instance.connection.connectionAttempts = 4;
25
-
26
23
  // Record all events.
27
24
  Pusher.instance.connection.bind("message", function(message) {
28
25
  var events = Pusher.instance.events,
data/lib/pusher-fake.rb CHANGED
@@ -16,7 +16,7 @@ require "pusher-fake/webhook"
16
16
 
17
17
  module PusherFake
18
18
  # The current version string.
19
- VERSION = "0.10.0"
19
+ VERSION = "0.11.0"
20
20
 
21
21
  # Call this method to modify the defaults.
22
22
  #
@@ -9,31 +9,68 @@ module PusherFake
9
9
  # @return [String] The Pusher API token. (Defaults to +PUSHER_API_SECRET+.)
10
10
  attr_accessor :secret
11
11
 
12
- # @return [String] The host on which the socket server listens. (Defaults to +127.0.0.1+.)
13
- attr_accessor :socket_host
14
-
15
- # @return [Fixnum] The port on which the socket server listens. (Defaults to +8080+.)
16
- attr_accessor :socket_port
17
-
18
- # @return [String] The host on which the web server listens. (Defaults to +127.0.0.1+.)
19
- attr_accessor :web_host
12
+ # Options for the socket server. See +EventMachine::WebSocket.start+ for options.
13
+ #
14
+ # @return [Hash] Options for the socket server.
15
+ attr_accessor :socket_options
20
16
 
21
- # @return [Fixnum] The port on which the web server listens. (Defaults to +8081+.)
22
- attr_accessor :web_port
17
+ # Options for the web server. See +Thin::Server+ for options.
18
+ #
19
+ # @return [Hash] Options for the web server.
20
+ attr_accessor :web_options
23
21
 
24
22
  # @return [Array] An array of webhook URLs. (Defaults to +[]+.)
25
23
  attr_accessor :webhooks
26
24
 
27
25
  # Instantiated from {PusherFake.configuration}. Sets the defaults.
28
26
  def initialize
29
- self.app_id = "PUSHER_APP_ID"
30
- self.key = "PUSHER_API_KEY"
31
- self.secret = "PUSHER_API_SECRET"
32
- self.socket_host = "127.0.0.1"
33
- self.socket_port = 8080
34
- self.web_host = "127.0.0.1"
35
- self.web_port = 8081
36
- self.webhooks = []
27
+ self.app_id = "PUSHER_APP_ID"
28
+ self.key = "PUSHER_API_KEY"
29
+ self.secret = "PUSHER_API_SECRET"
30
+ self.webhooks = []
31
+
32
+ self.socket_options = { host: "127.0.0.1", port: 8080 }
33
+ self.web_options = { host: "127.0.0.1", port: 8081 }
34
+ end
35
+
36
+ # Set the host on which the socket server listens.
37
+ #
38
+ # @deprecated Please use {#socket_options} +Hash+ instead.
39
+ # @param host String
40
+ def socket_host=(host)
41
+ warn "[DEPRECATION] `socket_host=` is deprecated. Please use `socket_options=` instead."
42
+
43
+ socket_options[:host] = host
44
+ end
45
+
46
+ # Set the port on which the socket server listens.
47
+ #
48
+ # @deprecated Please use {#socket_options} +Hash+ instead.
49
+ # @param port Integer
50
+ def socket_port=(port)
51
+ warn "[DEPRECATION] `socket_port=` is deprecated. Please use `socket_options=` instead."
52
+
53
+ socket_options[:port] = port
54
+ end
55
+
56
+ # Set the host on which the web server listens.
57
+ #
58
+ # @deprecated Please use {#web_options} +Hash+ instead.
59
+ # @param host String
60
+ def web_host=(host)
61
+ warn "[DEPRECATION] `web_host=` is deprecated. Please use `web_options=` instead."
62
+
63
+ web_options[:host] = host
64
+ end
65
+
66
+ # Set the port on which the web server listens.
67
+ #
68
+ # @deprecated Please use {#web_options} +Hash+ instead.
69
+ # @param port Integer
70
+ def web_port=(port)
71
+ warn "[DEPRECATION] `web_port=` is deprecated. Please use `web_options=` instead."
72
+
73
+ web_options[:port] = port
37
74
  end
38
75
 
39
76
  # Convert the configuration to a hash sutiable for Pusher JS options.
@@ -41,8 +78,8 @@ module PusherFake
41
78
  # @param [Hash] options Custom options for Pusher client.
42
79
  def to_options(options = {})
43
80
  options.merge({
44
- wsHost: socket_host,
45
- wsPort: socket_port
81
+ wsHost: socket_options[:host],
82
+ wsPort: socket_options[:port]
46
83
  })
47
84
  end
48
85
  end
@@ -6,8 +6,10 @@ PusherFake.configure do |configuration|
6
6
  end
7
7
 
8
8
  # Set the host and port to the fake web server.
9
- Pusher.host = PusherFake.configuration.web_host
10
- Pusher.port = PusherFake.configuration.web_port
9
+ PusherFake.configuration.web_options.tap do |options|
10
+ Pusher.host = options[:host]
11
+ Pusher.port = options[:port]
12
+ end
11
13
 
12
14
  # Start the fake web server.
13
15
  fork { PusherFake::Server.start }.tap do |id|
@@ -13,7 +13,7 @@ module PusherFake
13
13
 
14
14
  # Start the WebSocket server.
15
15
  def self.start_socket_server
16
- EventMachine::WebSocket.start(socket_server_options) do |socket|
16
+ EventMachine::WebSocket.start(configuration.socket_options) do |socket|
17
17
  socket.onopen do
18
18
  connection = Connection.new(socket)
19
19
  connection.establish
@@ -30,8 +30,16 @@ module PusherFake
30
30
 
31
31
  # Start the web server.
32
32
  def self.start_web_server
33
+ options = configuration.web_options.dup
34
+
33
35
  Thin::Logging.silent = true
34
- Thin::Server.start(configuration.web_host, configuration.web_port, Application)
36
+ Thin::Server.new(options.delete(:host), options.delete(:port), Application).tap do |server|
37
+ options.each do |key, value|
38
+ server.__send__("#{key}=", value)
39
+ end
40
+
41
+ server.start!
42
+ end
35
43
  end
36
44
 
37
45
  private
@@ -4,20 +4,58 @@ describe PusherFake::Configuration do
4
4
  it { should have_configuration_option(:app_id).with_default("PUSHER_APP_ID") }
5
5
  it { should have_configuration_option(:key).with_default("PUSHER_API_KEY") }
6
6
  it { should have_configuration_option(:secret).with_default("PUSHER_API_SECRET") }
7
- it { should have_configuration_option(:socket_host).with_default("127.0.0.1") }
8
- it { should have_configuration_option(:socket_port).with_default(8080) }
9
- it { should have_configuration_option(:web_host).with_default("127.0.0.1") }
10
- it { should have_configuration_option(:web_port).with_default(8081) }
7
+ it { should have_configuration_option(:socket_options).with_default({ host: "127.0.0.1", port: 8080 }) }
8
+ it { should have_configuration_option(:web_options).with_default({ host: "127.0.0.1", port: 8081 }) }
11
9
  it { should have_configuration_option(:webhooks).with_default([]) }
12
10
  end
13
11
 
12
+ describe PusherFake::Configuration, "#socket_host=" do
13
+ it "sets socket options host value" do
14
+ silence_warnings do
15
+ subject.socket_host = "192.168.0.1"
16
+ end
17
+
18
+ subject.socket_options[:host].should == "192.168.0.1"
19
+ end
20
+ end
21
+
22
+ describe PusherFake::Configuration, "#socket_post=" do
23
+ it "sets socket options host value" do
24
+ silence_warnings do
25
+ subject.socket_port = 443
26
+ end
27
+
28
+ subject.socket_options[:port].should == 443
29
+ end
30
+ end
31
+
32
+ describe PusherFake::Configuration, "#web_host=" do
33
+ it "sets web options host value" do
34
+ silence_warnings do
35
+ subject.web_host = "192.168.0.1"
36
+ end
37
+
38
+ subject.web_options[:host].should == "192.168.0.1"
39
+ end
40
+ end
41
+
42
+ describe PusherFake::Configuration, "#web_post=" do
43
+ it "sets web options host value" do
44
+ silence_warnings do
45
+ subject.web_port = 443
46
+ end
47
+
48
+ subject.web_options[:port].should == 443
49
+ end
50
+ end
51
+
14
52
  describe PusherFake::Configuration, "#to_options" do
15
53
  it "includes the socket host as wsHost" do
16
- subject.to_options.should include(wsHost: subject.socket_host)
54
+ subject.to_options.should include(wsHost: subject.socket_options[:host])
17
55
  end
18
56
 
19
57
  it "includes the socket port as wsPort" do
20
- subject.to_options.should include(wsPort: subject.socket_port)
58
+ subject.to_options.should include(wsPort: subject.socket_options[:port])
21
59
  end
22
60
 
23
61
  it "supports passing custom options" do
@@ -37,9 +37,9 @@ end
37
37
  describe PusherFake::Server, ".start_socket_server" do
38
38
  let(:data) { stub }
39
39
  let(:socket) { stub(onopen: nil, onmessage: nil, onclose: nil) }
40
- let(:options) { { host: configuration.socket_host, port: configuration.socket_port } }
40
+ let(:options) { configuration.socket_options }
41
41
  let(:connection) { stub(establish: nil, process: nil) }
42
- let(:configuration) { stub(socket_host: "192.168.0.1", socket_port: 8080) }
42
+ let(:configuration) { stub(socket_options: { host: "192.168.0.1", port: 8080 }) }
43
43
 
44
44
  subject { PusherFake::Server }
45
45
 
@@ -128,12 +128,13 @@ end
128
128
  describe PusherFake::Server, ".start_web_server" do
129
129
  let(:host) { "192.168.0.1" }
130
130
  let(:port) { 8081 }
131
- let(:configuration) { stub(web_host: host, web_port: port) }
131
+ let(:server) { stub(:start! => true, :ssl= => true) }
132
+ let(:configuration) { stub(web_options: { host: host, port: port, ssl: true }) }
132
133
 
133
134
  subject { PusherFake::Server }
134
135
 
135
136
  before do
136
- Thin::Server.stubs(:start)
137
+ Thin::Server.stubs(new: server)
137
138
  Thin::Logging.stubs(:silent=)
138
139
  PusherFake.stubs(configuration: configuration)
139
140
  end
@@ -143,8 +144,18 @@ describe PusherFake::Server, ".start_web_server" do
143
144
  Thin::Logging.should have_received(:silent=).with(true)
144
145
  end
145
146
 
147
+ it "creates the web server" do
148
+ subject.start_web_server
149
+ Thin::Server.should have_received(:new).with(host, port, PusherFake::Server::Application)
150
+ end
151
+
152
+ it "assigns custom options to the server" do
153
+ subject.start_web_server
154
+ server.should have_received(:ssl=).with(true)
155
+ end
156
+
146
157
  it "starts the web server" do
147
158
  subject.start_web_server
148
- Thin::Server.should have_received(:start).with(host, port, PusherFake::Server::Application)
159
+ server.should have_received(:start!).with()
149
160
  end
150
161
  end
@@ -7,7 +7,19 @@ module BartenderHelper
7
7
  def matches?(configuration)
8
8
  @configuration = configuration
9
9
  @configuration.respond_to?(@option).should == true
10
- @configuration.__send__(@option).should == @default if instance_variables.include?("@default")
10
+
11
+ if instance_variables.include?(:@default)
12
+ actual = @configuration.__send__(@option)
13
+
14
+ if @default.is_a?(Hash)
15
+ @default.each do |key, value|
16
+ actual[key].should == value
17
+ end
18
+ else
19
+ actual.should == @default
20
+ end
21
+ end
22
+
11
23
  @configuration.__send__(:"#{@option}=", "value")
12
24
  @configuration.__send__(@option).should == "value"
13
25
  end
@@ -0,0 +1,8 @@
1
+ module Kernel
2
+ def silence_warnings
3
+ old_verbose, $VERBOSE = $VERBOSE, nil
4
+ yield
5
+ ensure
6
+ $VERBOSE = old_verbose
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher-fake
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Dunn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-27 00:00:00.000000000 Z
11
+ date: 2013-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request
@@ -100,28 +100,28 @@ dependencies:
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.6.7
103
+ version: 0.7.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 0.6.7
110
+ version: 0.7.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: cucumber
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 1.3.6
117
+ version: 1.3.8
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 1.3.6
124
+ version: 1.3.8
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: pusher
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -184,28 +184,28 @@ dependencies:
184
184
  requirements:
185
185
  - - '='
186
186
  - !ruby/object:Gem::Version
187
- version: 1.4.3
187
+ version: 1.4.4
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - '='
193
193
  - !ruby/object:Gem::Version
194
- version: 1.4.3
194
+ version: 1.4.4
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: yard
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - '='
200
200
  - !ruby/object:Gem::Version
201
- version: 0.8.7
201
+ version: 0.8.7.2
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - '='
207
207
  - !ruby/object:Gem::Version
208
- version: 0.8.7
208
+ version: 0.8.7.2
209
209
  description: A fake Pusher server for development and testing.
210
210
  email: hello@tristandunn.com
211
211
  executables: []
@@ -236,7 +236,7 @@ files:
236
236
  - features/step_definitions/navigation_steps.rb
237
237
  - features/step_definitions/presence_steps.rb
238
238
  - features/step_definitions/webhook_steps.rb
239
- - features/support/application/public/javascripts/vendor/pusher-2.1.2.js
239
+ - features/support/application/public/javascripts/vendor/pusher-2.1.3.js
240
240
  - features/support/application/views/index.erb
241
241
  - features/support/application.rb
242
242
  - features/support/coveralls.rb
@@ -258,6 +258,7 @@ files:
258
258
  - spec/spec_helper.rb
259
259
  - spec/support/coveralls.rb
260
260
  - spec/support/have_configuration_option_matcher.rb
261
+ - spec/support/warnings.rb
261
262
  homepage: https://github.com/tristandunn/pusher-fake
262
263
  licenses:
263
264
  - MIT
@@ -296,7 +297,7 @@ test_files:
296
297
  - features/step_definitions/navigation_steps.rb
297
298
  - features/step_definitions/presence_steps.rb
298
299
  - features/step_definitions/webhook_steps.rb
299
- - features/support/application/public/javascripts/vendor/pusher-2.1.2.js
300
+ - features/support/application/public/javascripts/vendor/pusher-2.1.3.js
300
301
  - features/support/application/views/index.erb
301
302
  - features/support/application.rb
302
303
  - features/support/coveralls.rb
@@ -318,4 +319,5 @@ test_files:
318
319
  - spec/spec_helper.rb
319
320
  - spec/support/coveralls.rb
320
321
  - spec/support/have_configuration_option_matcher.rb
322
+ - spec/support/warnings.rb
321
323
  has_rdoc: