ably 1.0.4 → 1.0.5

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
- SHA1:
3
- metadata.gz: 3c9fbb2d2e98f6d82d7034718820679ab772adc9
4
- data.tar.gz: 33f0173c647e92e77724c48c761a5aefef608360
2
+ SHA256:
3
+ metadata.gz: a05adf2fb91ff543ae2797812dce8bc9c3119cc5ebf9c4a4468a177f07e2587c
4
+ data.tar.gz: 97c229e631a871cdba553220677629bff959be160db9a864b8c5b712e26480d1
5
5
  SHA512:
6
- metadata.gz: efd51a591e92dc64137f257beaabb3c9b909166f19abeb7ee37a8895c5e6dec7069c7c02f7c326240b6fbd628831c5dd718f87f0fd4174a4bb8a2d8116926622
7
- data.tar.gz: 1e0ef0ba81c9dcbc7ba86c44187c6afb2ff16f6841c96b430a461c1b121c63e5b76ab87c1d696428769f8948aee0774a061e183131e3b543d46e414919ccfe1c
6
+ metadata.gz: e3a2dc86d92459e6fe03721df934e819e504a39a6be899a42d3ea00b251e8dd8f465552e481451a024903ee199370a932addfdbda1962f441379fc5cb718ea73
7
+ data.tar.gz: db1ca5e7ae13cb490f469d72a58ee7ca8f1377a834e200ade85045f0b341f411aaed966a4c7d2d85de9dd7cd55084a8369ff39505e76508ce744549723b305a8
@@ -6,7 +6,9 @@ language: ruby
6
6
  rvm:
7
7
  - 1.9.3
8
8
  - 2.0.0
9
+ - 2.1.10
9
10
  - 2.2.0
11
+ - 2.3.6
10
12
  - 2.4.1
11
13
  script: bundle exec rspec
12
14
  notifications:
@@ -1,21 +1,50 @@
1
1
  # Change Log
2
2
 
3
- ## [v1.0.2](https://github.com/ably/ably-ruby/tree/v1.0.2)
3
+ ## [v1.0.5](https://github.com/ably/ably-ruby/tree/v1.0.5)
4
4
 
