ably-rest 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: e3a45b0f4d3366a78d1eaa428c977ad09ee7f4865c11e2e38ef84c4e3e46601a
4
- data.tar.gz: ec961d83634b624ca147bd391564659c06e9c0ca901bf0437eae61aa6ebdc7f7
3
+ metadata.gz: 2ebbf06f58854a46fb19f1d908463d6f8fbd39807a461cc478443ab03a3abdbc
4
+ data.tar.gz: '035845c681c3672a56b8fa50bbe1bc2508d791c4075914d470d9b521d1074b3a'
5
5
  SHA512:
6
- metadata.gz: 10abe88a9e2c047f946139306afc7d0b3fdd59af0dc778b3e262390a1c1d7c3d8e731faad3b510a2b6d7341117265f69396b662a945fa0e55f9001f7661b8981
7
- data.tar.gz: 2a2769c4d6706950d1f204f3ffe764b5336d1c7710839dc549091db6eacbc0bafc2be5e9f5ac644209778f433c97c0add81378735287108ead5702c1b7480828
6
+ metadata.gz: 7892f515bdc0d7b82f5ee0e4ee64e96cb2a6f69d66bc67f22c7f0de380c516c624585a3e0e22481783438211e785e71d4cc04fb62c971cd976212ba2058e63ab
7
+ data.tar.gz: 985fbbbe7f35c6e03a6f3f900d6d283ae2b4f3b5d041c0abced17463913603dd8fe38aa1ae0e8576d7d9caf1f2508e081ef7e8808ef8a369eff6c4fcf3b7590f
@@ -1,3 +1,3 @@
1
1
  # Change Log
2
2
 
3
- See https://github.com/ably/ably-ruby/blob/master/CHANGELOG.md
3
+ See https://github.com/ably/ably-ruby/blob/main/CHANGELOG.md
data/README.md CHANGED
@@ -158,7 +158,7 @@ Please note that the bulk of this repo is in fact a submodule of the [Ably Ruby
158
158
 
159
159
  ## Release Process
160
160
 
161
- 1. From the master branch, `cd lib/submodules/ably-ruby`
161
+ 1. From the `main` branch, `cd lib/submodules/ably-ruby`
162
162
  2. `git fetch origin && git fetch --tags`
163
163
  3. Reset to the tagged version released in ably-ruby, e.g. `git reset v1.0.5 --hard`
164
164
  4. Ensure submodules of this submodule are up to date (`git submodule update`)
@@ -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)
@@ -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.
@@ -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,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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew O'Riordan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-06 00:00:00.000000000 Z
11
+ date: 2020-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -462,7 +462,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
462
462
  - !ruby/object:Gem::Version
463
463
  version: '0'
464
464
  requirements: []
465
- rubygems_version: 3.0.3
465
+ rubygems_version: 3.1.2
466
466
  signing_key:
467
467
  specification_version: 4
468
468
  summary: A Ruby REST only client library for ably.io realtime messaging