ably-rest 1.1.2 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -1
  3. data/MAINTAINERS.md +1 -0
  4. data/README.md +1 -1
  5. data/ably-rest.gemspec +3 -1
  6. data/lib/submodules/ably-ruby/.github/workflows/check.yml +27 -0
  7. data/lib/submodules/ably-ruby/CHANGELOG.md +67 -0
  8. data/lib/submodules/ably-ruby/COPYRIGHT +1 -0
  9. data/lib/submodules/ably-ruby/LICENSE +172 -11
  10. data/lib/submodules/ably-ruby/MAINTAINERS.md +1 -0
  11. data/lib/submodules/ably-ruby/README.md +11 -21
  12. data/lib/submodules/ably-ruby/SPEC.md +1020 -922
  13. data/lib/submodules/ably-ruby/ably.gemspec +4 -4
  14. data/lib/submodules/ably-ruby/lib/ably/auth.rb +12 -2
  15. data/lib/submodules/ably-ruby/lib/ably/exceptions.rb +2 -2
  16. data/lib/submodules/ably-ruby/lib/ably/modules/ably.rb +11 -1
  17. data/lib/submodules/ably-ruby/lib/ably/realtime/channel.rb +7 -11
  18. data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb +2 -2
  19. data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_properties.rb +24 -0
  20. data/lib/submodules/ably-ruby/lib/ably/realtime/client.rb +9 -0
  21. data/lib/submodules/ably-ruby/lib/ably/realtime/connection.rb +5 -4
  22. data/lib/submodules/ably-ruby/lib/ably/realtime/connection/websocket_transport.rb +67 -1
  23. data/lib/submodules/ably-ruby/lib/ably/realtime/presence.rb +0 -14
  24. data/lib/submodules/ably-ruby/lib/ably/rest/channel.rb +27 -19
  25. data/lib/submodules/ably-ruby/lib/ably/rest/client.rb +31 -15
  26. data/lib/submodules/ably-ruby/lib/ably/rest/middleware/fail_if_unsupported_mime_type.rb +4 -1
  27. data/lib/submodules/ably-ruby/lib/ably/version.rb +1 -1
  28. data/lib/submodules/ably-ruby/spec/acceptance/realtime/auth_spec.rb +3 -3
  29. data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_spec.rb +10 -0
  30. data/lib/submodules/ably-ruby/spec/acceptance/realtime/client_spec.rb +72 -16
  31. data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_failures_spec.rb +26 -11
  32. data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_spec.rb +36 -17
  33. data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_history_spec.rb +0 -58
  34. data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb +54 -0
  35. data/lib/submodules/ably-ruby/spec/acceptance/realtime/push_admin_spec.rb +3 -19
  36. data/lib/submodules/ably-ruby/spec/acceptance/rest/auth_spec.rb +6 -75
  37. data/lib/submodules/ably-ruby/spec/acceptance/rest/base_spec.rb +8 -4
  38. data/lib/submodules/ably-ruby/spec/acceptance/rest/channel_spec.rb +42 -4
  39. data/lib/submodules/ably-ruby/spec/acceptance/rest/client_spec.rb +121 -26
  40. data/lib/submodules/ably-ruby/spec/acceptance/rest/push_admin_spec.rb +3 -19
  41. data/lib/submodules/ably-ruby/spec/shared/client_initializer_behaviour.rb +131 -8
  42. data/lib/submodules/ably-ruby/spec/spec_helper.rb +1 -0
  43. data/lib/submodules/ably-ruby/spec/support/serialization_helper.rb +21 -0
  44. data/lib/submodules/ably-ruby/spec/support/test_app.rb +2 -2
  45. data/lib/submodules/ably-ruby/spec/unit/realtime/client_spec.rb +19 -6
  46. data/spec/spec_helper.rb +5 -0
  47. metadata +41 -8
  48. data/lib/submodules/ably-ruby/.travis.yml +0 -19
@@ -89,31 +89,15 @@ describe Ably::Rest::Push::Admin do
89
89
  end
90
90
  end
91
91
 
92
- def request_body(request, protocol)
93
- if protocol == :msgpack
94
- MessagePack.unpack(request.body)
95
- else
96
- JSON.parse(request.body)
97
- end
98
- end
99
-
100
- def serialize(object, protocol)
101
- if protocol == :msgpack
102
- MessagePack.pack(object)
103
- else
104
- JSON.dump(object)
105
- end
106
- end
107
-
108
92
  let!(:publish_stub) do
