ably 1.1.2 → 1.1.3

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
  SHA256:
3
- metadata.gz: 372821f0df3a03b36e29d0c2ce4141e08b7467c794aa28c542e38b10d658a0f5
4
- data.tar.gz: 7015ce6030cf75b97474cab9dfb809d671d4178efd34aff777514502a3a74d83
3
+ metadata.gz: 65f86c14df1cc486e6ebd7ecb98c35a19545f9483ceba68983b8ffcdf11363f8
4
+ data.tar.gz: 999b6dbe3a20d4c73b7d18c9b5e4c1e33e3f77bbc52d7b0598764ca71c35a04a
5
5
  SHA512:
6
- metadata.gz: d92e931347421a955f3a318fca505cbb9f2271417a804a4e5a2e310c155abf4f42d2d89beca434e372a4b5777d931d278019a10b77d4b151d4e154a8a06d8064
7
- data.tar.gz: 7e1d96e9b49558bdd010fa63e155ca291921e910212cb38ec00eafe7a6e7b58038150a1e24308d109ac59814bc5f181d2d653734c12c901ce11d7757410a4b28
6
+ metadata.gz: 466bc5c7f6547bf298d8e0750a8d1e08abf0afffa214d7ec6ffae62ef39bc9b5cffaa14a6e43a5fc6835bcc359c04384ff66ad3d5b7406c9bfc5baf38b581688
7
+ data.tar.gz: 94e257ae6a88f2620ecf218816705fe3af940980ebc0dafbd122fd3c1bfbb9f5960c33f879932e5a142b75f344dff075a48cefd46377c86bca17f5bba660adb8
@@ -1,4 +1,3 @@
1
- sudo: false
2
1
  env:
3
2
  - RSPEC_RETRY=true PARALLEL_TEST_PROCESSORS=2 PROTOCOL=json
