ably 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +103 -0
- data/Rakefile +4 -0
- data/ably.gemspec +32 -0
- data/lib/ably.rb +11 -0
- data/lib/ably/auth.rb +381 -0
- data/lib/ably/exceptions.rb +16 -0
- data/lib/ably/realtime.rb +38 -0
- data/lib/ably/realtime/callbacks.rb +15 -0
- data/lib/ably/realtime/channel.rb +51 -0
- data/lib/ably/realtime/client.rb +82 -0
- data/lib/ably/realtime/connection.rb +61 -0
- data/lib/ably/rest.rb +15 -0
- data/lib/ably/rest/channel.rb +58 -0
- data/lib/ably/rest/client.rb +194 -0
- data/lib/ably/rest/middleware/exceptions.rb +42 -0
- data/lib/ably/rest/middleware/external_exceptions.rb +26 -0
- data/lib/ably/rest/middleware/parse_json.rb +15 -0
- data/lib/ably/rest/paged_resource.rb +107 -0
- data/lib/ably/rest/presence.rb +44 -0
- data/lib/ably/support.rb +14 -0
- data/lib/ably/token.rb +55 -0
- data/lib/ably/version.rb +3 -0
- data/spec/acceptance/realtime_client_spec.rb +12 -0
- data/spec/acceptance/rest/auth_spec.rb +441 -0
- data/spec/acceptance/rest/base_spec.rb +113 -0
- data/spec/acceptance/rest/channel_spec.rb +68 -0
- data/spec/acceptance/rest/presence_spec.rb +22 -0
- data/spec/acceptance/rest/stats_spec.rb +57 -0
- data/spec/acceptance/rest/time_spec.rb +14 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/api_helper.rb +41 -0
- data/spec/support/test_app.rb +77 -0
- data/spec/unit/auth.rb +9 -0
- data/spec/unit/realtime_spec.rb +9 -0
- data/spec/unit/rest_spec.rb +99 -0
- data/spec/unit/token_spec.rb +90 -0
- metadata +240 -0
@@ -0,0 +1,99 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Ably::Rest do
|
4
|
+
let(:options) { { api_key: 'app.key:secret' } }
|
5
|
+
|
6
|
+
specify 'constructor returns an Ably::Rest::Client' do
|
7
|
+
expect(Ably::Rest.new(options)).to be_instance_of(Ably::Rest::Client)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe Ably::Rest::Client do
|
11
|
+
describe "initializing the client" do
|
12
|
+
it "should disallow an invalid key" do
|
13
|
+
expect { Ably::Rest::Client.new({}) }.to raise_error(ArgumentError, /api_key is missing/)
|
14
|
+
expect { Ably::Rest::Client.new(api_key: 'invalid') }.to raise_error(ArgumentError, /api_key is invalid/)
|
15
|
+
expect { Ably::Rest::Client.new(api_key: 'invalid:asdad') }.to raise_error(ArgumentError, /api_key is invalid/)
|
16
|
+
expect { Ably::Rest::Client.new(api_key: 'appid.keyuid:keysecret') }.to_not raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should disallow api_key and key_id" do
|
20
|
+
expect { Ably::Rest::Client.new(api_key: 'valid', key_id: 'invalid') }.to raise_error(ArgumentError, /api_key and key_id or key_secret are mutually exclusive/)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should disallow api_key and key_secret" do
|
24
|
+
expect { Ably::Rest::Client.new(api_key: 'valid', key_secret: 'invalid') }.to raise_error(ArgumentError, /api_key and key_id or key_secret are mutually exclusive/)
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'using key_id and key_secret' do
|
28
|
+
let(:client) { Ably::Rest::Client.new(key_id: 'id', key_secret: 'secret') }
|
29
|
+
|
30
|
+
it "should allow key_id and key_secret in place of api_key" do
|
31
|
+
expect(client.auth.api_key).to eql('id:secret')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with a string key instead of options" do
|
36
|
+
let(:options) { 'app.key:secret' }
|
37
|
+
subject { Ably::Rest::Client.new(options) }
|
38
|
+
|
39
|
+
it 'should set the api_key' do
|
40
|
+
expect(subject.auth.api_key).to eql(options)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should set the key_id' do
|
44
|
+
expect(subject.auth.key_id).to eql('app.key')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should set the key_secret' do
|
48
|
+
expect(subject.auth.key_secret).to eql('secret')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "with a client_id" do
|
53
|
+
it "should require a valid key" do
|
54
|
+
expect { Ably::Rest::Client.new(client_id: 'valid') }.to raise_error(ArgumentError, /client_id cannot be provided without a complete API key/)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should default to the production REST end point" do
|
59
|
+
expect(Ably::Rest::Client.new(api_key: 'appid.keyuid:keysecret').endpoint.to_s).to eql('https://rest.ably.io')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should allow an environment to be set" do
|
63
|
+
expect(Ably::Rest::Client.new(api_key: 'appid.keyuid:keysecret', environment: 'sandbox').endpoint.to_s).to eql('https://sandbox-rest.ably.io')
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'with TLS disabled' do
|
67
|
+
let(:client) { Ably::Rest::Client.new(api_key: 'appid.keyid:secret', tls: false) }
|
68
|
+
|
69
|
+
it 'uses plain text' do
|
70
|
+
expect(client.use_tls?).to eql(false)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'uses HTTP' do
|
74
|
+
expect(client.endpoint.to_s).to eql('http://rest.ably.io')
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'fails when authenticating with basic auth' do
|
78
|
+
expect { client.channel('a').publish('event', 'message') }.to raise_error(Ably::InsecureRequestError)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'with no TLS option provided' do
|
83
|
+
let(:client) { Ably::Rest::Client.new(api_key: 'appid.keyid:secret') }
|
84
|
+
|
85
|
+
it 'defaults to TLS' do
|
86
|
+
expect(client.use_tls?).to eql(true)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'with alternative environment' do
|
91
|
+
let(:client) { Ably::Rest::Client.new(api_key: 'appid.keyid:secret', environment: 'sandbox') }
|
92
|
+
|
93
|
+
it 'should alter the endpoint' do
|
94
|
+
expect(client.endpoint.to_s).to eql('https://sandbox-rest.ably.io')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Ably::Token do
|
4
|
+
context 'defaults' do
|
5
|
+
let(:one_hour) { 60 * 60 }
|
6
|
+
let(:all_capabilities) { { "*" => ["*"] } }
|
7
|
+
|
8
|
+
it 'should default TTL to 1 hour' do
|
9
|
+
expect(Ably::Token::DEFAULTS[:ttl]).to eql(one_hour)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should default capability to all' do
|
13
|
+
expect(Ably::Token::DEFAULTS[:capability]).to eql(all_capabilities)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should only have defaults for :ttl and :capability' do
|
17
|
+
expect(Ably::Token::DEFAULTS.keys).to contain_exactly(:ttl, :capability)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'attributes' do
|
22
|
+
let(:unique_value) { 'unique_value' }
|
23
|
+
|
24
|
+
%w(id capability client_id nonce).each do |attribute|
|
25
|
+
context "##{attribute}" do
|
26
|
+
subject { Ably::Token.new({ attribute.to_sym => unique_value }) }
|
27
|
+
|
28
|
+
it "retrieves attribute :#{attribute}" do
|
29
|
+
expect(subject.public_send(attribute)).to eql(unique_value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context '#key_id' do
|
35
|
+
subject { Ably::Token.new({ key: unique_value }) }
|
36
|
+
it 'retrieves attribute :key' do
|
37
|
+
expect(subject.key_id).to eql(unique_value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
{ :issued_at => :issued_at, :expires_at => :expires }.each do |method_name, attribute|
|
42
|
+
let(:time) { Time.now }
|
43
|
+
context "##{method_name}" do
|
44
|
+
subject { Ably::Token.new({ attribute.to_sym => time.to_i }) }
|
45
|
+
|
46
|
+
it "retrieves attribute :#{attribute} as Time" do
|
47
|
+
expect(subject.public_send(method_name)).to be_a(Time)
|
48
|
+
expect(subject.public_send(method_name).to_i).to eql(time.to_i)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context '#expired?' do
|
54
|
+
let(:expire_time) { Time.now + Ably::Token::TOKEN_EXPIRY_BUFFER }
|
55
|
+
|
56
|
+
context 'once grace period buffer has passed' do
|
57
|
+
subject { Ably::Token.new(expires: expire_time - 1) }
|
58
|
+
|
59
|
+
it 'is true' do
|
60
|
+
expect(subject.expired?).to eql(true)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'within grace period buffer' do
|
65
|
+
subject { Ably::Token.new(expires: expire_time + 1) }
|
66
|
+
|
67
|
+
it 'is false' do
|
68
|
+
expect(subject.expired?).to eql(false)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context '==' do
|
75
|
+
let(:token_attributes) { { id: 'unique' } }
|
76
|
+
|
77
|
+
it 'is true when attributes are the same' do
|
78
|
+
new_token = -> { Ably::Token.new(token_attributes) }
|
79
|
+
expect(new_token[]).to eq(new_token[])
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'is false when attributes are not the same' do
|
83
|
+
expect(Ably::Token.new(id: 1)).to_not eq(Ably::Token.new(id: 2))
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'is false when class type differs' do
|
87
|
+
expect(Ably::Token.new(id: 1)).to_not eq(nil)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
metadata
ADDED
@@ -0,0 +1,240 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ably
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lewis Marshall
|
8
|
+
- Matthew O'Riordan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: eventmachine
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: faraday
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0.9'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0.9'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: json
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: websocket-driver
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bundler
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.3'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.3'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rake
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: redcarpet
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: rspec
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '3.0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '3.0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: yard
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: webmock
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
description: A Ruby client library for ably.io, the real-time messaging service
|
155
|
+
email:
|
156
|
+
- lewis@lmars.net
|
157
|
+
- matt@ably.io
|
158
|
+
executables: []
|
159
|
+
extensions: []
|
160
|
+
extra_rdoc_files: []
|
161
|
+
files:
|
162
|
+
- ".gitignore"
|
163
|
+
- Gemfile
|
164
|
+
- LICENSE.txt
|
165
|
+
- README.md
|
166
|
+
- Rakefile
|
167
|
+
- ably.gemspec
|
168
|
+
- lib/ably.rb
|
169
|
+
- lib/ably/auth.rb
|
170
|
+
- lib/ably/exceptions.rb
|
171
|
+
- lib/ably/realtime.rb
|
172
|
+
- lib/ably/realtime/callbacks.rb
|
173
|
+
- lib/ably/realtime/channel.rb
|
174
|
+
- lib/ably/realtime/client.rb
|
175
|
+
- lib/ably/realtime/connection.rb
|
176
|
+
- lib/ably/rest.rb
|
177
|
+
- lib/ably/rest/channel.rb
|
178
|
+
- lib/ably/rest/client.rb
|
179
|
+
- lib/ably/rest/middleware/exceptions.rb
|
180
|
+
- lib/ably/rest/middleware/external_exceptions.rb
|
181
|
+
- lib/ably/rest/middleware/parse_json.rb
|
182
|
+
- lib/ably/rest/paged_resource.rb
|
183
|
+
- lib/ably/rest/presence.rb
|
184
|
+
- lib/ably/support.rb
|
185
|
+
- lib/ably/token.rb
|
186
|
+
- lib/ably/version.rb
|
187
|
+
- spec/acceptance/realtime_client_spec.rb
|
188
|
+
- spec/acceptance/rest/auth_spec.rb
|
189
|
+
- spec/acceptance/rest/base_spec.rb
|
190
|
+
- spec/acceptance/rest/channel_spec.rb
|
191
|
+
- spec/acceptance/rest/presence_spec.rb
|
192
|
+
- spec/acceptance/rest/stats_spec.rb
|
193
|
+
- spec/acceptance/rest/time_spec.rb
|
194
|
+
- spec/spec_helper.rb
|
195
|
+
- spec/support/api_helper.rb
|
196
|
+
- spec/support/test_app.rb
|
197
|
+
- spec/unit/auth.rb
|
198
|
+
- spec/unit/realtime_spec.rb
|
199
|
+
- spec/unit/rest_spec.rb
|
200
|
+
- spec/unit/token_spec.rb
|
201
|
+
homepage: http://github.com/ably/ably-ruby
|
202
|
+
licenses:
|
203
|
+
- MIT
|
204
|
+
metadata: {}
|
205
|
+
post_install_message:
|
206
|
+
rdoc_options: []
|
207
|
+
require_paths:
|
208
|
+
- lib
|
209
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
210
|
+
requirements:
|
211
|
+
- - ">="
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: '0'
|
214
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
|
+
requirements:
|
216
|
+
- - ">="
|
217
|
+
- !ruby/object:Gem::Version
|
218
|
+
version: '0'
|
219
|
+
requirements: []
|
220
|
+
rubyforge_project:
|
221
|
+
rubygems_version: 2.2.2
|
222
|
+
signing_key:
|
223
|
+
specification_version: 4
|
224
|
+
summary: A Ruby client library for ably.io, the real-time messaging service
|
225
|
+
test_files:
|
226
|
+
- spec/acceptance/realtime_client_spec.rb
|
227
|
+
- spec/acceptance/rest/auth_spec.rb
|
228
|
+
- spec/acceptance/rest/base_spec.rb
|
229
|
+
- spec/acceptance/rest/channel_spec.rb
|
230
|
+
- spec/acceptance/rest/presence_spec.rb
|
231
|
+
- spec/acceptance/rest/stats_spec.rb
|
232
|
+
- spec/acceptance/rest/time_spec.rb
|
233
|
+
- spec/spec_helper.rb
|
234
|
+
- spec/support/api_helper.rb
|
235
|
+
- spec/support/test_app.rb
|
236
|
+
- spec/unit/auth.rb
|
237
|
+
- spec/unit/realtime_spec.rb
|
238
|
+
- spec/unit/rest_spec.rb
|
239
|
+
- spec/unit/token_spec.rb
|
240
|
+
has_rdoc:
|