109
93
  stub_request(:post, "#{client.endpoint}/push/publish").
110
94
  with do |request|
111
- expect(request_body(request, protocol)['recipient']['camelCase']['secondLevelCamelCase']).to eql('val')
112
- expect(request_body(request, protocol)['recipient']).to_not have_key('camel_case')
95
+ expect(deserialize_body(request.body, protocol)['recipient']['camelCase']['secondLevelCamelCase']).to eql('val')
96
+ expect(deserialize_body(request.body, protocol)['recipient']).to_not have_key('camel_case')
113
97
  true
114
98
  end.to_return(
115
99
  :status => 201,
116
- :body => serialize({}, protocol),
100
+ :body => serialize_body({}, protocol),
117
101
  :headers => { 'Content-Type' => content_type }
118
102
  )
119
103
  end
@@ -69,14 +69,6 @@ shared_examples 'a client initializer' do
69
69
  expect { subject }.to raise_error(ArgumentError, /key and key_name or key_secret are mutually exclusive/)
70
70
  end
71
71
  end
72
-
73
- context 'client_id as only option' do
74
- let(:client_options) { { client_id: 'valid' } }
75
-
76
- it 'requires a valid key' do
77
- expect { subject }.to raise_error(ArgumentError, /client_id cannot be provided without a complete API key or means to authenticate/)
78
- end
79
- end
80
72
  end
81
73
 
82
74
  context 'with valid arguments' do
@@ -273,6 +265,137 @@ shared_examples 'a client initializer' do
273
265
  end
274
266
  end
275
267
  end
