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
@@ -9,17 +9,17 @@ describe Ably::Rest::Client, '#stats' do
|
|
9
9
|
|
10
10
|
STATS_FIXTURES = [
|
11
11
|
{
|
12
|
-
intervalId: Ably::Models::
|
12
|
+
intervalId: Ably::Models::Stats.to_interval_id(LAST_INTERVAL - 120, :minute),
|
13
13
|
inbound: { realtime: { messages: { count: 50, data: 5000 } } },
|
14
14
|
outbound: { realtime: { messages: { count: 20, data: 2000 } } }
|
15
15
|
},
|
16
16
|
{
|
17
|
-
intervalId: Ably::Models::
|
17
|
+
intervalId: Ably::Models::Stats.to_interval_id(LAST_INTERVAL - 60, :minute),
|
18
18
|
inbound: { realtime: { messages: { count: 60, data: 6000 } } },
|
19
19
|
outbound: { realtime: { messages: { count: 10, data: 1000 } } }
|
20
20
|
},
|
21
21
|
{
|
22
|
-
intervalId: Ably::Models::
|
22
|
+
intervalId: Ably::Models::Stats.to_interval_id(LAST_INTERVAL, :minute),
|
23
23
|
inbound: { realtime: { messages: { count: 70, data: 7000 } } },
|
24
24
|
outbound: { realtime: { messages: { count: 40, data: 4000 } } },
|
25
25
|
persisted: { presence: { count: 20, data: 2000 } },
|
@@ -36,7 +36,7 @@ describe Ably::Rest::Client, '#stats' do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
vary_by_protocol do
|
39
|
-
let(:client) { Ably::Rest::Client.new(
|
39
|
+
let(:client) { Ably::Rest::Client.new(key: api_key, environment: environment, protocol: protocol) }
|
40
40
|
|
41
41
|
describe 'fetching application stats' do
|
42
42
|
context 'by minute' do
|
@@ -44,56 +44,61 @@ describe Ably::Rest::Client, '#stats' do
|
|
44
44
|
let(:last_inbound_realtime_count) { STATS_FIXTURES.last[:inbound][:realtime][:messages][:count] }
|
45
45
|
|
46
46
|
context 'with :from set to last interval and :limit set to 1' do
|
47
|
-
let(:subject) { client.stats(start: as_since_epoch(LAST_INTERVAL),
|
48
|
-
let(:stat) { subject.first}
|
47
|
+
let(:subject) { client.stats(start: as_since_epoch(LAST_INTERVAL), end: LAST_INTERVAL, unit: :minute, limit: 1) }
|
48
|
+
let(:stat) { subject.items.first }
|
49
49
|
|
50
50
|
it 'retrieves only one stat' do
|
51
|
-
expect(subject.count).to eql(1)
|
51
|
+
expect(subject.items.count).to eql(1)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns zero value for any missing metrics' do
|
55
|
+
expect(stat.channels.refused).to eql(0)
|
56
|
+
expect(stat.outbound.webhook.all.count).to eql(0)
|
52
57
|
end
|
53
58
|
|
54
59
|
it 'returns all aggregated message data' do
|
55
|
-
expect(stat.all
|
56
|
-
expect(stat.all
|
60
|
+
expect(stat.all.messages.count).to eql(70 + 40) # inbound + outbound
|
61
|
+
expect(stat.all.messages.data).to eql(7000 + 4000) # inbound + outbound
|
57
62
|
end
|
58
63
|
|
59
64
|
it 'returns inbound realtime all data' do
|
60
|
-
expect(stat.inbound
|
61
|
-
expect(stat.inbound
|
65
|
+
expect(stat.inbound.realtime.all.count).to eql(70)
|
66
|
+
expect(stat.inbound.realtime.all.data).to eql(7000)
|
62
67
|
end
|
63
68
|
|
64
69
|
it 'returns inbound realtime message data' do
|
65
|
-
expect(stat.inbound
|
66
|
-
expect(stat.inbound
|
70
|
+
expect(stat.inbound.realtime.messages.count).to eql(70)
|
71
|
+
expect(stat.inbound.realtime.messages.data).to eql(7000)
|
67
72
|
end
|
68
73
|
|
69
74
|
it 'returns outbound realtime all data' do
|
70
|
-
expect(stat.outbound
|
71
|
-
expect(stat.outbound
|
75
|
+
expect(stat.outbound.realtime.all.count).to eql(40)
|
76
|
+
expect(stat.outbound.realtime.all.data).to eql(4000)
|
72
77
|
end
|
73
78
|
|
74
79
|
it 'returns persisted presence all data' do
|
75
|
-
expect(stat.persisted
|
76
|
-
expect(stat.persisted
|
80
|
+
expect(stat.persisted.all.count).to eql(20)
|
81
|
+
expect(stat.persisted.all.data).to eql(2000)
|
77
82
|
end
|
78
83
|
|
79
84
|
it 'returns connections all data' do
|
80
|
-
expect(stat.connections
|
81
|
-
expect(stat.connections
|
85
|
+
expect(stat.connections.tls.peak).to eql(20)
|
86
|
+
expect(stat.connections.tls.opened).to eql(10)
|
82
87
|
end
|
83
88
|
|
84
89
|
it 'returns channels all data' do
|
85
|
-
expect(stat.channels
|
86
|
-
expect(stat.channels
|
90
|
+
expect(stat.channels.peak).to eql(50)
|
91
|
+
expect(stat.channels.opened).to eql(30)
|
87
92
|
end
|
88
93
|
|
89
94
|
it 'returns api_requests data' do
|
90
|
-
expect(stat.api_requests
|
91
|
-
expect(stat.api_requests
|
95
|
+
expect(stat.api_requests.succeeded).to eql(50)
|
96
|
+
expect(stat.api_requests.failed).to eql(10)
|
92
97
|
end
|
93
98
|
|
94
99
|
it 'returns token_requests data' do
|
95
|
-
expect(stat.token_requests
|
96
|
-
expect(stat.token_requests
|
100
|
+
expect(stat.token_requests.succeeded).to eql(60)
|
101
|
+
expect(stat.token_requests.failed).to eql(20)
|
97
102
|
end
|
98
103
|
|
99
104
|
it 'returns stat objects with #interval_granularity equal to :minute' do
|
@@ -111,43 +116,43 @@ describe Ably::Rest::Client, '#stats' do
|
|
111
116
|
|
112
117
|
context 'with :start set to first interval, :limit set to 1 and direction :forwards' do
|
113
118
|
let(:first_interval) { LAST_INTERVAL - 120 }
|
114
|
-
let(:subject) { client.stats(start: as_since_epoch(first_interval),
|
115
|
-
let(:stat) { subject.first}
|
119
|
+
let(:subject) { client.stats(start: as_since_epoch(first_interval), end: LAST_INTERVAL, unit: :minute, direction: :forwards, limit: 1) }
|
120
|
+
let(:stat) { subject.items.first }
|
116
121
|
|
117
122
|
it 'returns the first interval stats as stats are provided forwards from :start' do
|
118
|
-
expect(stat.inbound
|
123
|
+
expect(stat.inbound.realtime.all.count).to eql(first_inbound_realtime_count)
|
119
124
|
end
|
120
125
|
|
121
126
|
it 'returns 3 pages of stats' do
|
122
|
-
expect(subject).to
|
123
|
-
expect(subject).to_not
|
124
|
-
page3 = subject.
|
125
|
-
expect(page3).to
|
126
|
-
expect(page3.first.inbound
|
127
|
+
expect(subject).to be_first
|
128
|
+
expect(subject).to_not be_last
|
129
|
+
page3 = subject.next.next
|
130
|
+
expect(page3).to be_last
|
131
|
+
expect(page3.items.first.inbound.realtime.all.count).to eql(last_inbound_realtime_count)
|
127
132
|
end
|
128
133
|
end
|
129
134
|
|
130
135
|
context 'with :end set to last interval, :limit set to 1 and direction :backwards' do
|
131
|
-
let(:subject) { client.stats(:end => as_since_epoch(LAST_INTERVAL),
|
132
|
-
let(:stat) { subject.first}
|
136
|
+
let(:subject) { client.stats(:end => as_since_epoch(LAST_INTERVAL), end: LAST_INTERVAL, unit: :minute, direction: :backwards, limit: 1) }
|
137
|
+
let(:stat) { subject.items.first }
|
133
138
|
|
134
139
|
it 'returns the 3rd interval stats first as stats are provided backwards from :end' do
|
135
|
-
expect(stat.inbound
|
140
|
+
expect(stat.inbound.realtime.all.count).to eql(last_inbound_realtime_count)
|
136
141
|
end
|
137
142
|
|
138
143
|
it 'returns 3 pages of stats' do
|
139
|
-
expect(subject).to
|
140
|
-
expect(subject).to_not
|
141
|
-
page3 = subject.
|
142
|
-
expect(page3.first.inbound
|
144
|
+
expect(subject).to be_first
|
145
|
+
expect(subject).to_not be_last
|
146
|
+
page3 = subject.next.next
|
147
|
+
expect(page3.items.first.inbound.realtime.all.count).to eql(first_inbound_realtime_count)
|
143
148
|
end
|
144
149
|
end
|
145
150
|
end
|
146
151
|
|
147
152
|
[:hour, :day, :month].each do |interval|
|
148
153
|
context "by #{interval}" do
|
149
|
-
let(:subject) { client.stats(start: as_since_epoch(LAST_INTERVAL),
|
150
|
-
let(:stat) { subject.first }
|
154
|
+
let(:subject) { client.stats(start: as_since_epoch(LAST_INTERVAL), end: LAST_INTERVAL, unit: interval, direction: 'forwards', limit: 1) }
|
155
|
+
let(:stat) { subject.items.first }
|
151
156
|
let(:aggregate_messages_count) do
|
152
157
|
STATS_FIXTURES.inject(0) do |sum, fixture|
|
153
158
|
sum + fixture[:inbound][:realtime][:messages][:count] + fixture[:outbound][:realtime][:messages][:count]
|
@@ -160,10 +165,10 @@ describe Ably::Rest::Client, '#stats' do
|
|
160
165
|
end
|
161
166
|
|
162
167
|
it 'should aggregate the stats for that period' do
|
163
|
-
expect(subject.count).to eql(1)
|
168
|
+
expect(subject.items.count).to eql(1)
|
164
169
|
|
165
|
-
expect(stat.all
|
166
|
-
expect(stat.all
|
170
|
+
expect(stat.all.messages.count).to eql(aggregate_messages_count)
|
171
|
+
expect(stat.all.messages.data).to eql(aggregate_messages_data)
|
167
172
|
end
|
168
173
|
end
|
169
174
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Ably::Rest::Client, '#time' do
|
4
4
|
vary_by_protocol do
|
5
5
|
let(:client) do
|
6
|
-
Ably::Rest::Client.new(
|
6
|
+
Ably::Rest::Client.new(key: api_key, environment: environment, protocol: protocol)
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'fetching the service time' do
|
@@ -32,8 +32,9 @@ RSpec.configure do |config|
|
|
32
32
|
config.before(:example, :webmock) do
|
33
33
|
allow(TestApp).to receive(:instance).and_return(instance_double('TestApp',
|
34
34
|
app_id: 'app_id',
|
35
|
-
|
36
|
-
|
35
|
+
key_name: 'app_id.key_name',
|
36
|
+
key_secret: 'secret',
|
37
|
+
api_key: 'app_id.key_name:secret',
|
37
38
|
environment: 'sandbox'
|
38
39
|
))
|
39
40
|
WebMock.enable!
|
@@ -26,7 +26,7 @@ shared_examples 'a client initializer' do
|
|
26
26
|
let(:client_options) { Hash.new }
|
27
27
|
|
28
28
|
it 'raises an exception' do
|
29
|
-
expect { subject }.to raise_error(ArgumentError, /
|
29
|
+
expect { subject }.to raise_error(ArgumentError, /key is missing/)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -38,35 +38,35 @@ shared_examples 'a client initializer' do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
context '
|
42
|
-
let(:client_options) { {
|
41
|
+
context 'key: "invalid"' do
|
42
|
+
let(:client_options) { { key: 'invalid' } }
|
43
43
|
|
44
44
|
it 'raises an exception' do
|
45
|
-
expect { subject }.to raise_error(ArgumentError, /
|
45
|
+
expect { subject }.to raise_error(ArgumentError, /key is invalid/)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
context '
|
50
|
-
let(:client_options) { {
|
49
|
+
context 'key: "invalid:asdad"' do
|
50
|
+
let(:client_options) { { key: 'invalid:asdad' } }
|
51
51
|
|
52
52
|
it 'raises an exception' do
|
53
|
-
expect { subject }.to raise_error(ArgumentError, /
|
53
|
+
expect { subject }.to raise_error(ArgumentError, /key is invalid/)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
context '
|
58
|
-
let(:client_options) { {
|
57
|
+
context 'key and key_name' do
|
58
|
+
let(:client_options) { { key: 'appid.keyuid:keysecret', key_name: 'invalid' } }
|
59
59
|
|
60
60
|
it 'raises an exception' do
|
61
|
-
expect { subject }.to raise_error(ArgumentError, /
|
61
|
+
expect { subject }.to raise_error(ArgumentError, /key and key_name or key_secret are mutually exclusive/)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
context '
|
66
|
-
let(:client_options) { {
|
65
|
+
context 'key and key_secret' do
|
66
|
+
let(:client_options) { { key: 'appid.keyuid:keysecret', key_secret: 'invalid' } }
|
67
67
|
|
68
68
|
it 'raises an exception' do
|
69
|
-
expect { subject }.to raise_error(ArgumentError, /
|
69
|
+
expect { subject }.to raise_error(ArgumentError, /key and key_name or key_secret are mutually exclusive/)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -80,32 +80,32 @@ shared_examples 'a client initializer' do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
context 'with valid arguments' do
|
83
|
-
let(:default_options) { {
|
83
|
+
let(:default_options) { { key: 'appid.keyuid:keysecret' } }
|
84
84
|
let(:client_options) { default_options }
|
85
85
|
|
86
|
-
context '
|
86
|
+
context 'key only' do
|
87
87
|
it 'connects to the Ably service' do
|
88
88
|
expect { subject }.to_not raise_error
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
context '
|
93
|
-
let(:client_options) { {
|
92
|
+
context 'key_name and key_secret', api_private: true do
|
93
|
+
let(:client_options) { { key_name: 'id', key_secret: 'secret' } }
|
94
94
|
|
95
|
-
it 'constructs an
|
96
|
-
expect(subject.auth.
|
95
|
+
it 'constructs an key' do
|
96
|
+
expect(subject.auth.key).to eql('id:secret')
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
100
|
context 'with a string key instead of options hash' do
|
101
101
|
let(:client_options) { 'app.key:secret' }
|
102
102
|
|
103
|
-
it 'sets the
|
104
|
-
expect(subject.auth.
|
103
|
+
it 'sets the key' do
|
104
|
+
expect(subject.auth.key).to eql(client_options)
|
105
105
|
end
|
106
106
|
|
107
|
-
it 'sets the
|
108
|
-
expect(subject.auth.
|
107
|
+
it 'sets the key_name' do
|
108
|
+
expect(subject.auth.key_name).to eql('app.key')
|
109
109
|
end
|
110
110
|
|
111
111
|
it 'sets the key_secret' do
|
@@ -116,16 +116,24 @@ shared_examples 'a client initializer' do
|
|
116
116
|
context 'with a string token key instead of options hash' do
|
117
117
|
let(:client_options) { 'app.kjhkasjhdsakdh127g7g1271' }
|
118
118
|
|
119
|
-
it 'sets the
|
120
|
-
expect(subject.auth.
|
119
|
+
it 'sets the token' do
|
120
|
+
expect(subject.auth.token).to eql(client_options)
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
124
|
context 'with token' do
|
125
|
-
let(:client_options) { {
|
125
|
+
let(:client_options) { { token: 'token' } }
|
126
126
|
|
127
|
-
it 'sets the
|
128
|
-
expect(subject.auth.
|
127
|
+
it 'sets the token' do
|
128
|
+
expect(subject.auth.token).to eql('token')
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'with token_details' do
|
133
|
+
let(:client_options) { { token_details: Ably::Models::TokenDetails.new(token: 'token') } }
|
134
|
+
|
135
|
+
it 'sets the token' do
|
136
|
+
expect(subject.auth.token).to eql('token')
|
129
137
|
end
|
130
138
|
end
|
131
139
|
|
@@ -1,28 +1,15 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
|
3
3
|
class TestApp
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
],
|
14
|
-
'channels' => [
|
15
|
-
{
|
16
|
-
'name' => 'persisted:presence_fixtures',
|
17
|
-
'presence' => [
|
18
|
-
{ 'clientId' => 'client_bool', 'data' => 'true' },
|
19
|
-
{ 'clientId' => 'client_int', 'data' => '24' },
|
20
|
-
{ 'clientId' => 'client_string', 'data' => 'This is a string clientData payload' },
|
21
|
-
{ 'clientId' => 'client_json', 'data' => '{ "test" => \'This is a JSONObject clientData payload\'}' }
|
22
|
-
]
|
23
|
-
}
|
24
|
-
]
|
25
|
-
}
|
4
|
+
TEST_RESOURCES_PATH = File.expand_path('../../../lib/submodules/ably-common/test-resources', __FILE__)
|
5
|
+
|
6
|
+
# App configuration for test app
|
7
|
+
# See https://github.com/ably/ably-common/blob/master/test-resources/test-app-setup.json
|
8
|
+
APP_SPEC = JSON.parse(File.read(File.join(TEST_RESOURCES_PATH, 'test-app-setup.json')))['post_apps']
|
9
|
+
|
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
|
12
|
+
APP_SPEC_CIPHER = JSON.parse(File.read(File.join(TEST_RESOURCES_PATH, 'test-app-setup.json')))['cipher']
|
26
13
|
|
27
14
|
# If an app has already been created and we need a new app, create a new test app
|
28
15
|
# This is sometimes needed when a test needs to be isolated from any other tests
|
@@ -40,31 +27,31 @@ class TestApp
|
|
40
27
|
end
|
41
28
|
|
42
29
|
def app_id
|
43
|
-
@attributes
|
30
|
+
@attributes.fetch('appId')
|
44
31
|
end
|
45
32
|
|
46
33
|
def key
|
47
|
-
@attributes
|
34
|
+
@attributes.fetch('keys').first
|
48
35
|
end
|
49
36
|
|
50
37
|
def restricted_key
|
51
|
-
@attributes
|
38
|
+
@attributes.fetch('keys')[1]
|
52
39
|
end
|
53
40
|
|
54
|
-
def
|
55
|
-
|
41
|
+
def key_name
|
42
|
+
key.fetch('keyName')
|
56
43
|
end
|
57
44
|
|
58
|
-
def
|
59
|
-
key
|
45
|
+
def key_secret
|
46
|
+
key.fetch('keySecret')
|
60
47
|
end
|
61
48
|
|
62
49
|
def api_key
|
63
|
-
|
50
|
+
key.fetch('keyStr')
|
64
51
|
end
|
65
52
|
|
66
53
|
def restricted_api_key
|
67
|
-
|
54
|
+
restricted_key.fetch('keyStr')
|
68
55
|
end
|
69
56
|
|
70
57
|
def delete
|
@@ -107,13 +94,13 @@ class TestApp
|
|
107
94
|
end
|
108
95
|
|
109
96
|
def create_test_stats(stats)
|
110
|
-
client = Ably::Rest::Client.new(
|
97
|
+
client = Ably::Rest::Client.new(key: api_key, environment: environment)
|
111
98
|
response = client.post('/stats', stats)
|
112
99
|
raise "Could not create stats fixtures. Ably responded with status #{response.status}\n#{response.body}" unless (200..299).include?(response.status)
|
113
100
|
end
|
114
101
|
|
115
102
|
private
|
116
103
|
def sandbox_client
|
117
|
-
@sandbox_client ||= Ably::Rest::Client.new(
|
104
|
+
@sandbox_client ||= Ably::Rest::Client.new(key: 'app.key:secret', tls: true, environment: environment)
|
118
105
|
end
|
119
106
|
end
|