ably 0.7.6 → 0.8.0
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 +4 -4
- data/README.md +11 -7
- data/SPEC.md +310 -269
- data/lib/ably/auth.rb +177 -127
- data/lib/ably/models/presence_message.rb +1 -1
- data/lib/ably/models/protocol_message.rb +1 -2
- data/lib/ably/models/token_details.rb +101 -0
- data/lib/ably/models/token_request.rb +108 -0
- data/lib/ably/modules/http_helpers.rb +1 -1
- data/lib/ably/realtime.rb +2 -6
- data/lib/ably/realtime/channel.rb +14 -8
- data/lib/ably/realtime/client.rb +2 -6
- data/lib/ably/realtime/connection.rb +4 -2
- data/lib/ably/rest.rb +2 -6
- data/lib/ably/rest/channel.rb +10 -6
- data/lib/ably/rest/client.rb +15 -16
- data/lib/ably/rest/presence.rb +12 -10
- data/lib/ably/version.rb +1 -1
- data/spec/acceptance/realtime/client_spec.rb +15 -15
- data/spec/acceptance/realtime/connection_failures_spec.rb +3 -3
- data/spec/acceptance/realtime/connection_spec.rb +9 -9
- data/spec/acceptance/rest/auth_spec.rb +248 -172
- data/spec/acceptance/rest/base_spec.rb +8 -6
- data/spec/acceptance/rest/channel_spec.rb +9 -2
- data/spec/acceptance/rest/client_spec.rb +21 -21
- data/spec/acceptance/rest/presence_spec.rb +12 -5
- data/spec/acceptance/rest/stats_spec.rb +4 -4
- data/spec/rspec_config.rb +3 -2
- data/spec/shared/client_initializer_behaviour.rb +21 -24
- data/spec/support/api_helper.rb +3 -3
- data/spec/support/test_app.rb +9 -9
- data/spec/unit/auth_spec.rb +17 -0
- data/spec/unit/models/token_details_spec.rb +111 -0
- data/spec/unit/models/token_request_spec.rb +110 -0
- data/spec/unit/rest/client_spec.rb +1 -1
- metadata +8 -5
- data/lib/ably/models/token.rb +0 -74
- data/spec/unit/models/token_spec.rb +0 -86
@@ -30,7 +30,7 @@ module Ably::Models
|
|
30
30
|
# @!attribute [r] data
|
31
31
|
# @return [Object] Optional client-defined status or other event payload associated with this state
|
32
32
|
# @!attribute [r] encoding
|
33
|
-
# @return [
|
33
|
+
# @return [String] The encoding for the message data. Encoding and decoding of messages is handled automatically by the client library.
|
34
34
|
# Therefore, the `encoding` attribute should always be nil unless an Ably library decoding error has occurred.
|
35
35
|
# @!attribute [r] timestamp
|
36
36
|
# @return [Time] Timestamp when the message was received by the Ably the realtime service
|
@@ -31,7 +31,7 @@ module Ably::Models
|
|
31
31
|
# @!attribute [r] presence
|
32
32
|
# @return [PresenceMessage] A {ProtocolMessage} with a `:presence` action contains one or more presence updates belonging to a channel
|
33
33
|
# @!attribute [r] flags
|
34
|
-
# @return [Integer] Flags
|
34
|
+
# @return [Integer] Flags indicating special ProtocolMessage states
|
35
35
|
# @!attribute [r] hash
|
36
36
|
# @return [Hash] Access the protocol message Hash object ruby'fied to use symbolized keys
|
37
37
|
#
|
@@ -170,7 +170,6 @@ module Ably::Models
|
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
-
# Flags as bits
|
174
173
|
def flags
|
175
174
|
Integer(hash[:flags])
|
176
175
|
rescue TypeError
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Ably::Models
|
2
|
+
# Convert token details argument to a {TokenDetails} object
|
3
|
+
#
|
4
|
+
# @param attributes [TokenDetails,Hash] A {TokenDetails} object or Hash of token and meta data attributes
|
5
|
+
# @option attributes (see TokenDetails#initialize)
|
6
|
+
#
|
7
|
+
# @return [TokenDetails]
|
8
|
+
def self.TokenDetails(attributes)
|
9
|
+
case attributes
|
10
|
+
when TokenDetails
|
11
|
+
return attributes
|
12
|
+
else
|
13
|
+
TokenDetails.new(attributes)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# TokenDetails is a class providing details of the token string and the token's associated metadata,
|
18
|
+
# constructed from the response from Ably when request in a token via the REST API.
|
19
|
+
#
|
20
|
+
# Ruby {Time} objects are supported in place of Ably ms since epoch time fields. However, if a numeric is provided
|
21
|
+
# it must always be expressed in milliseconds as the Ably API always uses milliseconds for time fields.
|
22
|
+
#
|
23
|
+
class TokenDetails
|
24
|
+
include Ably::Modules::ModelCommon
|
25
|
+
|
26
|
+
# Buffer in seconds before a token is considered unusable
|
27
|
+
# For example, if buffer is 10s, the token can no longer be used for new requests 9s before it expires
|
28
|
+
TOKEN_EXPIRY_BUFFER = 5
|
29
|
+
|
30
|
+
def initialize(attributes)
|
31
|
+
@hash_object = IdiomaticRubyWrapper(attributes.clone.freeze)
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param attributes
|
35
|
+
# @option attributes [String] :token token used to authenticate requests
|
36
|
+
# @option attributes [String] :key_name API key name used to create this token
|
37
|
+
# @option attributes [Time,Integer] :issued Time the token was issued as Time or Integer in milliseconds
|
38
|
+
# @option attributes [Time,Integer] :expires Time the token expires as Time or Integer in milliseconds
|
39
|
+
# @option attributes [String] :capability JSON stringified capabilities assigned to this token
|
40
|
+
# @option attributes [String] :client_id client ID assigned to this token
|
41
|
+
#
|
42
|
+
def initialize(attributes = {})
|
43
|
+
@hash_object = IdiomaticRubyWrapper(attributes.clone)
|
44
|
+
|
45
|
+
%w(issued expires).map(&:to_sym).each do |time_attribute|
|
46
|
+
hash[time_attribute] = (hash[time_attribute].to_f * 1000).round if hash[time_attribute].kind_of?(Time)
|
47
|
+
end
|
48
|
+
|
49
|
+
hash.freeze
|
50
|
+
end
|
51
|
+
|
52
|
+
# @!attribute [r] token
|
53
|
+
# @return [String] Token used to authenticate requests
|
54
|
+
def token
|
55
|
+
hash.fetch(:token)
|
56
|
+
end
|
57
|
+
|
58
|
+
# @!attribute [r] key_name
|
59
|
+
# @return [String] API key name used to create this token. An API key is made up of an API key name and secret delimited by a +:+
|
60
|
+
def key_name
|
61
|
+
hash.fetch(:key_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
# @!attribute [r] issued
|
65
|
+
# @return [Time] Time the token was issued
|
66
|
+
def issued
|
67
|
+
as_time_from_epoch(hash.fetch(:issued), granularity: :ms)
|
68
|
+
end
|
69
|
+
|
70
|
+
# @!attribute [r] expires
|
71
|
+
# @return [Time] Time the token expires
|
72
|
+
def expires
|
73
|
+
as_time_from_epoch(hash.fetch(:expires), granularity: :ms)
|
74
|
+
end
|
75
|
+
|
76
|
+
# @!attribute [r] capability
|
77
|
+
# @return [Hash] Capabilities assigned to this token
|
78
|
+
def capability
|
79
|
+
JSON.parse(hash.fetch(:capability))
|
80
|
+
end
|
81
|
+
|
82
|
+
# @!attribute [r] client_id
|
83
|
+
# @return [String] Optional client ID assigned to this token
|
84
|
+
def client_id
|
85
|
+
hash[:client_id]
|
86
|
+
end
|
87
|
+
|
88
|
+
# Returns true if token is expired or about to expire
|
89
|
+
#
|
90
|
+
# @return [Boolean]
|
91
|
+
def expired?
|
92
|
+
expires < Time.now + TOKEN_EXPIRY_BUFFER
|
93
|
+
end
|
94
|
+
|
95
|
+
# @!attribute [r] hash
|
96
|
+
# @return [Hash] Access the token details Hash object ruby'fied to use symbolized keys
|
97
|
+
def hash
|
98
|
+
@hash_object
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module Ably::Models
|
2
|
+
# Convert token request argument to a {TokenRequest} object
|
3
|
+
#
|
4
|
+
# @param attributes [TokenRequest,Hash] A {TokenRequest} object or Hash of attributes to create a new token request
|
5
|
+
# @option attributes (see TokenRequest#initialize)
|
6
|
+
#
|
7
|
+
# @return [TokenRequest]
|
8
|
+
def self.TokenRequest(attributes)
|
9
|
+
case attributes
|
10
|
+
when TokenRequest
|
11
|
+
return attributes
|
12
|
+
else
|
13
|
+
TokenRequest.new(attributes)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# TokenRequest is a class that stores the attributes of a token request
|
19
|
+
#
|
20
|
+
# Ruby {Time} objects are supported in place of Ably ms since epoch time fields. However, if a numeric is provided
|
21
|
+
# it must always be expressed in milliseconds as the Ably API always uses milliseconds for time fields.
|
22
|
+
#
|
23
|
+
class TokenRequest
|
24
|
+
include Ably::Modules::ModelCommon
|
25
|
+
|
26
|
+
# @param attributes
|
27
|
+
# @option attributes [Integer] :ttl requested time to live for the token in milliseconds
|
28
|
+
# @option attributes [Time,Integer] :timestamp the timestamp of this request in milliseconds or as a {Time}
|
29
|
+
# @option attributes [String] :key_name API key name of the key against which this request is made
|
30
|
+
# @option attributes [String] :capability JSON stringified capability of the token
|
31
|
+
# @option attributes [String] :client_id client ID to associate with this token
|
32
|
+
# @option attributes [String] :nonce an opaque nonce string of at least 16 characters
|
33
|
+
# @option attributes [String] :mac the Message Authentication Code for this request
|
34
|
+
#
|
35
|
+
def initialize(attributes = {})
|
36
|
+
@hash_object = IdiomaticRubyWrapper(attributes.clone)
|
37
|
+
hash[:timestamp] = (hash[:timestamp].to_f * 1000).round if hash[:timestamp].kind_of?(Time)
|
38
|
+
hash.freeze
|
39
|
+
end
|
40
|
+
|
41
|
+
# @!attribute [r] key_name
|
42
|
+
# @return [String] API key name of the key against which this request is made. An API key is made up of an API key name and secret delimited by a +:+
|
43
|
+
def key_name
|
44
|
+
hash.fetch(:key_name)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @!attribute [r] ttl
|
48
|
+
# @return [Integer] requested time to live for the token in seconds. If the token request is successful,
|
49
|
+
# the TTL of the returned token will be less than or equal to this value depending on application
|
50
|
+
# settings and the attributes of the issuing key.
|
51
|
+
# TTL when sent to Ably is in milliseconds.
|
52
|
+
def ttl
|
53
|
+
hash.fetch(:ttl) / 1000
|
54
|
+
end
|
55
|
+
|
56
|
+
# @!attribute [r] capability
|
57
|
+
# @return [Hash] capability of the token. If the token request is successful,
|
58
|
+
# the capability of the returned token will be the intersection of
|
59
|
+
# this capability with the capability of the issuing key.
|
60
|
+
def capability
|
61
|
+
JSON.parse(hash.fetch(:capability))
|
62
|
+
end
|
63
|
+
|
64
|
+
# @!attribute [r] client_id
|
65
|
+
# @return [String] the client ID to associate with this token. The generated token
|
66
|
+
# may be used to authenticate as this clientId.
|
67
|
+
def client_id
|
68
|
+
hash[:client_id]
|
69
|
+
end
|
70
|
+
|
71
|
+
# @!attribute [r] timestamp
|
72
|
+
# @return [Time] the timestamp of this request.
|
73
|
+
# Timestamps, in conjunction with the nonce, are used to prevent
|
74
|
+
# token requests from being replayed.
|
75
|
+
# Timestamp when sent to Ably is in milliseconds.
|
76
|
+
def timestamp
|
77
|
+
as_time_from_epoch(hash.fetch(:timestamp), granularity: :ms)
|
78
|
+
end
|
79
|
+
|
80
|
+
# @!attribute [r] nonce
|
81
|
+
# @return [String] an opaque nonce string of at least 16 characters to ensure
|
82
|
+
# uniqueness of this request. Any subsequent request using the
|
83
|
+
# same nonce will be rejected.
|
84
|
+
def nonce
|
85
|
+
hash.fetch(:nonce)
|
86
|
+
end
|
87
|
+
|
88
|
+
# @!attribute [r] mac
|
89
|
+
# @return [String] the Message Authentication Code for this request. See the
|
90
|
+
# {https://www.ably.io/documentation Ably Authentication documentation} for more details.
|
91
|
+
def mac
|
92
|
+
hash.fetch(:mac)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Requests that the token is always persisted
|
96
|
+
# @api private
|
97
|
+
#
|
98
|
+
def persisted
|
99
|
+
hash.fetch(:persisted)
|
100
|
+
end
|
101
|
+
|
102
|
+
# @!attribute [r] hash
|
103
|
+
# @return [Hash] the token request Hash object ruby'fied to use symbolized keys
|
104
|
+
def hash
|
105
|
+
@hash_object
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/ably/realtime.rb
CHANGED
@@ -39,10 +39,6 @@ module Ably
|
|
39
39
|
# @param (see Ably::Realtime::Client#initialize)
|
40
40
|
# @option options (see Ably::Realtime::Client#initialize)
|
41
41
|
#
|
42
|
-
# @yield (see Ably::Realtime::Client#initialize)
|
43
|
-
# @yieldparam (see Ably::Realtime::Client#initialize)
|
44
|
-
# @yieldreturn (see Ably::Realtime::Client#initialize)
|
45
|
-
#
|
46
42
|
# @return [Ably::Realtime::Client]
|
47
43
|
#
|
48
44
|
# @example
|
@@ -52,8 +48,8 @@ module Ably
|
|
52
48
|
# # create a new client authenticating with basic auth and a client_id
|
53
49
|
# client = Ably::Realtime.new(key: 'key.id:secret', client_id: 'john')
|
54
50
|
#
|
55
|
-
def self.new(options
|
56
|
-
Ably::Realtime::Client.new(options
|
51
|
+
def self.new(options)
|
52
|
+
Ably::Realtime::Client.new(options)
|
57
53
|
end
|
58
54
|
end
|
59
55
|
end
|
@@ -100,7 +100,9 @@ module Ably
|
|
100
100
|
setup_presence
|
101
101
|
end
|
102
102
|
|
103
|
-
# Publish a message on the channel
|
103
|
+
# Publish a message on the channel.
|
104
|
+
#
|
105
|
+
# When publishing a message, if the channel is not attached, the channel is implicitly attached
|
104
106
|
#
|
105
107
|
# @param name [String] The event name of the message
|
106
108
|
# @param data [String,ByteArray] payload for the message
|
@@ -127,7 +129,9 @@ module Ably
|
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
130
|
-
# Subscribe to messages matching providing event name, or all messages if event name not provided
|
132
|
+
# Subscribe to messages matching providing event name, or all messages if event name not provided.
|
133
|
+
#
|
134
|
+
# When subscribing to messages, if the channel is not attached, the channel is implicitly attached
|
131
135
|
#
|
132
136
|
# @param names [String] The event name of the message to subscribe to if provided. Defaults to all events.
|
133
137
|
# @yield [Ably::Models::Message] For each message received, the block is called
|
@@ -177,6 +181,8 @@ module Ably
|
|
177
181
|
# presence on the channel and may also be used to obtain presence information
|
178
182
|
# and change events for other members of the channel.
|
179
183
|
#
|
184
|
+
# When accessing presence, if the channel is not attached, the channel is implicitly attached
|
185
|
+
#
|
180
186
|
# @return {Ably::Realtime::Presence}
|
181
187
|
#
|
182
188
|
def presence
|
@@ -186,21 +192,21 @@ module Ably
|
|
186
192
|
|
187
193
|
# Return the message history of the channel
|
188
194
|
#
|
189
|
-
#
|
190
|
-
# channel was attached with the option <tt>until_attach: true</tt>. This is
|
191
|
-
#
|
192
|
-
# the guarantee that no messages have been missed.
|
195
|
+
# If the channel is attached, you can retrieve messages published on the channel before the
|
196
|
+
# channel was attached with the option <tt>until_attach: true</tt>. This is useful when a developer
|
197
|
+
# wishes to display historical messages with the guarantee that no messages have been missed since attach.
|
193
198
|
#
|
194
199
|
# @param (see Ably::Rest::Channel#history)
|
195
200
|
# @option options (see Ably::Rest::Channel#history)
|
196
|
-
# @option options [Boolean] :until_attach When true,
|
201
|
+
# @option options [Boolean] :until_attach When true, the history request will be limited only to messages published before this channel was attached. Channel must be attached
|
197
202
|
#
|
198
203
|
# @yield [Ably::Models::PaginatedResource<Ably::Models::Message>] First {Ably::Models::PaginatedResource page} of {Ably::Models::Message} objects accessible with {Ably::Models::PaginatedResource#items #items}.
|
199
204
|
#
|
200
205
|
# @return [Ably::Util::SafeDeferrable]
|
206
|
+
#
|
201
207
|
def history(options = {}, &callback)
|
202
208
|
if options.delete(:until_attach)
|
203
|
-
raise ArgumentError, 'option :until_attach
|
209
|
+
raise ArgumentError, 'option :until_attach is invalid as the channel is not attached' unless attached?
|
204
210
|
options[:from_serial] = attached_serial
|
205
211
|
end
|
206
212
|
|
data/lib/ably/realtime/client.rb
CHANGED
@@ -64,10 +64,6 @@ module Ably
|
|
64
64
|
# @option options [String] :recover When a recover option is specified a connection inherits the state of a previous connection that may have existed under a different instance of the Realtime library, please refer to the API documentation for further information on connection state recovery
|
65
65
|
# @option options [Boolean] :connect_automatically By default as soon as the client library is instantiated it will connect to Ably. You can optionally set this to false and explicitly connect.
|
66
66
|
#
|
67
|
-
# @yield (see Ably::Rest::Client#initialize)
|
68
|
-
# @yieldparam (see Ably::Rest::Client#initialize)
|
69
|
-
# @yieldreturn (see Ably::Rest::Client#initialize)
|
70
|
-
#
|
71
67
|
# @return [Ably::Realtime::Client]
|
72
68
|
#
|
73
69
|
# @example
|
@@ -77,8 +73,8 @@ module Ably
|
|
77
73
|
# # create a new client and configure a client ID used for presence
|
78
74
|
# client = Ably::Realtime::Client.new(key: 'key.id:secret', client_id: 'john')
|
79
75
|
#
|
80
|
-
def initialize(options
|
81
|
-
@rest_client = Ably::Rest::Client.new(options
|
76
|
+
def initialize(options)
|
77
|
+
@rest_client = Ably::Rest::Client.new(options)
|
82
78
|
@auth = @rest_client.auth
|
83
79
|
@channels = Ably::Realtime::Channels.new(self)
|
84
80
|
@echo_messages = @rest_client.options.fetch(:echo_messages, true) == false ? false : true
|
@@ -10,8 +10,9 @@ module Ably
|
|
10
10
|
# connected: 2
|
11
11
|
# disconnected: 3
|
12
12
|
# suspended: 4
|
13
|
-
#
|
14
|
-
#
|
13
|
+
# closing: 5
|
14
|
+
# closed: 6
|
15
|
+
# failed: 7
|
15
16
|
#
|
16
17
|
# Note that the states are available as Enum-like constants:
|
17
18
|
#
|
@@ -20,6 +21,7 @@ module Ably
|
|
20
21
|
# Connection::STATE.Connected
|
21
22
|
# Connection::STATE.Disconnected
|
22
23
|
# Connection::STATE.Suspended
|
24
|
+
# Connection::STATE.Closing
|
23
25
|
# Connection::STATE.Closed
|
24
26
|
# Connection::STATE.Failed
|
25
27
|
#
|
data/lib/ably/rest.rb
CHANGED
@@ -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
|
@@ -36,8 +32,8 @@ module Ably
|
|
36
32
|
# # create a new client authenticating with basic auth and a client_id
|
37
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
|
data/lib/ably/rest/channel.rb
CHANGED
@@ -54,16 +54,20 @@ module Ably
|
|
54
54
|
|
55
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 +:forwards+ or +:backwards+
|
61
|
-
# @option options [Integer] :limit Maximum number of messages to retrieve up to
|
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
62
|
#
|
63
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}.
|
64
|
+
#
|
64
65
|
def history(options = {})
|
65
66
|
url = "#{base_path}/messages"
|
66
|
-
options =
|
67
|
+
options = {
|
68
|
+
:direction => :backwards,
|
69
|
+
:limit => 100
|
70
|
+
}.merge(options)
|
67
71
|
|
68
72
|
[:start, :end].each { |option| options[option] = as_since_epoch(options[option]) if options.has_key?(option) }
|
69
73
|
|
data/lib/ably/rest/client.rb
CHANGED
@@ -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] :key API key comprising the key
|
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
|
@@ -91,7 +89,7 @@ module Ably
|
|
91
89
|
# # create a new client and configure a client ID used for presence
|
92
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
|
@@ -99,7 +97,7 @@ module Ably
|
|
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,18 +144,19 @@ 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
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) }
|