4
3
  - RSPEC_RETRY=true PARALLEL_TEST_PROCESSORS=2 PROTOCOL=msgpack
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## [v1.1.3](https://github.com/ably/ably-ruby/tree/v1.1.3)
4
+
5
+ [Full Changelog](https://github.com/ably/ably-ruby/compare/v1.1.2...v1.1.3)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - RestChannel#publish: implement params (RSL1l) [\#210](https://github.com/ably/ably-ruby/pull/210) ([simonwoolf](https://github.com/simonwoolf))
10
+
3
11
  ## [v1.1.2](https://github.com/ably/ably-ruby/tree/v1.1.2)
4
12
 
5
13
  [Full Changelog](https://github.com/ably/ably-ruby/compare/v1.1.1...v1.1.2)
data/LICENSE CHANGED
@@ -1,6 +1,4 @@
1
- Copyright (c) 2015-2017 Ably
2
-
3
- Copyright 2015-2017 Ably Real-time Ltd
1
+ Copyright 2015-2020 Ably Real-time Ltd (ably.com)
4
2
 
5
3
  Licensed under the Apache License, Version 2.0 (the "License");
6
4
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -329,7 +329,3 @@ This library uses [semantic versioning](http://semver.org/). For each release, t
329
329
  * 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.
330
330
  * Run `rake release` to publish the gem to [Rubygems](https://rubygems.org/gems/ably)
331
331
  * Release the [REST-only library `ably-ruby-rest`](https://github.com/ably/ably-ruby-rest#release-process)
332
-
333
- ## License
334
-
335
- Copyright (c) 2017 Ably Real-time Ltd, Licensed under the Apache License, Version 2.0. Refer to [LICENSE](LICENSE) for the license terms.
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency 'eventmachine', '~> 1.2.6'
22
22
  spec.add_runtime_dependency 'em-http-request', '~> 1.1'
23
23
  spec.add_runtime_dependency 'statesman', '~> 1.0.0'
24
- spec.add_runtime_dependency 'faraday', '~> 0.12'
24
+ spec.add_runtime_dependency 'faraday', '>= 0.12', '< 2.0.0'
25
25
  spec.add_runtime_dependency 'excon', '~> 0.55'
26
26
 
27
27
  if RUBY_VERSION.match(/^1\./)
@@ -5,7 +5,7 @@ module Ably
5
5
  TOKEN_EXPIRED_CODE = 40140..40149
6
6
 
7
7
  # Base Ably exception class that contains status and code values used by Ably
8
- # Refer to https://github.com/ably/ably-common/blob/master/protocol/errors.json
8
+ # Refer to https://github.com/ably/ably-common/blob/main/protocol/errors.json
9
9
  #
10
10
  # @!attribute [r] message
11
11
  # @return [String] Error message from Ably
@@ -116,7 +116,7 @@ module Ably
116
116
  class InvalidState < BaseAblyException; end
117
117
 
118
118
  # A generic Ably exception taht supports a status & code.
119
- # See https://github.com/ably/ably-common/blob/master/protocol/errors.json for a list of Ably errors
119
+ # See https://github.com/ably/ably-common/blob/main/protocol/errors.json for a list of Ably errors
120
120
  class Standard < BaseAblyException; end
121
121
 
122
122
  # The HTTP request has returned a 500 error
@@ -40,15 +40,14 @@ module Ably
40
40
  @push = PushChannel.new(self)
41
41
  end
42
42
 
43
- # Publish one or more messages to the channel.
44
- #
45
- # @param name [String, Array<Ably::Models::Message|Hash>, nil] The event name of the message to publish, or an Array of [Ably::Model::Message] objects or [Hash] objects with +:name+ and +:data+ pairs
46
- # @param data [String, ByteArray, nil] The message payload unless an Array of [Ably::Model::Message] objects passed in the first argument
47
- # @param attributes [Hash, nil] Optional additional message attributes such as :extras, :id, :client_id or :connection_id, applied when name attribute is nil or a string
43
+ # Publish one or more messages to the channel. Three overloaded forms
44
+ # @param name [String, Array<Ably::Models::Message|Hash>, Ably::Models::Message, nil] The event name of the message to publish, or an Array of [Ably::Model::Message] objects or [Hash] objects with +:name+ and +:data+ pairs, or a single Ably::Model::Message object
45
+ # @param data [String, ByteArray, Hash, nil] The message payload unless an Array of [Ably::Model::Message] objects passed in the first argument, in which case an optional hash of query parameters
46
+ # @param attributes [Hash, nil] Optional additional message attributes such as :extras, :id, :client_id or :connection_id, applied when name attribute is nil or a string (Deprecated, will be removed in 2.0 in favour of constructing a Message object)
48
47
  # @return [Boolean] true if the message was published, otherwise false
49
48
  #
50
49
  # @example
51
- # # Publish a single message
50
+ # # Publish a single message with (name, data) form
52
51
  # channel.publish 'click', { x: 1, y: 2 }
53
52
  #
54
53
  # # Publish an array of message Hashes
@@ -65,17 +64,25 @@ module Ably
65
64
  # ]
66
65
  # channel.publish messages
67
66
  #
68
- def publish(name, data = nil, attributes = {})
69
- messages = if name.kind_of?(Enumerable)
70
- name
67
+ # # Publish a single Ably::Models::Message object, with a query params
68
+ # # specifying quickAck: true
69
+ # message = Ably::Models::Message(name: 'click', { x: 1, y: 2 })
70
+ # channel.publish message, quickAck: 'true'
71
+ #
72
+ def publish(first, second = nil, third = {})
73
+ messages, qs_params = if first.kind_of?(Enumerable)
74
+ # ([Message], qs_params) form
75
+ [first, second]
76
+ elsif first.kind_of?(Ably::Models::Message)
77
+ # (Message, qs_params) form
78
+ [[first], second]
71
79
  else
72
- if name.kind_of?(Ably::Models::Message)
73
- raise ArgumentError, "name argument does not support single Message objects, only arrays of Message objects"
74
- end
75
-
76
- name = ensure_utf_8(:name, name, allow_nil: true)
77
- ensure_supported_payload data
78
- [{ name: name, data: data }.merge(attributes)]
80
+ # (name, data, attributes) form
81
+ first = ensure_utf_8(:name, first, allow_nil: true)
82
+ ensure_supported_payload second
83
+ # RSL1h - attributes as an extra method parameter is extra-spec but need to
84
+ # keep it for backcompat until version 2
85
+ [[{ name: first, data: second }.merge(third)], nil]
79
86
  end
80
87
 
81
88
  payload = messages.each_with_index.map do |message, index|
@@ -103,7 +110,8 @@ module Ably
103
110
  end
104
111
  end
105
112
 
106
- response = client.post("#{base_path}/publish", payload.length == 1 ? payload.first : payload)
113
+ options = qs_params ? { qs_params: qs_params } : {}
114
+ response = client.post("#{base_path}/publish", payload.length == 1 ? payload.first : payload, options)
107
115
 
108
116
  [201, 204].include?(response.status)
109
117
  end
@@ -32,6 +32,13 @@ module Ably
32
32
 
33
33
  FALLBACK_RETRY_TIMEOUT = 10 * 60
34
34
 
35
+ # Faraday 1.0 introduced new error types, however we want to support Faraday <1 too which only used Faraday::ClientError
36
+ FARADAY_CLIENT_OR_SERVER_ERRORS = if defined?(Faraday::ParsingError)
37
+ [Faraday::ClientError, Faraday::ServerError, Faraday::ConnectionFailed, Faraday::SSLError, Faraday::ParsingError]
38
+ else
39
+ Faraday::ClientError
40
+ end
41
+
35
42
  def_delegators :auth, :client_id, :auth_options
36
43
 
37
44
  # Custom environment to use such as 'sandbox' when testing the client library against an alternate Ably environment
@@ -559,6 +566,9 @@ module Ably
559
566
  request.options.context = {} if request.options.context.nil?
560
567
  request.options.context[:request_id] = request_id
561
568
  end
569
+ if options[:qs_params]
570
+ request.params.merge!(options[:qs_params])
571
+ end
562
572
  unless options[:send_auth_header] == false
563
573
  request.headers[:authorization] = auth.auth_header
564
574
  if options[:headers]
@@ -578,7 +588,7 @@ module Ably
578
588
  end
579
589
  end
580
590
 
581
- rescue Faraday::TimeoutError, Faraday::ClientError, Ably::Exceptions::ServerError => error
591
+ rescue *([Faraday::TimeoutError, Ably::Exceptions::ServerError] + FARADAY_CLIENT_OR_SERVER_ERRORS) => error
582
592
  retry_sequence_id ||= SecureRandom.urlsafe_base64(4)
583
593
  time_passed = Time.now - requested_at
584
594
 
@@ -598,7 +608,7 @@ module Ably
598
608
  case error
599
609
  when Faraday::TimeoutError
600
610
  raise Ably::Exceptions::ConnectionTimeout.new(error.message, nil, Ably::Exceptions::Codes::CONNECTION_TIMED_OUT, error, { request_id: request_id })
601
- when Faraday::ClientError
611
+ when *FARADAY_CLIENT_OR_SERVER_ERRORS
602
612
  # request_id is also available in the request context
603
613
  raise Ably::Exceptions::ConnectionError.new(error.message, nil, Ably::Exceptions::Codes::CONNECTION_FAILED, error, { request_id: request_id })
604
614
  else
@@ -1,5 +1,5 @@
1
1
  module Ably
2
- VERSION = '1.1.2'
2
+ VERSION = '1.1.3'
3
3
  PROTOCOL_VERSION = '1.1'
4
4
 
5
5
  # Allow a variant to be configured for all instances of this client library
@@ -1058,7 +1058,7 @@ describe Ably::Realtime::Auth, :event_machine do
1058
1058
 
1059
1059
  it 'disconnected includes and invalid signature message' do
1060
1060
  client.connection.once(:disconnected) do |state_change|
1061
- expect(state_change.reason.message.match(/invalid signature/i)).to_not be_nil
1061
+ expect(state_change.reason.message.match(/signature verification failed/i)).to_not be_nil
1062
1062
  expect(state_change.reason.code).to eql(40144)
1063
1063
  stop_reactor
1064
1064
  end
@@ -1111,7 +1111,7 @@ describe Ably::Realtime::Auth, :event_machine do
1111
1111
 
1112
1112
  it 'authentication fails and reason for disconnection is invalid signature' do
1113
1113
  client.connection.once(:disconnected) do |state_change|
1114
- expect(state_change.reason.message.match(/invalid signature/i)).to_not be_nil
1114
+ expect(state_change.reason.message.match(/signature verification failed/i)).to_not be_nil
1115
1115
  expect(state_change.reason.code).to eql(40144)
1116
1116
  stop_reactor
1117
1117
  end
@@ -1143,7 +1143,7 @@ describe Ably::Realtime::Auth, :event_machine do
1143
1143
 
1144
1144
  it 'fails with an invalid signature error' do
1145
1145
  client.connection.once(:disconnected) do |state_change|
1146
- expect(state_change.reason.message.match(/invalid signature/i)).to_not be_nil
1146
+ expect(state_change.reason.message.match(/signature verification failed/i)).to_not be_nil
1147
1147
  expect(state_change.reason.code).to eql(40144)
1148
1148
  stop_reactor
1149
1149
  end
@@ -40,7 +40,7 @@ describe Ably::Rest::Channel do
40
40
 
41
41
  it 'publishes the message without a client_id' do
42
42
  expect(client).to receive(:post).
43
- with("/channels/#{channel_name}/publish", hash_excluding(client_id: client_id)).
43
+ with("/channels/#{channel_name}/publish", hash_excluding(client_id: client_id), {}).
44
44
  and_return(double('response', status: 201))
45
45
 
46
46
  expect(channel.publish(name, data)).to eql(true)
@@ -82,6 +82,44 @@ describe Ably::Rest::Channel do
82
82
  end
83
83
  end
84
84
 
85
+ context 'with a Message object' do
86
+ let(:name) { random_str }
87
+
88
+ let(:message) do
89
+ Ably::Models::Message(name: name, data: data)
90
+ end
91
+
92
+ it 'publishes the message' do
93
+ expect(client).to receive(:post).once.and_call_original
94
+ expect(channel.publish(message)).to eql(true)
95
+ expect(channel.history.items.first.name).to eql(name)
96
+ end
97
+ end
98
+
99
+ context 'with a Message object and query params' do
100
+ let(:message) do
101
+ Ably::Models::Message(name: name, data: data)
102
+ end
103
+
104
+ it 'should fail to publish the message (RSL1l1)' do
105
+ expect(client).to receive(:post).once.and_call_original
106
+ expect { channel.publish(message, { _forceNack: 'true' }) }.to raise_error(Ably::Exceptions::InvalidRequest, /40099/)
107
+ end
108
+ end
109
+
110
+ context 'with Messages and query params' do
111
+ let(:messages) do
112
+ 10.times.map do |index|
113
+ { name: index.to_s, data: { "index" => index + 10 } }
114
+ end
115
+ end
116
+
117
+ it 'should fail to publish the message (RSL1l1)' do
118
+ expect(client).to receive(:post).once.and_call_original
119
+ expect { channel.publish(messages, { _forceNack: 'true' }) }.to raise_error(Ably::Exceptions::InvalidRequest, /40099/)
120
+ end
121
+ end
122
+
85
123
  context 'without adequate permissions on the channel' do
86
124
  let(:capability) { { onlyChannel: ['subscribe'] } }
87
125
  let(:client_options) { default_options.merge(use_token_auth: true, default_token_params: { capability: capability }) }
@@ -96,7 +134,7 @@ describe Ably::Rest::Channel do
96
134
  let(:data) { random_str }
97
135
 
98
136
  it 'publishes the message without a name attribute in the payload' do
99
- expect(client).to receive(:post).with(anything, { "data" => data }).once.and_call_original
137
+ expect(client).to receive(:post).with(anything, { "data" => data }, {}).once.and_call_original
100
138
  expect(channel.publish(nil, data)).to eql(true)
101
139
  expect(channel.history.items.first.name).to be_nil
102
140
  expect(channel.history.items.first.data).to eql(data)
@@ -107,7 +145,7 @@ describe Ably::Rest::Channel do
107
145
  let(:name) { random_str }
108
146
 
109
147
  it 'publishes the message without a data attribute in the payload' do
110
- expect(client).to receive(:post).with(anything, { "name" => name }).once.and_call_original
148
+ expect(client).to receive(:post).with(anything, { "name" => name }, {}).once.and_call_original
111
149
  expect(channel.publish(name)).to eql(true)
112
150
  expect(channel.history.items.first.name).to eql(name)
113
151
  expect(channel.history.items.first.data).to be_nil
@@ -118,7 +156,7 @@ describe Ably::Rest::Channel do
118
156
  let(:name) { random_str }
119
157
 
120
158
  it 'publishes the message without any attributes in the payload' do
121
- expect(client).to receive(:post).with(anything, {}).once.and_call_original
159
+ expect(client).to receive(:post).with(anything, {}, {}).once.and_call_original
122
160
  expect(channel.publish(nil)).to eql(true)
123
161
  expect(channel.history.items.first.name).to be_nil
124
162
  expect(channel.history.items.first.data).to be_nil
@@ -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
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.1.2
4
+ version: 1.1.3
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: 2019-08-06 00:00:00.000000000 Z
12
+ date: 2020-12-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -57,16 +57,22 @@ dependencies:
57
57
  name: faraday
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "~>"
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0.12'
63
+ - - "<"
64
+ - !ruby/object:Gem::Version
65
+ version: 2.0.0
63
66
  type: :runtime
64
67
  prerelease: false
65
68
  version_requirements: !ruby/object:Gem::Requirement
66
69
  requirements:
67
- - - "~>"
70
+ - - ">="
68
71
  - !ruby/object:Gem::Version
69
72
  version: '0.12'
73
+ - - "<"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.0
70
76
  - !ruby/object:Gem::Dependency
71
77
  name: excon
72
78
  requirement: !ruby/object:Gem::Requirement
@@ -527,7 +533,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
527
533
  - !ruby/object:Gem::Version
528
534
  version: '0'
529
535
  requirements: []
530
- rubygems_version: 3.0.3
536
+ rubygems_version: 3.1.2
531
537
  signing_key:
532
538
  specification_version: 4
533
539
  summary: A Ruby client library for ably.io realtime messaging implemented using EventMachine