268
+
269
+ context 'environment' do
270
+ context 'when set without custom fallback hosts configured' do
271
+ let(:environment) { 'foo' }
272
+ let(:client_options) { default_options.merge(environment: environment) }
273
+ let(:default_fallbacks) { %w(a b c d e).map { |id| "#{environment}-#{id}-fallback.ably-realtime.com" } }
274
+
275
+ it 'sets the environment attribute' do
276
+ expect(subject.environment).to eql(environment)
277
+ end
278
+
279
+ it 'uses the default fallback hosts (#TBC, see https://github.com/ably/wiki/issues/361)' do
280
+ expect(subject.fallback_hosts.sort).to eql(default_fallbacks)
281
+ end
282
+ end
283
+
284
+ context 'when set with custom fallback hosts configured' do
285
+ let(:environment) { 'foo' }
286
+ let(:custom_fallbacks) { %w(a b c).map { |id| "#{environment}-#{id}.foo.com" } }
287
+ let(:client_options) { default_options.merge(environment: environment, fallback_hosts: custom_fallbacks) }
288
+
289
+ it 'sets the environment attribute' do
290
+ expect(subject.environment).to eql(environment)
291
+ end
292
+
293
+ it 'uses the custom provided fallback hosts (#RSC15a)' do
294
+ expect(subject.fallback_hosts.sort).to eql(custom_fallbacks)
295
+ end
296
+ end
297
+
298
+ context 'when set with fallback_hosts_use_default' do
299
+ let(:environment) { 'foo' }
300
+ let(:custom_fallbacks) { %w(a b c).map { |id| "#{environment}-#{id}.foo.com" } }
301
+ let(:default_production_fallbacks) { %w(a b c d e).map { |id| "#{id}.ably-realtime.com" } }
302
+ let(:client_options) { default_options.merge(environment: environment, fallback_hosts_use_default: true) }
303
+
304
+ it 'sets the environment attribute' do
305
+ expect(subject.environment).to eql(environment)
306
+ end
307
+
308
+ it 'uses the production default fallback hosts (#RTN17b)' do
309
+ expect(subject.fallback_hosts.sort).to eql(default_production_fallbacks)
310
+ end
311
+ end
312
+ end
313
+
314
+ context 'rest_host' do
315
+ context 'when set without custom fallback hosts configured' do
316
+ let(:custom_rest_host) { 'foo.com' }
317
+ let(:client_options) { default_options.merge(rest_host: custom_rest_host) }
318
+
319
+ it 'sets the custom_host attribute' do
320
+ expect(subject.custom_host).to eql(custom_rest_host)
321
+ end
322
+
323
+ it 'has no default fallback hosts' do
324
+ expect(subject.fallback_hosts).to be_empty
325
+ end
326
+ end
327
+
328
+ context 'when set with environment and without custom fallback hosts configured' do
329
+ let(:environment) { 'foobar' }
330
+ let(:custom_rest_host) { 'foo.com' }
331
+ let(:client_options) { default_options.merge(environment: environment, rest_host: custom_rest_host) }
332
+
333
+ it 'sets the environment attribute' do
334
+ expect(subject.environment).to eql(environment)
335
+ end
336
+
337
+ it 'sets the custom_host attribute' do
338
+ expect(subject.custom_host).to eql(custom_rest_host)
339
+ end
340
+
341
+ it 'has no default fallback hosts' do
342
+ expect(subject.fallback_hosts).to be_empty
343
+ end
344
+ end
345
+
346
+ context 'when set with custom fallback hosts configured' do
347
+ let(:custom_rest_host) { 'foo.com' }
348
+ let(:custom_fallbacks) { %w(a b c).map { |id| "#{environment}-#{id}.foo.com" } }
349
+ let(:client_options) { default_options.merge(rest_host: custom_rest_host, fallback_hosts: custom_fallbacks) }
350
+
351
+ it 'sets the custom_host attribute' do
352
+ expect(subject.custom_host).to eql(custom_rest_host)
353
+ end
354
+
355
+ it 'has no default fallback hosts' do
356
+ expect(subject.fallback_hosts.sort).to eql(custom_fallbacks)
357
+ end
358
+ end
359
+ end
360
+
361
+ context 'realtime_host' do
362
+ context 'when set without custom fallback hosts configured' do
363
+ let(:custom_realtime_host) { 'realtime.foo.com' }
364
+ let(:client_options) { default_options.merge(realtime_host: custom_realtime_host) }
365
+
366
+ # These tests are shared between realtime & rest clients
367
+ # So don't test for the attribute, instead test the options
368
+ it 'sets the realtime_host option' do
369
+ expect(subject.options[:realtime_host]).to eql(custom_realtime_host)
370
+ end
371
+
372
+ it 'has no default fallback hosts' do
373
+ expect(subject.fallback_hosts).to be_empty
374
+ end
375
+ end
376
+ end
377
+
378
+ context 'custom port' do
379
+ context 'when set without custom fallback hosts configured' do
380
+ let(:custom_port) { 555 }
381
+ let(:client_options) { default_options.merge(port: custom_port) }
382
+
383
+ it 'has no default fallback hosts' do
384
+ expect(subject.fallback_hosts).to be_empty
385
+ end
386
+ end
387
+ end
388
+
389
+ context 'custom TLS port' do
390
+ context 'when set without custom fallback hosts configured' do
391
+ let(:custom_port) { 555 }
392
+ let(:client_options) { default_options.merge(tls_port: custom_port) }
393
+
394
+ it 'has no default fallback hosts' do
395
+ expect(subject.fallback_hosts).to be_empty
396
+ end
397
+ end
398
+ end
276
399
  end
277
400
 
278
401
  context 'delegators' do
@@ -19,6 +19,7 @@ require 'support/event_emitter_helper'
19
19
  require 'support/private_api_formatter'
20
20
  require 'support/protocol_helper'
21
21
  require 'support/random_helper'
22
+ require 'support/serialization_helper'
22
23
  require 'support/test_logger_helper'
23
24
 
24
25
  require 'rspec_config'
@@ -0,0 +1,21 @@
1
+ module SerializationHelper
2
+ def serialize_body(object, protocol)
3
+ if protocol == :msgpack
4
+ MessagePack.pack(object)
5
+ else
6
+ JSON.dump(object)
7
+ end
8
+ end
9
+
10
+ def deserialize_body(object, protocol)
11
+ if protocol == :msgpack
12
+ MessagePack.unpack(object)
13
+ else
14
+ JSON.parse(object)
15
+ end
16
+ end
17
+
18
+ RSpec.configure do |config|
19
+ config.include self
20
+ end
21
+ end
@@ -4,11 +4,11 @@ class TestApp
4
4
  TEST_RESOURCES_PATH = File.expand_path('../../../lib/submodules/ably-common/test-resources', __FILE__)
5
5
 
6
6
  # App configuration for test app