5
+ [Full Changelog](https://github.com/ably/ably-ruby/compare/v1.0.4...v1.0.5)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Add supported platforms to README file [\#128](https://github.com/ably/ably-ruby/issues/128)
10
+ - Add Ruby 2.1 and 2.3 to Travis tests [\#130](https://github.com/ably/ably-ruby/pull/130) ([funkyboy](https://github.com/funkyboy))
11
+
12
+ **Closed issues:**
13
+
14
+ - Cannot get realtime to work [\#127](https://github.com/ably/ably-ruby/issues/127)
15
+
16
+ **Merged pull requests:**
17
+
18
+ - Improve pagination history test [\#138](https://github.com/ably/ably-ruby/pull/138) ([funkyboy](https://github.com/funkyboy))
19
+ - Fix failing auth test [\#135](https://github.com/ably/ably-ruby/pull/135) ([funkyboy](https://github.com/funkyboy))
20
+ - Add submodule instructions to Contributing section [\#134](https://github.com/ably/ably-ruby/pull/134) ([funkyboy](https://github.com/funkyboy))
21
+ - Add request\_id option to client [\#133](https://github.com/ably/ably-ruby/pull/133) ([funkyboy](https://github.com/funkyboy))
22
+ - Update README with supported platforms [\#131](https://github.com/ably/ably-ruby/pull/131) ([funkyboy](https://github.com/funkyboy))
23
+
24
+ ## [v1.0.4](https://github.com/ably/ably-ruby/tree/v1.0.4) (2017-05-31)
25
+ [Full Changelog](https://github.com/ably/ably-ruby/compare/v1.0.3...v1.0.4)
26
+
27
+ ## [v1.0.3](https://github.com/ably/ably-ruby/tree/v1.0.3) (2017-05-31)
28
+ [Full Changelog](https://github.com/ably/ably-ruby/compare/v1.0.2...v1.0.3)
29
+
30
+ ## [v1.0.2](https://github.com/ably/ably-ruby/tree/v1.0.2) (2017-05-16)
5
31
  [Full Changelog](https://github.com/ably/ably-ruby/compare/v1.0.1...v1.0.2)
6
32
 
7
33
  **Fixed bugs:**
8
34
 
9
35
  - Reconnect following disconnection is hitting a 403 error [\#117](https://github.com/ably/ably-ruby/issues/117)
10
- - [Fallback hosts were used upon any disconnection as opposed to only when the primary host is unavailable](https://github.com/ably/ably-ruby/pull/120)
11
36
 
12
37
  **Merged pull requests:**
13
38
 
14
39
  - Fallback fixes [\#120](https://github.com/ably/ably-ruby/pull/120) ([mattheworiordan](https://github.com/mattheworiordan))
40
+ - Channel name encoding error for REST requests [\#119](https://github.com/ably/ably-ruby/pull/119) ([mattheworiordan](https://github.com/mattheworiordan))
15
41
 
16
42
  ## [v1.0.1](https://github.com/ably/ably-ruby/tree/v1.0.1) (2017-05-11)
17
43
  [Full Changelog](https://github.com/ably/ably-ruby/compare/v1.0.0...v1.0.1)
18
44
 
45
+ ## [v1.1.0-beta.push.1](https://github.com/ably/ably-ruby/tree/v1.1.0-beta.push.1) (2017-04-25)
46
+ [Full Changelog](https://github.com/ably/ably-ruby/compare/v1.0.0...v1.1.0-beta.push.1)
47
+
19
48
  ## [v1.0.0](https://github.com/ably/ably-ruby/tree/v1.0.0) (2017-03-07)
20
49
  [Full Changelog](https://github.com/ably/ably-ruby/compare/v0.8.15...v1.0.0)
21
50
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- Copyright (c) 2016 Ably
1
+ Copyright (c) 2015-2017 Ably
2
2
 
3
- Copyright 2016 Ably Real-time Ltd
3
+ Copyright 2015-2017 Ably Real-time Ltd
4
4
 
5
5
  Licensed under the Apache License, Version 2.0 (the "License");
6
6
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -5,6 +5,14 @@
5
5
 
6
6
  A Ruby client library for [ably.io](https://www.ably.io), the realtime messaging service.
7
7
 
8
+ ## Supported platforms
9
+
10
+ This SDK supports Ruby 1.9.3+.
11
+
12
+ We regression-test the SDK against a selection of Ruby versions (which we update over time, but usually consists of mainstream and widely used versions). Please refer to [.travis.yml](./.travis.yml) for the set of versions that currently undergo CI testing.
13
+
14
+ If you find any compatibility issues, please [do raise an issue](https://github.com/ably/ably-ruby/issues/new) in this repository or [contact Ably customer support](https://support.ably.io/) for advice.
15
+
8
16
  ## Documentation
9
17
 
10
18
  Visit https://www.ably.io/documentation for a complete API reference and more examples.
@@ -296,21 +304,23 @@ To see what has changed in recent versions of Bundler, see the [CHANGELOG](CHANG
296
304
  ## Contributing
297
305
 
298
306
  1. Fork it
299
- 2. Create your feature branch (`git checkout -b my-new-feature`)
300
- 3. Commit your changes (`git commit -am 'Add some feature'`)
301
- 4. Ensure you have added suitable tests and the test suite is passing(`bundle exec rspec`)
302
- 4. Push to the branch (`git push origin my-new-feature`)
303
- 5. Create a new Pull Request
307
+ 2. When pulling to local, make sure to also pull the `ably-common` repo (`git submodule init && git submodule update`)
308
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
309
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
310
+ 5. Ensure you have added suitable tests and the test suite is passing(`bundle exec rspec`)
311
+ 6. Push to the branch (`git push origin my-new-feature`)
312
+ 7. Create a new Pull Request
304
313
 
305
- ## Release notes
314
+ ## Release process
306
315
 
307
316
  This library uses [semantic versioning](http://semver.org/). For each release, the following needs to be done:
308
317
 
309
318
  * Update the version number in [version.rb](./lib/ably/version.rb) and commit the change.
310
319
  * Run [`github_changelog_generator`](https://github.com/skywinder/Github-Changelog-Generator) to automate the update of the [CHANGELOG](./CHANGELOG.md). Once the `CHANGELOG` update has completed, manually change the `Unreleased` heading and link with the current version number such as `v1.0.0`. Also ensure that the `Full Changelog` link points to the new version tag instead of the `HEAD`. Commit this change.
311
320
  * Add a tag and push to origin such as `git tag v1.0.0 && git push origin v1.0.0`
321
+ * Visit [https://github.com/ably/ably-ruby/tags](https://github.com/ably/ably-ruby/tags) and `Add release notes` for the release including links to the changelog entry.
312
322
  * Run `rake release` to publish the gem to [Rubygems](http://www.rubydoc.info/gems/ably)
313
323
 
314
324
  ## License
315
325
 
316
- Copyright (c) 2016 Ably Real-time Ltd, Licensed under the Apache License, Version 2.0. Refer to [LICENSE](LICENSE) for the license terms.
326
+ Copyright (c) 2017 Ably Real-time Ltd, Licensed under the Apache License, Version 2.0. Refer to [LICENSE](LICENSE) for the license terms.
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.description = %q{A Ruby client library for ably.io realtime messaging}
12
12
  spec.summary = %q{A Ruby client library for ably.io realtime messaging implemented using EventMachine}
13
13
  spec.homepage = 'http://github.com/ably/ably-ruby'
14
- spec.license = 'Apache 2'
14
+ spec.license = 'Apache-2.0'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -13,7 +13,7 @@ module Ably
13
13
  # @!attribute [r] code
14
14
  # @return [String] Ably specific error code
15
15
  class BaseAblyException < StandardError
16
- attr_reader :status, :code
16
+ attr_reader :status, :code, :request_id
17
17
 
18
18
  def initialize(message, status = nil, code = nil, base_exception = nil, options = {})
19
19
  super message
@@ -25,6 +25,7 @@ module Ably
25
25
  @code = code
26
26
  @code ||= base_exception.code if base_exception && base_exception.respond_to?(:code)
27
27
  @code ||= options[:fallback_code]
28
+ @request_id ||= options[:request_id]
28
29
  end
29
30
 
30
31
  def to_s
@@ -34,6 +35,7 @@ module Ably
34
35
  additional_info << "code: #{code}" if code
35
36
  additional_info << "http status: #{status}" if status
36
37
  additional_info << "base exception: #{@base_exception.class}" if @base_exception
38
+ additional_info << "request_id: #{request_id}" if request_id
37
39
  message << "(#{additional_info.join(', ')})"
38
40
  end
39
41
  message.join(' ')
@@ -83,6 +83,10 @@ module Ably
83
83
  # if empty or nil then fallback host functionality is disabled
84
84
  attr_reader :fallback_hosts
85
85
 
86
+ # Whethere the {Client} has to add a random identifier to the path of a request
87
+ # @return [Boolean]
88
+ attr_reader :add_request_ids
89
+
86
90
  # Creates a {Ably::Rest::Client Rest Client} and configures the {Ably::Auth} object for the connection.
87
91
  #
88
92
  # @param [Hash,String] options an options Hash used to configure the client and the authentication, or String with an API key or Token ID
@@ -146,6 +150,7 @@ module Ably
146
150
  @custom_host = options.delete(:rest_host)
147
151
  @custom_port = options.delete(:port)
148
152
  @custom_tls_port = options.delete(:tls_port)
153
+ @add_request_ids = options.delete(:add_request_ids)
149
154
 
150
155
  if options[:fallback_hosts_use_default] && options[:fallback_jhosts]
151
156
  raise ArgumentError, "fallback_hosts_use_default cannot be set to trye when fallback_jhosts is also provided"
@@ -434,11 +439,25 @@ module Ably
434
439
  max_retry_duration = http_defaults.fetch(:max_retry_duration)
435
440
  requested_at = Time.now
436
441
  retry_count = 0
442
+ request_id = nil
443
+ if add_request_ids
444
+ params = if params.nil?
445
+ {}
446
+ else
447
+ params.dup
448
+ end
449
+ request_id = SecureRandom.urlsafe_base64(10)
450
+ params[:request_id] = request_id
451
+ end
437
452
 
438
453
  begin
439
454
  use_fallback = can_fallback_to_alternate_ably_host? && retry_count > 0
440
455
 
441
456
  connection(use_fallback: use_fallback).send(method, path, params) do |request|
457
+ if add_request_ids
458
+ request.options.context = {} if request.options.context.nil?
459
+ request.options.context[:request_id] = request_id
460
+ end
442
461
  unless options[:send_auth_header] == false
443
462
  request.headers[:authorization] = auth.auth_header
444
463
  if options[:headers]
@@ -456,12 +475,12 @@ module Ably
456
475
  logger.warn { "Ably::Rest::Client - Retry #{retry_count} for #{method} #{path} #{params} as initial attempt failed: #{error}" }
457
476
  retry
458
477
  end
459
-
460
478
  case error
461
479
  when Faraday::TimeoutError
462
- raise Ably::Exceptions::ConnectionTimeout.new(error.message, nil, 80014, error)
480
+ raise Ably::Exceptions::ConnectionTimeout.new(error.message, nil, 80014, error, { request_id: request_id })
463
481
  when Faraday::ClientError
464
- raise Ably::Exceptions::ConnectionError.new(error.message, nil, 80000, error)
482
+ # request_id is also available in the request context
483
+ raise Ably::Exceptions::ConnectionError.new(error.message, nil, 80000, error, { request_id: request_id })
465
484
  else
466
485
  raise error
467
486
  end
@@ -27,8 +27,8 @@ module Ably
27
27
  end
28
28
 
29
29
  message = 'Unknown server error' if message.to_s.strip == ''
30
-
31
- exception_args = [message, error_status_code, error_code]
30
+ request_id = env.request.context[:request_id] if env.request.context
31
+ exception_args = [message, error_status_code, error_code, nil, { request_id: request_id }]
32
32
 
33
33
  if env.status >= 500
34
34
  raise Ably::Exceptions::ServerError.new(*exception_args)
@@ -1,5 +1,5 @@
1
1
  module Ably
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
  PROTOCOL_VERSION = '1.0'
4
4
 
5
5
  # Allow a variant to be configured for all instances of this client library
@@ -1083,7 +1083,7 @@ describe Ably::Auth do
1083
1083
  expect { auth.request_token(timestamp: Time.now - 180) }.to raise_error do |error|
1084
1084
  expect(error).to be_a(Ably::Exceptions::UnauthorizedRequest)
1085
1085
  expect(error.status).to eql(401)
1086
- expect(error.code).to eql(40101)
1086
+ expect(error.code).to eql(40104)
1087
1087
  end
1088
1088
  end
1089
1089
 
@@ -343,7 +343,13 @@ describe Ably::Rest::Channel do
343
343
 
344
344
  # Page 3
345
345
  expect(page_3.items.size).to eql(1)
346
- expect(page_3).to be_last
346
+ # This test should be deterministic but it's not.
347
+ # Sometimes the backend, to avoid too much work, returns a `next` link that contains empty reults.
348
+ if page_3.next
349
+ expect(page_3.next.items.length).to eql(0)
350
+ else
351
+ expect(page_3).to be_last
352
+ end
347
353
  end
348
354
 
349
355
  context 'direction' do
@@ -959,5 +959,100 @@ describe Ably::Rest::Client do
959
959
  end
960
960
  end
961
961
  end
962
+
963
+ context 'request_id generation' do
964
+ context 'Timeout error' do
965
+ context 'with request_id', :webmock do
966
+ let(:custom_logger) do
967
+ Class.new do
968
+ def initialize
969
+ @messages = []
970
+ end
971
+
972
+ [:fatal, :error, :warn, :info, :debug].each do |severity|
973
+ define_method severity do |message, &block|
974
+ message_val = [message]
975
+ message_val << block.call if block
976
+
977
+ @messages << [severity, message_val.compact.join(' ')]
978
+ end
979
+ end
980
+
981
+ def logs
982
+ @messages
983
+ end
984
+
985
+ def level
986
+ 1
987
+ end
988
+
989
+ def level=(new_level)
990
+ end
991
+ end
992
+ end
993
+ let(:custom_logger_object) { custom_logger.new }
994
+ let(:client_options) { default_options.merge(key: api_key, logger: custom_logger_object, add_request_ids: true) }
995
+ before do
996
+ @request_id = nil
997
+ stub_request(:get, Addressable::Template.new("#{client.endpoint}/time{?request_id}")).with do |request|
998
+ @request_id = request.uri.query_values['request_id']
999
+ end.to_return do
1000
+ raise Faraday::TimeoutError.new('timeout error message')
1001
+ end
1002
+ end
1003
+ it 'has an error with the same request_id of the request' do
1004
+ expect{ client.time }.to raise_error(Ably::Exceptions::ConnectionTimeout, /#{@request_id}/)
1005
+ expect(custom_logger_object.logs.find { |severity, message| message.match(/#{@request_id}/i)} ).to_not be_nil
1006
+ end
1007
+ end
1008
+
1009
+ context 'when specifying fallback hosts', :webmock do
1010
+ let(:client_options) { { key: api_key, fallback_hosts_use_default: true, add_request_ids: true } }
1011
+ let(:requests) { [] }
1012
+ before do
1013
+ @request_id = nil
1014
+ hosts = Ably::FALLBACK_HOSTS + ['rest.ably.io']
1015
+ hosts.each do |host|
1016
+ stub_request(:get, Addressable::Template.new("https://#{host.downcase}/time{?request_id}")).with do |request|
1017
+ @request_id = request.uri.query_values['request_id']
1018
+ requests << @request_id
1019
+ end.to_return do
1020
+ raise Faraday::TimeoutError.new('timeout error message')
1021
+ end
1022
+ end
1023
+ end
1024
+ it 'request_id is the same across retries' do
1025
+ expect{ client.time }.to raise_error(Ably::Exceptions::ConnectionTimeout, /#{@request_id}/)
1026
+ expect(requests.uniq.count).to eql(1)
1027
+ expect(requests.uniq.first).to eql(@request_id)
1028
+ end
1029
+ end
1030
+
1031
+ context 'without request_id' do
1032
+ let(:client_options) { default_options.merge(key: api_key, http_request_timeout: 0) }
1033
+ it 'does not include request_id in ConnectionTimeout error' do
1034
+ begin
1035
+ client.stats
1036
+ rescue Ably::Exceptions::ConnectionTimeout => err
1037
+ expect(err.request_id).to eql(nil)
1038
+ end
1039
+ end
1040
+ end
1041
+ end
1042
+
1043
+ context 'UnauthorizedRequest nonce error' do
1044
+ let(:token_params) { { nonce: "samenonce_#{protocol}", timestamp: Time.now.to_i } }
1045
+ it 'includes request_id in UnauthorizedRequest error due to replayed nonce' do
1046
+ client1 = Ably::Rest::Client.new(default_options.merge(key: api_key))
1047
+ client2 = Ably::Rest::Client.new(default_options.merge(key: api_key, add_request_ids: true))
1048
+ expect { client1.auth.request_token(token_params) }.not_to raise_error
1049
+ begin
1050
+ client2.auth.request_token(token_params)
1051
+ rescue Ably::Exceptions::UnauthorizedRequest => err
1052
+ expect(err.request_id).to_not eql(nil)
1053
+ end
1054
+ end
1055
+ end
1056
+ end
962
1057
  end
963
1058
  end
@@ -50,4 +50,11 @@ describe Ably::Rest::Client do
50
50
  end
51
51
  end
52
52
  end
53
+
54
+ context 'request_id generation' do
55
+ let(:client_options) { { key: 'appid.keyuid:keysecret', add_request_ids: true } }
56
+ it 'includes request_id in URL' do
57
+ expect(subject.add_request_ids).to eql(true)
58
+ end
59
+ end
53
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ably
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lewis Marshall
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-31 00:00:00.000000000 Z
12
+ date: 2018-04-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -440,7 +440,7 @@ files:
440
440
  - spec/unit/util/pub_sub_spec.rb
441
441
  homepage: http://github.com/ably/ably-ruby
442
442
  licenses:
443
- - Apache 2
443
+ - Apache-2.0
444
444
  metadata: {}
445
445
  post_install_message:
446
446
  rdoc_options: []
@@ -458,7 +458,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
458
458
  version: '0'
459
459
  requirements: []
460
460
  rubyforge_project:
461
- rubygems_version: 2.4.8
461
+ rubygems_version: 2.7.6
462
462
  signing_key:
463
463
  specification_version: 4
464
464
  summary: A Ruby client library for ably.io realtime messaging implemented using EventMachine