ably-rest 0.7.5 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'shared/model_behaviour'
|
3
|
+
|
4
|
+
describe Ably::Models::TokenDetails do
|
5
|
+
include Ably::Modules::Conversions
|
6
|
+
|
7
|
+
subject { Ably::Models::TokenDetails }
|
8
|
+
|
9
|
+
it_behaves_like 'a model', with_simple_attributes: %w(token key_name client_id) do
|
10
|
+
let(:model_args) { [] }
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
context 'attributes' do
|
15
|
+
let(:capability) { { "value" => random_str } }
|
16
|
+
let(:capability_str) { JSON.dump(capability) }
|
17
|
+
|
18
|
+
context '#capability' do
|
19
|
+
subject { Ably::Models::TokenDetails.new({ capability: capability_str }) }
|
20
|
+
|
21
|
+
it 'retrieves attribute :capability as parsed JSON' do
|
22
|
+
expect(subject.capability).to eql(capability)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
{ :issued => :issued, :expires => :expires }.each do |method_name, attribute|
|
27
|
+
let(:time) { Time.now }
|
28
|
+
context "##{method_name} with :#{method_name} option as milliseconds in constructor" do
|
29
|
+
subject { Ably::Models::TokenDetails.new({ attribute.to_sym => time.to_i * 1000 }) }
|
30
|
+
|
31
|
+
it "retrieves attribute :#{attribute} as Time" do
|
32
|
+
expect(subject.public_send(method_name)).to be_a(Time)
|
33
|
+
expect(subject.public_send(method_name).to_i).to eql(time.to_i)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "##{method_name} with :#{method_name} option as a Time in constructor" do
|
38
|
+
subject { Ably::Models::TokenDetails.new({ attribute.to_sym => time }) }
|
39
|
+
|
40
|
+
it "retrieves attribute :#{attribute} as Time" do
|
41
|
+
expect(subject.public_send(method_name)).to be_a(Time)
|
42
|
+
expect(subject.public_send(method_name).to_i).to eql(time.to_i)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "##{method_name} when converted to JSON" do
|
47
|
+
subject { Ably::Models::TokenDetails.new({ attribute.to_sym => time }) }
|
48
|
+
|
49
|
+
it 'is in milliseconds' do
|
50
|
+
expect(JSON.parse(JSON.dump(subject))[convert_to_mixed_case(attribute)]).to eql((time.to_f * 1000).round)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context '#expired?' do
|
56
|
+
let(:expire_time) { Time.now + Ably::Models::TokenDetails::TOKEN_EXPIRY_BUFFER }
|
57
|
+
|
58
|
+
context 'once grace period buffer has passed' do
|
59
|
+
subject { Ably::Models::TokenDetails.new(expires: expire_time - 1) }
|
60
|
+
|
61
|
+
it 'is true' do
|
62
|
+
expect(subject.expired?).to eql(true)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'within grace period buffer' do
|
67
|
+
subject { Ably::Models::TokenDetails.new(expires: expire_time + 1) }
|
68
|
+
|
69
|
+
it 'is false' do
|
70
|
+
expect(subject.expired?).to eql(false)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context '==' do
|
77
|
+
let(:token_attributes) { { token: 'unique' } }
|
78
|
+
|
79
|
+
it 'is true when attributes are the same' do
|
80
|
+
new_token = -> { Ably::Models::TokenDetails.new(token_attributes) }
|
81
|
+
expect(new_token[]).to eq(new_token[])
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'is false when attributes are not the same' do
|
85
|
+
expect(Ably::Models::TokenDetails.new(token: 1)).to_not eq(Ably::Models::TokenDetails.new(token: 2))
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'is false when class type differs' do
|
89
|
+
expect(Ably::Models::TokenDetails.new(token: 1)).to_not eq(nil)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'TokenDetails conversion methods', :api_private do
|
94
|
+
context 'with a TokenDetails object' do
|
95
|
+
let(:token_details) { Ably::Models::TokenDetails.new(client_id: random_str) }
|
96
|
+
|
97
|
+
it 'returns the TokenDetails object' do
|
98
|
+
expect(Ably::Models::TokenDetails(token_details)).to eql(token_details)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'with a JSON object' do
|
103
|
+
let(:client_id) { random_str }
|
104
|
+
let(:token_details_json) { { client_id: client_id } }
|
105
|
+
|
106
|
+
it 'returns a new TokenDetails object from the JSON' do
|
107
|
+
expect(Ably::Models::TokenDetails(token_details_json).client_id).to eql(client_id)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'shared/model_behaviour'
|
3
|
+
|
4
|
+
describe Ably::Models::TokenRequest do
|
5
|
+
subject { Ably::Models::TokenRequest }
|
6
|
+
|
7
|
+
it_behaves_like 'a model', with_simple_attributes: %w(key_name client_id nonce mac) do
|
8
|
+
let(:model_args) { [] }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'attributes' do
|
12
|
+
context '#capability' do
|
13
|
+
let(:capability) { { "value" => random_str } }
|
14
|
+
let(:capability_str) { JSON.dump(capability) }
|
15
|
+
|
16
|
+
subject { Ably::Models::TokenRequest.new({ capability: capability_str }) }
|
17
|
+
|
18
|
+
it 'retrieves attribute :capability as parsed JSON' do
|
19
|
+
expect(subject.capability).to eql(capability)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "#timestamp" do
|
24
|
+
let(:time) { Time.now }
|
25
|
+
|
26
|
+
context 'with :timestamp option as milliseconds in constructor' do
|
27
|
+
subject { Ably::Models::TokenRequest.new(timestamp: time.to_i * 1000) }
|
28
|
+
|
29
|
+
it "retrieves attribute :timestamp as Time" do
|
30
|
+
expect(subject.timestamp).to be_a(Time)
|
31
|
+
expect(subject.timestamp.to_i).to eql(time.to_i)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with :timestamp option as Time in constructor' do
|
36
|
+
subject { Ably::Models::TokenRequest.new(timestamp: time) }
|
37
|
+
|
38
|
+
it "retrieves attribute :timestamp as Time" do
|
39
|
+
expect(subject.timestamp).to be_a(Time)
|
40
|
+
expect(subject.timestamp.to_i).to eql(time.to_i)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when converted to JSON' do
|
45
|
+
subject { Ably::Models::TokenRequest.new(timestamp: time) }
|
46
|
+
|
47
|
+
it "is in milliseconds since epoch" do
|
48
|
+
expect(JSON.parse(JSON.dump(subject))['timestamp']).to eql((time.to_f * 1000).round)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "#ttl" do
|
54
|
+
let(:ttl) { 500 }
|
55
|
+
|
56
|
+
context 'with :ttl option as milliseconds in constructor' do
|
57
|
+
subject { Ably::Models::TokenRequest.new(ttl: ttl * 1000) }
|
58
|
+
|
59
|
+
it "retrieves attribute :ttl as seconds" do
|
60
|
+
expect(subject.ttl).to be_a(Integer)
|
61
|
+
expect(subject.ttl).to eql(ttl)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when converted to JSON' do
|
66
|
+
subject { Ably::Models::TokenRequest.new(ttl: ttl * 1000) }
|
67
|
+
|
68
|
+
it "is in milliseconds since epoch" do
|
69
|
+
expect(JSON.parse(JSON.dump(subject))['ttl']).to eql(ttl * 1000)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context '==' do
|
76
|
+
let(:token_attributes) { { client_id: random_str } }
|
77
|
+
|
78
|
+
it 'is true when attributes are the same' do
|
79
|
+
new_token = -> { Ably::Models::TokenRequest.new(token_attributes) }
|
80
|
+
expect(new_token[]).to eq(new_token[])
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'is false when attributes are not the same' do
|
84
|
+
expect(Ably::Models::TokenRequest.new(client_id: 1)).to_not eq(Ably::Models::TokenRequest.new(client_id: 2))
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'is false when class type differs' do
|
88
|
+
expect(Ably::Models::TokenRequest.new(client_id: 1)).to_not eq(nil)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'TokenRequest conversion methods', :api_private do
|
93
|
+
context 'with a TokenRequest object' do
|
94
|
+
let(:token_request) { Ably::Models::TokenRequest.new(client_id: random_str) }
|
95
|
+
|
96
|
+
it 'returns the TokenRequest object' do
|
97
|
+
expect(Ably::Models::TokenRequest(token_request)).to eql(token_request)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'with a JSON object' do
|
102
|
+
let(:client_id) { random_str }
|
103
|
+
let(:token_request_json) { { client_id: client_id } }
|
104
|
+
|
105
|
+
it 'returns a new TokenRequest object from the JSON' do
|
106
|
+
expect(Ably::Models::TokenRequest(token_request_json).client_id).to eql(client_id)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -10,7 +10,7 @@ describe Ably::Realtime::Client do
|
|
10
10
|
it_behaves_like 'a client initializer'
|
11
11
|
|
12
12
|
context 'delegation to the REST Client' do
|
13
|
-
let(:client_options) { {
|
13
|
+
let(:client_options) { { key: 'appid.keyuid:keysecret' } }
|
14
14
|
|
15
15
|
it 'passes on the options to the initializer' do
|
16
16
|
rest_client = instance_double('Ably::Rest::Client', auth: instance_double('Ably::Auth'), options: client_options)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Ably::Realtime do
|
4
|
-
let(:options) { {
|
4
|
+
let(:options) { { key: 'app.key:secret' } }
|
5
5
|
|
6
6
|
specify 'constructor returns an Ably::Realtime::Client' do
|
7
7
|
expect(Ably::Realtime.new(options)).to be_instance_of(Ably::Realtime::Client)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
describe Ably::Rest::
|
4
|
+
describe Ably::Rest::Channel do
|
5
5
|
let(:client) { instance_double('Ably::Rest::Client', encoders: [], post: instance_double('Faraday::Response', status: 201)) }
|
6
6
|
let(:channel_name) { 'unique' }
|
7
7
|
|
@@ -12,7 +12,7 @@ describe Ably::Rest::Client do
|
|
12
12
|
context 'initializer options' do
|
13
13
|
context 'TLS' do
|
14
14
|
context 'disabled' do
|
15
|
-
let(:client_options) { {
|
15
|
+
let(:client_options) { { key: 'appid.keyuid:keysecret', tls: false } }
|
16
16
|
|
17
17
|
it 'fails for any operation with basic auth and attempting to send an API key over a non-secure connection' do
|
18
18
|
expect { subject.channel('a').publish('event', 'message') }.to raise_error(Ably::Exceptions::InsecureRequestError)
|
@@ -22,28 +22,28 @@ describe Ably::Rest::Client do
|
|
22
22
|
|
23
23
|
context ':use_token_auth' do
|
24
24
|
context 'set to false' do
|
25
|
-
context 'with an
|
26
|
-
let(:client_options) { { use_token_auth: false,
|
25
|
+
context 'with an key with :tls => false' do
|
26
|
+
let(:client_options) { { use_token_auth: false, key: 'appid.keyuid:keysecret', tls: false } }
|
27
27
|
|
28
28
|
it 'fails for any operation with basic auth and attempting to send an API key over a non-secure connection' do
|
29
29
|
expect { subject.channel('a').publish('event', 'message') }.to raise_error(Ably::Exceptions::InsecureRequestError)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
context 'without an
|
33
|
+
context 'without an key' do
|
34
34
|
let(:client_options) { { use_token_auth: false } }
|
35
35
|
|
36
|
-
it 'fails as an
|
36
|
+
it 'fails as an key is required if not using token auth' do
|
37
37
|
expect { subject.channel('a').publish('event', 'message') }.to raise_error(ArgumentError)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
context 'set to true' do
|
43
|
-
context 'without an
|
44
|
-
let(:client_options) { { use_token_auth: true,
|
43
|
+
context 'without an key or token' do
|
44
|
+
let(:client_options) { { use_token_auth: true, key: true } }
|
45
45
|
|
46
|
-
it 'fails as an
|
46
|
+
it 'fails as an key is required to issue tokens' do
|
47
47
|
expect { subject.channel('a').publish('event', 'message') }.to raise_error(ArgumentError)
|
48
48
|
end
|
49
49
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Ably::Rest do
|
5
|
-
let(:options) { {
|
5
|
+
let(:options) { { key: 'app.key:secret' } }
|
6
6
|
|
7
7
|
specify 'constructor returns an Ably::Rest::Client' do
|
8
8
|
expect(Ably::Rest.new(options)).to be_instance_of(Ably::Rest::Client)
|
@@ -45,7 +45,7 @@ describe Ably::Util::Crypto do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
context 'using shared client lib fixture data' do
|
48
|
-
let(:resources_root) { File.expand_path('
|
48
|
+
let(:resources_root) { File.expand_path('../../../../lib/submodules/ably-common/test-resources', __FILE__) }
|
49
49
|
let(:encryption_data_128) { JSON.parse(File.read(File.join(resources_root, 'crypto-data-128.json'))) }
|
50
50
|
let(:encryption_data_256) { JSON.parse(File.read(File.join(resources_root, 'crypto-data-256.json'))) }
|
51
51
|
|
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: 0.
|
4
|
+
version: 0.8.1
|
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: 2015-
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -172,6 +172,7 @@ files:
|
|
172
172
|
- lib/ably-rest.rb
|
173
173
|
- lib/ably-rest/modules/eventmachine_deferrable.rb
|
174
174
|
- lib/submodules/ably-ruby/.gitignore
|
175
|
+
- lib/submodules/ably-ruby/.gitmodules
|
175
176
|
- lib/submodules/ably-ruby/.rspec
|
176
177
|
- lib/submodules/ably-ruby/.travis.yml
|
177
178
|
- lib/submodules/ably-ruby/Gemfile
|
@@ -197,7 +198,9 @@ files:
|
|
197
198
|
- lib/submodules/ably-ruby/lib/ably/models/presence_message.rb
|
198
199
|
- lib/submodules/ably-ruby/lib/ably/models/protocol_message.rb
|
199
200
|
- lib/submodules/ably-ruby/lib/ably/models/stat.rb
|
200
|
-
- lib/submodules/ably-ruby/lib/ably/models/
|
201
|
+
- lib/submodules/ably-ruby/lib/ably/models/stats_types.rb
|
202
|
+
- lib/submodules/ably-ruby/lib/ably/models/token_details.rb
|
203
|
+
- lib/submodules/ably-ruby/lib/ably/models/token_request.rb
|
201
204
|
- lib/submodules/ably-ruby/lib/ably/modules/ably.rb
|
202
205
|
- lib/submodules/ably-ruby/lib/ably/modules/async_wrapper.rb
|
203
206
|
- lib/submodules/ably-ruby/lib/ably/modules/channels_collection.rb
|
@@ -269,8 +272,6 @@ files:
|
|
269
272
|
- lib/submodules/ably-ruby/spec/acceptance/rest/presence_spec.rb
|
270
273
|
- lib/submodules/ably-ruby/spec/acceptance/rest/stats_spec.rb
|
271
274
|
- lib/submodules/ably-ruby/spec/acceptance/rest/time_spec.rb
|
272
|
-
- lib/submodules/ably-ruby/spec/resources/crypto-data-128.json
|
273
|
-
- lib/submodules/ably-ruby/spec/resources/crypto-data-256.json
|
274
275
|
- lib/submodules/ably-ruby/spec/rspec_config.rb
|
275
276
|
- lib/submodules/ably-ruby/spec/shared/client_initializer_behaviour.rb
|
276
277
|
- lib/submodules/ably-ruby/spec/shared/model_behaviour.rb
|
@@ -297,8 +298,9 @@ files:
|
|
297
298
|
- lib/submodules/ably-ruby/spec/unit/models/paginated_resource_spec.rb
|
298
299
|
- lib/submodules/ably-ruby/spec/unit/models/presence_message_spec.rb
|
299
300
|
- lib/submodules/ably-ruby/spec/unit/models/protocol_message_spec.rb
|
300
|
-
- lib/submodules/ably-ruby/spec/unit/models/
|
301
|
-
- lib/submodules/ably-ruby/spec/unit/models/
|
301
|
+
- lib/submodules/ably-ruby/spec/unit/models/stats_spec.rb
|
302
|
+
- lib/submodules/ably-ruby/spec/unit/models/token_details_spec.rb
|
303
|
+
- lib/submodules/ably-ruby/spec/unit/models/token_request_spec.rb
|
302
304
|
- lib/submodules/ably-ruby/spec/unit/modules/async_wrapper_spec.rb
|
303
305
|
- lib/submodules/ably-ruby/spec/unit/modules/conversions_spec.rb
|
304
306
|
- lib/submodules/ably-ruby/spec/unit/modules/enum_spec.rb
|
@@ -1,74 +0,0 @@
|
|
1
|
-
module Ably::Models
|
2
|
-
# Authentication token issued by Ably in response to an token request
|
3
|
-
class Token
|
4
|
-
include Ably::Modules::ModelCommon
|
5
|
-
|
6
|
-
DEFAULTS = {
|
7
|
-
capability: { '*' => ['*'] },
|
8
|
-
ttl: 60 * 60 # 1 hour
|
9
|
-
}
|
10
|
-
|
11
|
-
# Buffer in seconds given to the use of a token prior to it being considered unusable
|
12
|
-
# For example, if buffer is 10s, the token can no longer be used for new requests 9s before it expires
|
13
|
-
TOKEN_EXPIRY_BUFFER = 5
|
14
|
-
|
15
|
-
def initialize(attributes)
|
16
|
-
@hash_object = IdiomaticRubyWrapper(attributes.clone.freeze)
|
17
|
-
end
|
18
|
-
|
19
|
-
# @!attribute [r] id
|
20
|
-
# @return [String] Unique token ID used to authenticate requests
|
21
|
-
def id
|
22
|
-
hash.fetch(:id)
|
23
|
-
end
|
24
|
-
|
25
|
-
# @!attribute [r] key_id
|
26
|
-
# @return [String] Key ID used to create this token
|
27
|
-
def key_id
|
28
|
-
hash.fetch(:key)
|
29
|
-
end
|
30
|
-
|
31
|
-
# @!attribute [r] issued_at
|
32
|
-
# @return [Time] Time the token was issued
|
33
|
-
def issued_at
|
34
|
-
as_time_from_epoch(hash.fetch(:issued_at), granularity: :s)
|
35
|
-
end
|
36
|
-
|
37
|
-
# @!attribute [r] expires_at
|
38
|
-
# @return [Time] Time the token expires
|
39
|
-
def expires_at
|
40
|
-
as_time_from_epoch(hash.fetch(:expires), granularity: :s)
|
41
|
-
end
|
42
|
-
|
43
|
-
# @!attribute [r] capability
|
44
|
-
# @return [Hash] Capabilities assigned to this token
|
45
|
-
def capability
|
46
|
-
hash.fetch(:capability)
|
47
|
-
end
|
48
|
-
|
49
|
-
# @!attribute [r] client_id
|
50
|
-
# @return [String] Optional client ID assigned to this token
|
51
|
-
def client_id
|
52
|
-
hash[:client_id]
|
53
|
-
end
|
54
|
-
|
55
|
-
# @!attribute [r] nonce
|
56
|
-
# @return [String] unique nonce used to generate Token and ensure token generation cannot be replayed
|
57
|
-
def nonce
|
58
|
-
hash.fetch(:nonce)
|
59
|
-
end
|
60
|
-
|
61
|
-
# Returns true if token is expired or about to expire
|
62
|
-
#
|
63
|
-
# @return [Boolean]
|
64
|
-
def expired?
|
65
|
-
expires_at < Time.now + TOKEN_EXPIRY_BUFFER
|
66
|
-
end
|
67
|
-
|
68
|
-
# @!attribute [r] hash
|
69
|
-
# @return [Hash] Access the token Hash object ruby'fied to use symbolized keys
|
70
|
-
def hash
|
71
|
-
@hash_object
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|