7
- # See https://github.com/ably/ably-common/blob/master/test-resources/test-app-setup.json
7
+ # See https://github.com/ably/ably-common/blob/main/test-resources/test-app-setup.json
8
8
  APP_SPEC = JSON.parse(File.read(File.join(TEST_RESOURCES_PATH, 'test-app-setup.json')))['post_apps']
9
9
 
10
10
  # Cipher details used for client_encoded presence data in test app
11
- # See https://github.com/ably/ably-common/blob/master/test-resources/test-app-setup.json
11
+ # See https://github.com/ably/ably-common/blob/main/test-resources/test-app-setup.json
12
12
  APP_SPEC_CIPHER = JSON.parse(File.read(File.join(TEST_RESOURCES_PATH, 'test-app-setup.json')))['cipher']
13
13
 
14
14
  # If an app has already been created and we need a new app, create a new test app
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  require 'shared/client_initializer_behaviour'
4
4
 
5
5
  describe Ably::Realtime::Client do
6
- subject do
6
+ subject(:realtime_client) do
7
7
  Ably::Realtime::Client.new(client_options)
8
8
  end
9
9
 
@@ -15,28 +15,41 @@ describe Ably::Realtime::Client do
15
15
  it 'passes on the options to the initializer' do
16
16
  rest_client = instance_double('Ably::Rest::Client', auth: instance_double('Ably::Auth'), options: client_options, environment: 'production', use_tls?: true, custom_tls_port: nil)
17
17
  expect(Ably::Rest::Client).to receive(:new).with(hash_including(client_options)).and_return(rest_client)
18
- subject
18
+ realtime_client
19
19
  end
20
20
 
21
21
  context 'for attribute' do
22
22
  [:environment, :use_tls?, :log_level, :custom_host].each do |attribute|
23
23
  specify "##{attribute}" do
24
- expect(subject.rest_client).to receive(attribute)
25
- subject.public_send attribute
24
+ expect(realtime_client.rest_client).to receive(attribute)
25
+ realtime_client.public_send attribute
26
26
  end
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
+ context 'when :transport_params option is passed' do
32
+ let(:expected_transport_params) do
33
+ { 'heartbeats' => 'true', 'v' => '1.0', 'extra_param' => 'extra_param' }
34
+ end
35
+ let(:client_options) do
36
+ { key: 'appid.keyuid:keysecret', transport_params: { heartbeats: true, v: 1.0, extra_param: 'extra_param'} }
37
+ end
38
+
39
+ it 'converts options to strings' do
40
+ expect(realtime_client.transport_params).to eq(expected_transport_params)
41
+ end
42
+ end
43
+
31
44
  context 'push' do
32
45
  let(:client_options) { { key: 'appid.keyuid:keysecret' } }
33
46
 
34
47
  specify '#device is not supported and raises an exception' do
35
- expect { subject.device }.to raise_error Ably::Exceptions::PushNotificationsNotSupported
48
+ expect { realtime_client.device }.to raise_error Ably::Exceptions::PushNotificationsNotSupported
36
49
  end
37
50
 
38
51
  specify '#push returns a Push object' do
39
- expect(subject.push).to be_a(Ably::Realtime::Push)
52
+ expect(realtime_client.push).to be_a(Ably::Realtime::Push)
40
53
  end
41
54
  end
42
55
 
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,11 @@ require 'support/private_api_formatter'
15
15
  require 'support/protocol_helper'
16
16
  require 'support/random_helper'
17
17
  require 'support/test_logger_helper'
18
+ require 'support/serialization_helper'
19
+
20
+ RSpec.configure do |config|
21
+ config.include SerializationHelper
22
+ end
18
23
 
19
24
  # Load in all shared behaviours
20
25
  Dir.glob(File.expand_path("../lib/submodules/ably-ruby/spec/shared/*.rb", File.dirname(__FILE__))).each do |file|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ably-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew O'Riordan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-06 00:00:00.000000000 Z
11
+ date: 2021-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.12'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.12'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: excon
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.55'
41
+ - !ruby/object:Gem::Dependency
42
+ name: typhoeus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.4'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: json
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,20 @@ dependencies:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0.4'
167
+ - !ruby/object:Gem::Dependency
168
+ name: webrick
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
153
181
  - !ruby/object:Gem::Dependency
154
182
  name: yard
155
183
  requirement: !ruby/object:Gem::Requirement
