ably-rest 0.7.5 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/.travis.yml +2 -0
- data/README.md +41 -15
- data/SPEC.md +654 -518
- data/lib/submodules/ably-ruby/.gitignore +1 -0
- data/lib/submodules/ably-ruby/.gitmodules +3 -0
- data/lib/submodules/ably-ruby/README.md +54 -26
- data/lib/submodules/ably-ruby/SPEC.md +468 -322
- data/lib/submodules/ably-ruby/ably.gemspec +4 -2
- data/lib/submodules/ably-ruby/lib/ably/auth.rb +185 -131
- data/lib/submodules/ably-ruby/lib/ably/models/message.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/models/paginated_resource.rb +31 -44
- data/lib/submodules/ably-ruby/lib/ably/models/presence_message.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb +1 -2
- data/lib/submodules/ably-ruby/lib/ably/models/stat.rb +67 -24
- data/lib/submodules/ably-ruby/lib/ably/models/stats_types.rb +131 -0
- data/lib/submodules/ably-ruby/lib/ably/models/token_details.rb +101 -0
- data/lib/submodules/ably-ruby/lib/ably/models/token_request.rb +108 -0
- data/lib/submodules/ably-ruby/lib/ably/modules/async_wrapper.rb +3 -2
- data/lib/submodules/ably-ruby/lib/ably/modules/http_helpers.rb +1 -1
- data/lib/submodules/ably-ruby/lib/ably/modules/message_emitter.rb +2 -2
- data/lib/submodules/ably-ruby/lib/ably/realtime.rb +3 -7
- data/lib/submodules/ably-ruby/lib/ably/realtime/channel.rb +32 -5
- data/lib/submodules/ably-ruby/lib/ably/realtime/channel/channel_manager.rb +1 -0
- data/lib/submodules/ably-ruby/lib/ably/realtime/client.rb +4 -8
- data/lib/submodules/ably-ruby/lib/ably/realtime/connection.rb +5 -3
- data/lib/submodules/ably-ruby/lib/ably/realtime/presence.rb +12 -1
- data/lib/submodules/ably-ruby/lib/ably/rest.rb +3 -7
- data/lib/submodules/ably-ruby/lib/ably/rest/channel.rb +13 -10
- data/lib/submodules/ably-ruby/lib/ably/rest/client.rb +19 -20
- data/lib/submodules/ably-ruby/lib/ably/rest/presence.rb +14 -12
- data/lib/submodules/ably-ruby/lib/ably/version.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_history_spec.rb +74 -23
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/channel_spec.rb +3 -3
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/client_spec.rb +18 -18
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_failures_spec.rb +5 -5
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/connection_spec.rb +12 -12
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/message_spec.rb +5 -5
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_history_spec.rb +56 -13
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb +8 -8
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/stats_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/realtime/time_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/rest/auth_spec.rb +262 -158
- data/lib/submodules/ably-ruby/spec/acceptance/rest/base_spec.rb +11 -9
- data/lib/submodules/ably-ruby/spec/acceptance/rest/channel_spec.rb +28 -21
- data/lib/submodules/ably-ruby/spec/acceptance/rest/channels_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/rest/client_spec.rb +30 -27
- data/lib/submodules/ably-ruby/spec/acceptance/rest/encoders_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/acceptance/rest/message_spec.rb +10 -10
- data/lib/submodules/ably-ruby/spec/acceptance/rest/presence_spec.rb +93 -56
- data/lib/submodules/ably-ruby/spec/acceptance/rest/stats_spec.rb +50 -45
- data/lib/submodules/ably-ruby/spec/acceptance/rest/time_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/rspec_config.rb +3 -2
- data/lib/submodules/ably-ruby/spec/shared/client_initializer_behaviour.rb +36 -28
- data/lib/submodules/ably-ruby/spec/spec_helper.rb +3 -0
- data/lib/submodules/ably-ruby/spec/support/api_helper.rb +3 -3
- data/lib/submodules/ably-ruby/spec/support/markdown_spec_formatter.rb +1 -1
- data/lib/submodules/ably-ruby/spec/support/test_app.rb +20 -33
- data/lib/submodules/ably-ruby/spec/unit/auth_spec.rb +18 -1
- data/lib/submodules/ably-ruby/spec/unit/models/paginated_resource_spec.rb +81 -72
- data/lib/submodules/ably-ruby/spec/unit/models/stats_spec.rb +289 -0
- data/lib/submodules/ably-ruby/spec/unit/models/token_details_spec.rb +111 -0
- data/lib/submodules/ably-ruby/spec/unit/models/token_request_spec.rb +110 -0
- data/lib/submodules/ably-ruby/spec/unit/modules/async_wrapper_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/unit/realtime/client_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/unit/realtime/realtime_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/unit/rest/channel_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/unit/rest/client_spec.rb +8 -8
- data/lib/submodules/ably-ruby/spec/unit/rest/rest_spec.rb +1 -1
- data/lib/submodules/ably-ruby/spec/unit/util/crypto_spec.rb +1 -1
- metadata +9 -7
- data/lib/submodules/ably-ruby/lib/ably/models/token.rb +0 -74
- data/lib/submodules/ably-ruby/spec/resources/crypto-data-128.json +0 -56
- data/lib/submodules/ably-ruby/spec/resources/crypto-data-256.json +0 -56
- data/lib/submodules/ably-ruby/spec/unit/models/stat_spec.rb +0 -113
- data/lib/submodules/ably-ruby/spec/unit/models/token_spec.rb +0 -86
|
@@ -23,10 +23,6 @@ module Ably
|
|
|
23
23
|
# @param (see Ably::Rest::Client#initialize)
|
|
24
24
|
# @option options (see Ably::Rest::Client#initialize)
|
|
25
25
|
#
|
|
26
|
-
# @yield (see Ably::Rest::Client#initialize)
|
|
27
|
-
# @yieldparam (see Ably::Rest::Client#initialize)
|
|
28
|
-
# @yieldreturn (see Ably::Rest::Client#initialize)
|
|
29
|
-
#
|
|
30
26
|
# @return [Ably::Rest::Client]
|
|
31
27
|
#
|
|
32
28
|
# @example
|
|
@@ -34,10 +30,10 @@ module Ably
|
|
|
34
30
|
# client = Ably::Rest.new('key.id:secret')
|
|
35
31
|
#
|
|
36
32
|
# # create a new client authenticating with basic auth and a client_id
|
|
37
|
-
# client = Ably::Rest.new(
|
|
33
|
+
# client = Ably::Rest.new(key: 'key.id:secret', client_id: 'john')
|
|
38
34
|
#
|
|
39
|
-
def self.new(options
|
|
40
|
-
Ably::Rest::Client.new(options
|
|
35
|
+
def self.new(options)
|
|
36
|
+
Ably::Rest::Client.new(options)
|
|
41
37
|
end
|
|
42
38
|
end
|
|
43
39
|
end
|
|
@@ -20,7 +20,7 @@ module Ably
|
|
|
20
20
|
# @param name [String] The name of the channel
|
|
21
21
|
# @param channel_options [Hash] Channel options, currently reserved for Encryption options
|
|
22
22
|
# @option channel_options [Boolean] :encrypted setting this to true for this channel will encrypt & decrypt all messages automatically
|
|
23
|
-
# @option channel_options [Hash] :cipher_params A hash of options to configure the encryption. *:key* is required, all other options are optional. See {Ably::Util::Crypto#initialize} for a list of
|
|
23
|
+
# @option channel_options [Hash] :cipher_params A hash of options to configure the encryption. *:key* is required, all other options are optional. See {Ably::Util::Crypto#initialize} for a list of +cipher_params+ options
|
|
24
24
|
#
|
|
25
25
|
def initialize(client, name, channel_options = {})
|
|
26
26
|
ensure_utf_8 :name, name
|
|
@@ -52,19 +52,22 @@ module Ably
|
|
|
52
52
|
[201, 204].include?(response.status)
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
# Return the message
|
|
55
|
+
# Return the message of the channel
|
|
56
56
|
#
|
|
57
|
-
# @param [Hash] options
|
|
58
|
-
# @option options [Integer,Time] :start
|
|
59
|
-
# @option options [Integer,Time] :end
|
|
60
|
-
# @option options [Symbol] :direction
|
|
61
|
-
# @option options [Integer] :limit Maximum number of messages to retrieve up to
|
|
62
|
-
#
|
|
57
|
+
# @param [Hash] options the options for the message history request
|
|
58
|
+
# @option options [Integer,Time] :start Ensure earliest time or millisecond since epoch for any messages retrieved is +:start+
|
|
59
|
+
# @option options [Integer,Time] :end Ensure latest time or millisecond since epoch for any messages retrieved is +:end+
|
|
60
|
+
# @option options [Symbol] :direction +:forwards+ or +:backwards+, defaults to +:backwards+
|
|
61
|
+
# @option options [Integer] :limit Maximum number of messages to retrieve up to 1,000, defaults to 100
|
|
62
|
+
#
|
|
63
|
+
# @return [Ably::Models::PaginatedResource<Ably::Models::Message>] First {Ably::Models::PaginatedResource page} of {Ably::Models::Message} objects accessible with {Ably::Models::PaginatedResource#items #items}.
|
|
63
64
|
#
|
|
64
|
-
# @return [Ably::Models::PaginatedResource<Ably::Models::Message>] An Array of {Ably::Models::Message} objects that supports paging (#next_page, #first_page)
|
|
65
65
|
def history(options = {})
|
|
66
66
|
url = "#{base_path}/messages"
|
|
67
|
-
options =
|
|
67
|
+
options = {
|
|
68
|
+
:direction => :backwards,
|
|
69
|
+
:limit => 100
|
|
70
|
+
}.merge(options)
|
|
68
71
|
|
|
69
72
|
[:start, :end].each { |option| options[option] = as_since_epoch(options[option]) if options.has_key?(option) }
|
|
70
73
|
|
|
@@ -70,18 +70,16 @@ module Ably
|
|
|
70
70
|
# @param [Hash,String] options an options Hash used to configure the client and the authentication, or String with an API key or Token ID
|
|
71
71
|
# @option options (see Ably::Auth#authorise)
|
|
72
72
|
# @option options [Boolean] :tls TLS is used by default, providing a value of false disables TLS. Please note Basic Auth is disallowed without TLS as secrets cannot be transmitted over unsecured connections.
|
|
73
|
-
# @option options [String] :
|
|
74
|
-
# @option options [
|
|
73
|
+
# @option options [String] :key API key comprising the key name and key secret in a single string
|
|
74
|
+
# @option options [String] :token Token string or {Models::TokenDetails} used to authenticate requests
|
|
75
|
+
# @option options [String] :token_details {Models::TokenDetails} used to authenticate requests
|
|
76
|
+
# @option options [Boolean] :use_token_auth Will force Basic Auth if set to false, and Token auth if set to true
|
|
75
77
|
# @option options [String] :environment Specify 'sandbox' when testing the client library against an alternate Ably environment
|
|
76
78
|
# @option options [Symbol] :protocol Protocol used to communicate with Ably, :json and :msgpack currently supported. Defaults to :msgpack
|
|
77
79
|
# @option options [Boolean] :use_binary_protocol Protocol used to communicate with Ably, defaults to true and uses MessagePack protocol. This option will overide :protocol option
|
|
78
80
|
# @option options [Logger::Severity,Symbol] :log_level Log level for the standard Logger that outputs to STDOUT. Defaults to Logger::ERROR, can be set to :fatal (Logger::FATAL), :error (Logger::ERROR), :warn (Logger::WARN), :info (Logger::INFO), :debug (Logger::DEBUG) or :none
|
|
79
81
|
# @option options [Logger] :logger A custom logger can be used however it must adhere to the Ruby Logger interface, see http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html
|
|
80
82
|
#
|
|
81
|
-
# @yield (see Ably::Auth#authorise)
|
|
82
|
-
# @yieldparam (see Ably::Auth#authorise)
|
|
83
|
-
# @yieldreturn (see Ably::Auth#authorise)
|
|
84
|
-
#
|
|
85
83
|
# @return [Ably::Rest::Client]
|
|
86
84
|
#
|
|
87
85
|
# @example
|
|
@@ -89,17 +87,17 @@ module Ably
|
|
|
89
87
|
# client = Ably::Rest::Client.new('key.id:secret')
|
|
90
88
|
#
|
|
91
89
|
# # create a new client and configure a client ID used for presence
|
|
92
|
-
# client = Ably::Rest::Client.new(
|
|
90
|
+
# client = Ably::Rest::Client.new(key: 'key.id:secret', client_id: 'john')
|
|
93
91
|
#
|
|
94
|
-
def initialize(options
|
|
92
|
+
def initialize(options)
|
|
95
93
|
raise ArgumentError, 'Options Hash is expected' if options.nil?
|
|
96
94
|
|
|
97
95
|
options = options.clone
|
|
98
96
|
if options.kind_of?(String)
|
|
99
97
|
options = if options.match(/^[\w]{2,}\.[\w]{2,}:[\w]{2,}$/)
|
|
100
|
-
{
|
|
98
|
+
{ key: options }
|
|
101
99
|
else
|
|
102
|
-
{
|
|
100
|
+
{ token: options }
|
|
103
101
|
end
|
|
104
102
|
end
|
|
105
103
|
|
|
@@ -127,7 +125,7 @@ module Ably
|
|
|
127
125
|
raise ArgumentError, 'Protocol is invalid. Must be either :msgpack or :json' unless [:msgpack, :json].include?(@protocol)
|
|
128
126
|
|
|
129
127
|
@options = options.freeze
|
|
130
|
-
@auth = Auth.new(self, options
|
|
128
|
+
@auth = Auth.new(self, options)
|
|
131
129
|
@channels = Ably::Rest::Channels.new(self)
|
|
132
130
|
@encoders = []
|
|
133
131
|
|
|
@@ -146,24 +144,25 @@ module Ably
|
|
|
146
144
|
# Retrieve the Stats for the application
|
|
147
145
|
#
|
|
148
146
|
# @param [Hash] options the options for the stats request
|
|
149
|
-
# @option options [Integer,Time] :start
|
|
150
|
-
# @option options [Integer,Time] :end
|
|
151
|
-
# @option options [Symbol] :direction
|
|
152
|
-
# @option options [Integer] :limit Maximum number of
|
|
153
|
-
# @option options [Symbol] :
|
|
147
|
+
# @option options [Integer,Time] :start Ensure earliest time or millisecond since epoch for any stats retrieved is +:start+
|
|
148
|
+
# @option options [Integer,Time] :end Ensure latest time or millisecond since epoch for any stats retrieved is +:end+
|
|
149
|
+
# @option options [Symbol] :direction +:forwards+ or +:backwards+, defaults to +:backwards+
|
|
150
|
+
# @option options [Integer] :limit Maximum number of messages to retrieve up to 1,000, defaults to 100
|
|
151
|
+
# @option options [Symbol] :unit `:minute`, `:hour`, `:day` or `:month`. Defaults to `:minute`
|
|
154
152
|
#
|
|
155
|
-
# @return [Ably::Models::PaginatedResource<Ably::Models::
|
|
153
|
+
# @return [Ably::Models::PaginatedResource<Ably::Models::Stats>] An Array of Stats
|
|
156
154
|
#
|
|
157
155
|
def stats(options = {})
|
|
158
156
|
options = {
|
|
159
|
-
:direction => :
|
|
160
|
-
:
|
|
157
|
+
:direction => :backwards,
|
|
158
|
+
:unit => :minute,
|
|
159
|
+
:limit => 100
|
|
161
160
|
}.merge(options)
|
|
162
161
|
|
|
163
162
|
[:start, :end].each { |option| options[option] = as_since_epoch(options[option]) if options.has_key?(option) }
|
|
164
163
|
|
|
165
164
|
paginated_options = {
|
|
166
|
-
coerce_into: 'Ably::Models::
|
|
165
|
+
coerce_into: 'Ably::Models::Stats'
|
|
167
166
|
}
|
|
168
167
|
|
|
169
168
|
url = '/stats'
|
|
@@ -23,15 +23,14 @@ module Ably
|
|
|
23
23
|
# Obtain the set of members currently present for a channel
|
|
24
24
|
#
|
|
25
25
|
# @param [Hash] options the options for the set of members present
|
|
26
|
-
# @option options [Integer
|
|
27
|
-
# @option options [Integer,Time] :end Time or millisecond since epoch
|
|
28
|
-
# @option options [Symbol] :direction `:forwards` or `:backwards`
|
|
29
|
-
# @option options [Integer] :limit Maximum number of members to retrieve up to 10,000
|
|
26
|
+
# @option options [Integer] :limit Maximum number of members to retrieve up to 1,000, defaults to 100
|
|
30
27
|
#
|
|
31
|
-
# @return [Ably::Models::PaginatedResource<Ably::Models::PresenceMessage>]
|
|
28
|
+
# @return [Ably::Models::PaginatedResource<Ably::Models::PresenceMessage>] First {Ably::Models::PaginatedResource page} of {Ably::Models::PresenceMessage} objects accessible with {Ably::Models::PaginatedResource#items #items}.
|
|
32
29
|
#
|
|
33
30
|
def get(options = {})
|
|
34
|
-
options = options
|
|
31
|
+
options = options = {
|
|
32
|
+
:limit => 100
|
|
33
|
+
}.merge(options)
|
|
35
34
|
|
|
36
35
|
paginated_options = {
|
|
37
36
|
coerce_into: 'Ably::Models::PresenceMessage',
|
|
@@ -50,16 +49,19 @@ module Ably
|
|
|
50
49
|
# Return the presence messages history for the channel
|
|
51
50
|
#
|
|
52
51
|
# @param [Hash] options the options for the message history request
|
|
53
|
-
# @option options [Integer,Time] :start
|
|
54
|
-
# @option options [Integer,Time] :end
|
|
55
|
-
# @option options [Symbol] :direction
|
|
56
|
-
# @option options [Integer] :limit Maximum number of
|
|
52
|
+
# @option options [Integer,Time] :start Ensure earliest time or millisecond since epoch for any presence messages retrieved is +:start+
|
|
53
|
+
# @option options [Integer,Time] :end Ensure latest time or millisecond since epoch for any presence messages retrieved is +:end+
|
|
54
|
+
# @option options [Symbol] :direction +:forwards+ or +:backwards+, defaults to +:backwards+
|
|
55
|
+
# @option options [Integer] :limit Maximum number of messages to retrieve up to 1,000, defaults to 100
|
|
57
56
|
#
|
|
58
|
-
# @return [Ably::Models::PaginatedResource<Ably::Models::PresenceMessage>]
|
|
57
|
+
# @return [Ably::Models::PaginatedResource<Ably::Models::PresenceMessage>] First {Ably::Models::PaginatedResource page} of {Ably::Models::PresenceMessage} objects accessible with {Ably::Models::PaginatedResource#items #items}.
|
|
59
58
|
#
|
|
60
59
|
def history(options = {})
|
|
61
60
|
url = "#{base_path}/history"
|
|
62
|
-
options = options
|
|
61
|
+
options = options = {
|
|
62
|
+
:direction => :backwards,
|
|
63
|
+
:limit => 100
|
|
64
|
+
}.merge(options)
|
|
63
65
|
|
|
64
66
|
[:start, :end].each { |option| options[option] = as_since_epoch(options[option]) if options.has_key?(option) }
|
|
65
67
|
|
|
@@ -3,10 +3,11 @@ require 'spec_helper'
|
|
|
3
3
|
|
|
4
4
|
describe Ably::Realtime::Channel, '#history', :event_machine do
|
|
5
5
|
vary_by_protocol do
|
|
6
|
-
let(:default_options) { options.merge(
|
|
6
|
+
let(:default_options) { options.merge(key: api_key, environment: environment, protocol: protocol) }
|
|
7
7
|
|
|
8
8
|
let(:client) { Ably::Realtime::Client.new(default_options) }
|
|
9
9
|
let(:channel) { client.channel(channel_name) }
|
|
10
|
+
let(:rest_channel) { client.rest_client.channel(channel_name) }
|
|
10
11
|
|
|
11
12
|
let(:client2) { Ably::Realtime::Client.new(default_options) }
|
|
12
13
|
let(:channel2) { client2.channel(channel_name) }
|
|
@@ -21,20 +22,20 @@ describe Ably::Realtime::Channel, '#history', :event_machine do
|
|
|
21
22
|
channel.publish('event', payload) do |message|
|
|
22
23
|
history = channel.history
|
|
23
24
|
expect(history).to be_a(Ably::Util::SafeDeferrable)
|
|
24
|
-
history.callback do |
|
|
25
|
-
expect(
|
|
26
|
-
expect(
|
|
25
|
+
history.callback do |page|
|
|
26
|
+
expect(page.items.count).to eql(1)
|
|
27
|
+
expect(page).to be_a(Ably::Models::PaginatedResource)
|
|
27
28
|
stop_reactor
|
|
28
29
|
end
|
|
29
30
|
end
|
|
30
31
|
end
|
|
31
32
|
|
|
32
33
|
context 'with a single client publishing and receiving' do
|
|
33
|
-
it 'retrieves
|
|
34
|
+
it 'retrieves realtime history' do
|
|
34
35
|
channel.publish('event', payload) do |message|
|
|
35
|
-
channel.history do |
|
|
36
|
-
expect(
|
|
37
|
-
expect(
|
|
36
|
+
channel.history do |page|
|
|
37
|
+
expect(page.items.length).to eql(1)
|
|
38
|
+
expect(page.items[0].data).to eql(payload)
|
|
38
39
|
stop_reactor
|
|
39
40
|
end
|
|
40
41
|
end
|
|
@@ -42,15 +43,15 @@ describe Ably::Realtime::Channel, '#history', :event_machine do
|
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
context 'with two clients publishing messages on the same channel' do
|
|
45
|
-
it 'retrieves
|
|
46
|
+
it 'retrieves realtime history on both channels' do
|
|
46
47
|
channel.publish('event', payload) do |message|
|
|
47
48
|
channel2.publish('event', payload) do |message|
|
|
48
|
-
channel.history do |
|
|
49
|
-
expect(
|
|
50
|
-
expect(
|
|
49
|
+
channel.history do |page|
|
|
50
|
+
expect(page.items.length).to eql(2)
|
|
51
|
+
expect(page.items.map(&:data).uniq).to eql([payload])
|
|
51
52
|
|
|
52
|
-
channel2.history do |
|
|
53
|
-
expect(
|
|
53
|
+
channel2.history do |page_2|
|
|
54
|
+
expect(page_2.items.length).to eql(2)
|
|
54
55
|
stop_reactor
|
|
55
56
|
end
|
|
56
57
|
end
|
|
@@ -65,18 +66,18 @@ describe Ably::Realtime::Channel, '#history', :event_machine do
|
|
|
65
66
|
let(:limit) { 15 }
|
|
66
67
|
|
|
67
68
|
def ensure_message_history_direction_and_paging_is_correct(direction)
|
|
68
|
-
channel.history(direction: direction, limit: limit) do |
|
|
69
|
-
expect(
|
|
69
|
+
channel.history(direction: direction, limit: limit) do |history_page|
|
|
70
|
+
expect(history_page.items.length).to eql(limit)
|
|
70
71
|
limit.times do |index|
|
|
71
|
-
expect(
|
|
72
|
+
expect(history_page.items[index].data).to eql("history#{index}")
|
|
72
73
|
end
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
expect(
|
|
75
|
+
history_page.next do |next_page|
|
|
76
|
+
expect(next_page.items.length).to eql(limit)
|
|
76
77
|
limit.times do |index|
|
|
77
|
-
expect(
|
|
78
|
+
expect(next_page.items[index].data).to eql("history#{index + limit}")
|
|
78
79
|
end
|
|
79
|
-
expect(
|
|
80
|
+
expect(next_page).to be_last
|
|
80
81
|
|
|
81
82
|
stop_reactor
|
|
82
83
|
end
|
|
@@ -141,8 +142,8 @@ describe Ably::Realtime::Channel, '#history', :event_machine do
|
|
|
141
142
|
channel.subscribe('event') do |message|
|
|
142
143
|
messages << message
|
|
143
144
|
if messages.count == batches * messages_per_batch
|
|
144
|
-
channel.history do |
|
|
145
|
-
expect(
|
|
145
|
+
channel.history do |page|
|
|
146
|
+
expect(page.items.map(&:id).sort).to eql(messages.map(&:id).sort)
|
|
146
147
|
stop_reactor
|
|
147
148
|
end
|
|
148
149
|
end
|
|
@@ -150,5 +151,55 @@ describe Ably::Realtime::Channel, '#history', :event_machine do
|
|
|
150
151
|
end
|
|
151
152
|
end
|
|
152
153
|
end
|
|
154
|
+
|
|
155
|
+
context 'with option until_attach: true' do
|
|
156
|
+
let(:event) { random_str }
|
|
157
|
+
let(:message_before_attach) { random_str }
|
|
158
|
+
let(:message_after_attach) { random_str }
|
|
159
|
+
|
|
160
|
+
it 'retrieves all messages before channel was attached' do
|
|
161
|
+
rest_channel.publish event, message_before_attach
|
|
162
|
+
|
|
163
|
+
channel.attach do
|
|
164
|
+
channel.publish(event, message_after_attach) do
|
|
165
|
+
channel.history(until_attach: true) do |messages|
|
|
166
|
+
expect(messages.items.count).to eql(1)
|
|
167
|
+
expect(messages.items.first.data).to eql(message_before_attach)
|
|
168
|
+
stop_reactor
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
context 'and two pages of messages' do
|
|
175
|
+
it 'retrieves two pages of messages before channel was attached' do
|
|
176
|
+
10.times { rest_channel.publish event, message_before_attach }
|
|
177
|
+
|
|
178
|
+
channel.attach do
|
|
179
|
+
10.times { rest_channel.publish event, message_after_attach }
|
|
180
|
+
|
|
181
|
+
EventMachine.add_timer(0.5) do
|
|
182
|
+
channel.history(until_attach: true, limit: 5) do |messages|
|
|
183
|
+
expect(messages.items.count).to eql(5)
|
|
184
|
+
expect(messages.items.map(&:data).uniq.first).to eql(message_before_attach)
|
|
185
|
+
|
|
186
|
+
messages.next do |next_page_messages|
|
|
187
|
+
expect(next_page_messages.items.count).to eql(5)
|
|
188
|
+
expect(next_page_messages.items.map(&:data).uniq.first).to eql(message_before_attach)
|
|
189
|
+
expect(next_page_messages).to be_last
|
|
190
|
+
|
|
191
|
+
stop_reactor
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
it 'raises an exception unless state is attached' do
|
|
200
|
+
expect { channel.history(until_attach: true) }.to raise_error(ArgumentError, /not attached/)
|
|
201
|
+
stop_reactor
|
|
202
|
+
end
|
|
203
|
+
end
|
|
153
204
|
end
|
|
154
205
|
end
|
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
|
3
3
|
|
|
4
4
|
describe Ably::Realtime::Channel, :event_machine do
|
|
5
5
|
vary_by_protocol do
|
|
6
|
-
let(:default_options) { {
|
|
6
|
+
let(:default_options) { { key: api_key, environment: environment, protocol: protocol } }
|
|
7
7
|
let(:client_options) { default_options }
|
|
8
8
|
|
|
9
9
|
let(:client) { Ably::Realtime::Client.new(client_options) }
|
|
@@ -158,7 +158,7 @@ describe Ably::Realtime::Channel, :event_machine do
|
|
|
158
158
|
|
|
159
159
|
context 'failure as a result of insufficient key permissions' do
|
|
160
160
|
let(:restricted_client) do
|
|
161
|
-
Ably::Realtime::Client.new(default_options.merge(
|
|
161
|
+
Ably::Realtime::Client.new(default_options.merge(key: restricted_api_key, log_level: :fatal))
|
|
162
162
|
end
|
|
163
163
|
let(:restricted_channel) { restricted_client.channel("cannot_subscribe") }
|
|
164
164
|
|
|
@@ -202,7 +202,7 @@ describe Ably::Realtime::Channel, :event_machine do
|
|
|
202
202
|
restricted_channel.once(:failed) do
|
|
203
203
|
restricted_client.close do
|
|
204
204
|
# A direct call to #authorise is synchronous
|
|
205
|
-
restricted_client.auth.authorise(
|
|
205
|
+
restricted_client.auth.authorise(key: api_key)
|
|
206
206
|
|
|
207
207
|
restricted_client.connect do
|
|
208
208
|
restricted_channel.once(:attached) do
|
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
|
4
4
|
describe Ably::Realtime::Client, :event_machine do
|
|
5
5
|
vary_by_protocol do
|
|
6
6
|
let(:default_options) do
|
|
7
|
-
{
|
|
7
|
+
{ key: api_key, environment: environment, protocol: protocol }
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
let(:client_options) { default_options }
|
|
@@ -15,11 +15,11 @@ describe Ably::Realtime::Client, :event_machine do
|
|
|
15
15
|
|
|
16
16
|
context 'initialization' do
|
|
17
17
|
context 'basic auth' do
|
|
18
|
-
it 'is enabled by default with a provided :
|
|
18
|
+
it 'is enabled by default with a provided :key option' do
|
|
19
19
|
connection.on(:connected) do
|
|
20
|
-
expect(auth_params[:
|
|
20
|
+
expect(auth_params[:key]).to_not be_nil
|
|
21
21
|
expect(auth_params[:access_token]).to be_nil
|
|
22
|
-
expect(subject.auth.
|
|
22
|
+
expect(subject.auth.current_token_details).to be_nil
|
|
23
23
|
stop_reactor
|
|
24
24
|
end
|
|
25
25
|
end
|
|
@@ -44,26 +44,26 @@ describe Ably::Realtime::Client, :event_machine do
|
|
|
44
44
|
[true, false].each do |tls_enabled|
|
|
45
45
|
context "with TLS #{tls_enabled ? 'enabled' : 'disabled'}" do
|
|
46
46
|
let(:capability) { { :foo => ["publish"] } }
|
|
47
|
-
let(:
|
|
48
|
-
let(:client_options) { default_options.merge(
|
|
47
|
+
let(:token_details) { Ably::Realtime::Client.new(default_options).auth.request_token(capability: capability) }
|
|
48
|
+
let(:client_options) { default_options.merge(token: token_details.token) }
|
|
49
49
|
|
|
50
|
-
context 'and a pre-generated Token provided with the :
|
|
50
|
+
context 'and a pre-generated Token provided with the :token option' do
|
|
51
51
|
it 'connects using token auth' do
|
|
52
52
|
connection.on(:connected) do
|
|
53
53
|
expect(auth_params[:access_token]).to_not be_nil
|
|
54
|
-
expect(auth_params[:
|
|
55
|
-
expect(subject.auth.
|
|
54
|
+
expect(auth_params[:key]).to be_nil
|
|
55
|
+
expect(subject.auth.current_token_details).to be_nil
|
|
56
56
|
stop_reactor
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
context 'with valid :
|
|
61
|
+
context 'with valid :key and :use_token_auth option set to true' do
|
|
62
62
|
let(:client_options) { default_options.merge(use_token_auth: true) }
|
|
63
63
|
|
|
64
64
|
it 'automatically authorises on connect and generates a token' do
|
|
65
65
|
connection.on(:connected) do
|
|
66
|
-
expect(subject.auth.
|
|
66
|
+
expect(subject.auth.current_token_details).to_not be_nil
|
|
67
67
|
expect(auth_params[:access_token]).to_not be_nil
|
|
68
68
|
stop_reactor
|
|
69
69
|
end
|
|
@@ -79,7 +79,7 @@ describe Ably::Realtime::Client, :event_machine do
|
|
|
79
79
|
connection.on(:connected) do
|
|
80
80
|
expect(connection.state).to eq(:connected)
|
|
81
81
|
expect(auth_params[:access_token]).to_not be_nil
|
|
82
|
-
expect(auth_params[:
|
|
82
|
+
expect(auth_params[:key]).to be_nil
|
|
83
83
|
stop_reactor
|
|
84
84
|
end
|
|
85
85
|
end
|
|
@@ -88,27 +88,27 @@ describe Ably::Realtime::Client, :event_machine do
|
|
|
88
88
|
end
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
-
context 'with
|
|
91
|
+
context 'with a Proc for the :auth_callback option' do
|
|
92
92
|
let(:client_id) { random_str }
|
|
93
93
|
let(:auth) { subject.auth }
|
|
94
94
|
|
|
95
95
|
subject do
|
|
96
|
-
Ably::Realtime::Client.new(client_options
|
|
96
|
+
Ably::Realtime::Client.new(client_options.merge(auth_callback: Proc.new do
|
|
97
97
|
@block_called = true
|
|
98
98
|
auth.create_token_request(client_id: client_id)
|
|
99
|
-
end
|
|
99
|
+
end))
|
|
100
100
|
end
|
|
101
101
|
|
|
102
|
-
it 'calls the
|
|
102
|
+
it 'calls the Proc' do
|
|
103
103
|
connection.on(:connected) do
|
|
104
104
|
expect(@block_called).to eql(true)
|
|
105
105
|
stop_reactor
|
|
106
106
|
end
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
-
it 'uses the token request when requesting a new token' do
|
|
109
|
+
it 'uses the token request returned from the callback when requesting a new token' do
|
|
110
110
|
connection.on(:connected) do
|
|
111
|
-
expect(auth.
|
|
111
|
+
expect(auth.current_token_details.client_id).to eql(client_id)
|
|
112
112
|
stop_reactor
|
|
113
113
|
end
|
|
114
114
|
end
|