@@ -235,6 +263,7 @@ files:
235
263
  - CHANGELOG.md
236
264
  - Gemfile
237
265
  - LICENSE
266
+ - MAINTAINERS.md
238
267
  - README.md
239
268
  - Rakefile
240
269
  - SPEC.md
@@ -242,13 +271,15 @@ files:
242
271
  - lib/ably-rest.rb
243
272
  - lib/ably-rest/modules/eventmachine_deferrable.rb
244
273
  - lib/submodules/ably-ruby/.editorconfig
274
+ - lib/submodules/ably-ruby/.github/workflows/check.yml
245
275
  - lib/submodules/ably-ruby/.gitignore
246
276
  - lib/submodules/ably-ruby/.gitmodules
247
277
  - lib/submodules/ably-ruby/.rspec
248
- - lib/submodules/ably-ruby/.travis.yml
249
278
  - lib/submodules/ably-ruby/CHANGELOG.md
279
+ - lib/submodules/ably-ruby/COPYRIGHT
250
280
  - lib/submodules/ably-ruby/Gemfile
251
281
  - lib/submodules/ably-ruby/LICENSE
282
+ - lib/submodules/ably-ruby/MAINTAINERS.md
252
283
  - lib/submodules/ably-ruby/README.md
253
284
  - lib/submodules/ably-ruby/Rakefile
254
285
  - lib/submodules/ably-ruby/SPEC.md
@@ -305,6 +336,7 @@ files:
305
336
  - lib/submodules/ably-ruby/lib/ably/realtime/auth.rb
306
337
  - lib/submodules/ably-ruby/lib/ably/realtime/channel.rb
307
338
  - lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb
339
+ - lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_properties.rb
308
340
  - lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_state_machine.rb
309
341
  - lib/submodules/ably-ruby/lib/ably/realtime/channel/publisher.rb
310
342
  - lib/submodules/ably-ruby/lib/ably/realtime/channel/push_channel.rb
@@ -388,6 +420,7 @@ files:
388
420
  - lib/submodules/ably-ruby/spec/support/protocol_helper.rb
389
421
  - lib/submodules/ably-ruby/spec/support/random_helper.rb
390
422
  - lib/submodules/ably-ruby/spec/support/rest_testapp_before_retry.rb
423
+ - lib/submodules/ably-ruby/spec/support/serialization_helper.rb
391
424
  - lib/submodules/ably-ruby/spec/support/test_app.rb
392
425
  - lib/submodules/ably-ruby/spec/support/test_logger_helper.rb
393
426
  - lib/submodules/ably-ruby/spec/unit/auth_spec.rb
@@ -447,7 +480,7 @@ homepage: http://github.com/ably/ably-ruby-rest
447
480
  licenses:
448
481
  - Apache 2
449
482
  metadata: {}
450
- post_install_message:
483
+ post_install_message:
451
484
  rdoc_options: []
452
485
  require_paths:
453
486
  - lib
@@ -463,7 +496,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
463
496
  version: '0'
464
497
  requirements: []
465
498
  rubygems_version: 3.0.3
466
- signing_key:
499
+ signing_key:
467
500
  specification_version: 4
468
501
  summary: A Ruby REST only client library for ably.io realtime messaging
469
502
  test_files:
@@ -1,19 +0,0 @@
1
- sudo: false
2
- env:
3
- - RSPEC_RETRY=true PARALLEL_TEST_PROCESSORS=2 PROTOCOL=json
4
- - RSPEC_RETRY=true PARALLEL_TEST_PROCESSORS=2 PROTOCOL=msgpack
5
- language: ruby
6
- rvm:
7
- - 1.9.3
8
- - 2.1.10
9
- - 2.2.10
10
- - 2.3.8
11
- - 2.5.5
12
- - 2.6.0
13
- - 2.6.1
14
- - 2.6.2
15
- - 2.6.3
16
- script: spec/run_parallel_tests
17
- notifications:
18
- slack:
19
- secure: Xe8MwDcV2C8XLGk6O6Co31LpQiRSxsmS7Toy5vM7rHds5fnVRBNn5iX6Q5mXMdLOlnsMhjKLt7zl4fsBOZv+siQ+Us0omZSIYpXCYSCIj8nofReF0Lj8M4oa6lFSL5OuygO7PH+wLKTRxQURGZ6Pi1nHU+RE5izRmsewQHkhtY0=