ably 1.1.4.rc → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ describe Ably::Rest::Client do
12
12
  http_defaults = Ably::Rest::Client::HTTP_DEFAULTS
13
13
 
14
14
  def encode64(text)
15
- Base64.encode64(text).gsub("\n", '')
15
+ Base64.urlsafe_encode64(text)
16
16
  end
17
17
 
18
18
  context '#initialize' do
@@ -56,14 +56,6 @@ describe Ably::Rest::Client do
56
56
  end
57
57
  end
58
58
 
59
- context 'with a :client_id configured' do
60
- let(:client) { Ably::Rest::Client.new(client_options.merge(key: api_key, client_id: random_str)) }
61
-
62
- it 'uses token authentication' do
63
- expect(client.auth).to be_using_token_auth
64
- end
65
- end
66
-
67
59
  context 'with a non string :client_id' do
68
60
  let(:client) { Ably::Rest::Client.new(client_options.merge(key: api_key, client_id: 1)) }
69
61
 
@@ -144,11 +136,12 @@ describe Ably::Rest::Client do
144
136
  let(:history_querystring) { history_params.map { |k, v| "#{k}=#{v}" }.join("&") }
145
137
 
146
138
  context 'with basic auth', webmock: true do
147
- let(:client_options) { default_options.merge(key: api_key) }
139
+ let(:client_options) { default_options.merge(key: api_key, client_id: client_id) }
148
140
 
149
141
  let!(:get_message_history_stub) do
150
- stub_request(:get, "https://#{environment}-#{Ably::Rest::Client::DOMAIN}/channels/#{channel_name}/messages?#{history_querystring}").
151
- to_return(body: [], headers: { 'Content-Type' => 'application/json' })
142
+ stub_request(:get, "https://#{environment}-#{Ably::Rest::Client::DOMAIN}/channels/#{channel_name}/messages?#{history_querystring}")
143
+ .with(headers: { 'X-Ably-ClientId' => encode64(client_id) })
144
+ .to_return(body: [], headers: { 'Content-Type' => 'application/json' })
152
145
  end
153
146
 
154
147
  it 'sends the API key in authentication part of the secure URL (the Authorization: Basic header is not used with the Faraday HTTP library by default)' do
@@ -1091,6 +1084,8 @@ describe Ably::Rest::Client do
1091
1084
 
1092
1085
  context '#request (#RSC19*)' do
1093
1086
  let(:client_options) { default_options.merge(key: api_key) }
1087
+ let(:device_id) { random_str }
1088
+ let(:endpoint) { client.endpoint }
1094
1089
 
1095
1090
  context 'get' do
1096
1091
  it 'returns an HttpPaginatedResponse object' do
@@ -1130,6 +1125,71 @@ describe Ably::Rest::Client do
1130
1125
  end
1131
1126
  end
1132
1127
  end
1128
+
1129
+ context 'post', :webmock do
1130
+ before do
1131
+ stub_request(:delete, "#{endpoint}/push/deviceRegistrations/#{device_id}/resetUpdateToken").
1132
+ to_return(status: 200, body: '{}', headers: { 'Content-Type' => 'application/json' })
1133
+ end
1134
+
1135
+ it 'supports post' do
1136
+ response = client.request(:delete, "push/deviceRegistrations/#{device_id}/resetUpdateToken")
1137
+
1138
+ expect(response).to be_success
1139
+ end
1140
+ end
1141
+
1142
+ context 'delete', :webmock do
1143
+ before do
1144
+ stub_request(:delete, "#{endpoint}/push/channelSubscriptions?deviceId=#{device_id}").
1145
+ to_return(status: 200, body: '{}', headers: { 'Content-Type' => 'application/json' })
1146
+ end
1147
+
1148
+ it 'supports delete' do
1149
+ response = client.request(:delete, "/push/channelSubscriptions", { deviceId: device_id})
1150
+
1151
+ expect(response).to be_success
1152
+ end
1153
+ end
1154
+
1155
+ context 'patch', :webmock do
1156
+ let(:body_params) { { 'metadata' => { 'key' => 'value' } } }
1157
+
1158
+ before do
1159
+ stub_request(:patch, "#{endpoint}/push/deviceRegistrations/#{device_id}")
1160
+ .with(body: serialize_body(body_params, protocol))
1161
+ .to_return(status: 200, body: '{}', headers: { 'Content-Type' => 'application/json' })
1162
+ end
1163
+
1164
+ it 'supports patch' do
1165
+ response = client.request(:patch, "/push/deviceRegistrations/#{device_id}", {}, body_params)
1166
+
1167
+ expect(response).to be_success
1168
+ end
1169
+ end
1170
+
1171
+ context 'put', :webmock do
1172
+ let(:body_params) do
1173
+ {
1174
+ 'id' => random_str,
1175
+ 'platform' => 'ios',
1176
+ 'formFactor' => 'phone',
1177
+ 'metadata' => { 'key' => 'value' }
1178
+ }
1179
+ end
1180
+
1181
+ before do
1182
+ stub_request(:put, "#{endpoint}/push/deviceRegistrations/#{device_id}")
1183
+ .with(body: serialize_body(body_params, protocol))
1184
+ .to_return(status: 200, body: '{}', headers: { 'Content-Type' => 'application/json' })
1185
+ end
1186
+
1187
+ it 'supports put' do
1188
+ response = client.request(:put, "/push/deviceRegistrations/#{device_id}", {}, body_params)
1189
+
1190
+ expect(response).to be_success
1191
+ end
1192
+ end
1133
1193
  end
1134
1194
 
1135
1195
  context 'request_id generation' do
@@ -89,31 +89,15 @@ describe Ably::Rest::Push::Admin do
89
89
  end
90
90
  end
91
91
 
92
- def request_body(request, protocol)
93
- if protocol == :msgpack
94
- MessagePack.unpack(request.body)
95
- else
96
- JSON.parse(request.body)
97
- end
98
- end
99
-
100
- def serialize(object, protocol)
101
- if protocol == :msgpack
102
- MessagePack.pack(object)
103
- else
104
- JSON.dump(object)
105
- end
106
- end
107
-
108
92
  let!(:publish_stub) do
109
93
  stub_request(:post, "#{client.endpoint}/push/publish").
110
94
  with do |request|
111
- expect(request_body(request, protocol)['recipient']['camelCase']['secondLevelCamelCase']).to eql('val')
112
- expect(request_body(request, protocol)['recipient']).to_not have_key('camel_case')
95
+ expect(deserialize_body(request.body, protocol)['recipient']['camelCase']['secondLevelCamelCase']).to eql('val')
96
+ expect(deserialize_body(request.body, protocol)['recipient']).to_not have_key('camel_case')
113
97
  true
114
98
  end.to_return(
115
99
  :status => 201,
116
- :body => serialize({}, protocol),
100
+ :body => serialize_body({}, protocol),
117
101
  :headers => { 'Content-Type' => content_type }
118
102
  )
119
103
  end
@@ -69,14 +69,6 @@ shared_examples 'a client initializer' do
69
69
  expect { subject }.to raise_error(ArgumentError, /key and key_name or key_secret are mutually exclusive/)
70
70
  end
71
71
  end
72
-
73
- context 'client_id as only option' do
74
- let(:client_options) { { client_id: 'valid' } }
75
-
76
- it 'requires a valid key' do
77
- expect { subject }.to raise_error(ArgumentError, /client_id cannot be provided without a complete API key or means to authenticate/)
78
- end
79
- end
80
72
  end
81
73
 
82
74
  context 'with valid arguments' do
data/spec/spec_helper.rb CHANGED
@@ -19,6 +19,7 @@ require 'support/event_emitter_helper'
19
19
  require 'support/private_api_formatter'
20
20
  require 'support/protocol_helper'
21
21
  require 'support/random_helper'
22
+ require 'support/serialization_helper'
22
23
  require 'support/test_logger_helper'
23
24
 
24
25
  require 'rspec_config'
@@ -0,0 +1,21 @@
1
+ module SerializationHelper
2
+ def serialize_body(object, protocol)
3
+ if protocol == :msgpack
4
+ MessagePack.pack(object)
5
+ else
6
+ JSON.dump(object)
7
+ end
8
+ end
9
+
10
+ def deserialize_body(object, protocol)
11
+ if protocol == :msgpack
12
+ MessagePack.unpack(object)
13
+ else
14
+ JSON.parse(object)
15
+ end
16
+ end
17
+
18
+ RSpec.configure do |config|
19
+ config.include self
20
+ end
21
+ end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  require 'shared/client_initializer_behaviour'
4
4
 
5
5
  describe Ably::Realtime::Client do
6
- subject do
6
+ subject(:realtime_client) do
7
7
  Ably::Realtime::Client.new(client_options)
8
8
  end
9
9
 
@@ -15,28 +15,41 @@ describe Ably::Realtime::Client do
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, environment: 'production', use_tls?: true, custom_tls_port: nil)
17
17
  expect(Ably::Rest::Client).to receive(:new).with(hash_including(client_options)).and_return(rest_client)
18
- subject
18
+ realtime_client
19
19
  end
20
20
 
21
21
  context 'for attribute' do
22
22
  [:environment, :use_tls?, :log_level, :custom_host].each do |attribute|
23
23
  specify "##{attribute}" do
24
- expect(subject.rest_client).to receive(attribute)
25
- subject.public_send attribute
24
+ expect(realtime_client.rest_client).to receive(attribute)
25
+ realtime_client.public_send attribute
26
26
  end
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
+ context 'when :transport_params option is passed' do
32
+ let(:expected_transport_params) do
33
+ { 'heartbeats' => 'true', 'v' => '1.0', 'extra_param' => 'extra_param' }
34
+ end
35
+ let(:client_options) do
36
+ { key: 'appid.keyuid:keysecret', transport_params: { heartbeats: true, v: 1.0, extra_param: 'extra_param'} }
37
+ end
38
+
39
+ it 'converts options to strings' do
40
+ expect(realtime_client.transport_params).to eq(expected_transport_params)
41
+ end
42
+ end
43
+
31
44
  context 'push' do
32
45
  let(:client_options) { { key: 'appid.keyuid:keysecret' } }
33
46
 
34
47
  specify '#device is not supported and raises an exception' do
35
- expect { subject.device }.to raise_error Ably::Exceptions::PushNotificationsNotSupported
48
+ expect { realtime_client.device }.to raise_error Ably::Exceptions::PushNotificationsNotSupported
36
49
  end
37
50
 
38
51
  specify '#push returns a Push object' do
39
- expect(subject.push).to be_a(Ably::Realtime::Push)
52
+ expect(realtime_client.push).to be_a(Ably::Realtime::Push)
40
53
  end
41
54
  end
42
55
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ably
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4.rc
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lewis Marshall
8
8
  - Matthew O'Riordan
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-16 00:00:00.000000000 Z
12
+ date: 2021-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -45,42 +45,48 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: 1.0.0
48
+ version: '7.4'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: 1.0.0
55
+ version: '7.4'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: faraday
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "~>"
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: '1.0'
62
+ version: '0.12'
63
+ - - "<"
64
+ - !ruby/object:Gem::Version
65
+ version: 2.0.0
63
66
  type: :runtime
64
67
  prerelease: false
65
68
  version_requirements: !ruby/object:Gem::Requirement
66
69
  requirements:
67
- - - "~>"
70
+ - - ">="
68
71
  - !ruby/object:Gem::Version
69
- version: '1.0'
72
+ version: '0.12'
73
+ - - "<"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.0
70
76
  - !ruby/object:Gem::Dependency
71
- name: typhoeus
77
+ name: excon
72
78
  requirement: !ruby/object:Gem::Requirement
73
79
  requirements:
74
80
  - - "~>"
75
81
  - !ruby/object:Gem::Version
76
- version: '1.4'
82
+ version: '0.55'
77
83
  type: :runtime
78
84
  prerelease: false
79
85
  version_requirements: !ruby/object:Gem::Requirement
80
86
  requirements:
81
87
  - - "~>"
82
88
  - !ruby/object:Gem::Version
83
- version: '1.4'
89
+ version: '0.55'
84
90
  - !ruby/object:Gem::Dependency
85
91
  name: json
86
92
  requirement: !ruby/object:Gem::Requirement
@@ -143,14 +149,14 @@ dependencies:
143
149
  requirements:
144
150
  - - "~>"
145
151
  - !ruby/object:Gem::Version
146
- version: '13.0'
152
+ version: '11.3'
147
153
  type: :development
148
154
  prerelease: false
149
155
  version_requirements: !ruby/object:Gem::Requirement
150
156
  requirements:
151
157
  - - "~>"
152
158
  - !ruby/object:Gem::Version
153
- version: '13.0'
159
+ version: '11.3'
154
160
  - !ruby/object:Gem::Dependency
155
161
  name: redcarpet
156
162
  requirement: !ruby/object:Gem::Requirement
@@ -171,14 +177,14 @@ dependencies:
171
177
  requirements:
172
178
  - - "~>"
173
179
  - !ruby/object:Gem::Version
174
- version: 3.10.0
180
+ version: 3.3.0
175
181
  type: :development
176
182
  prerelease: false
177
183
  version_requirements: !ruby/object:Gem::Requirement
178
184
  requirements:
179
185
  - - "~>"
180
186
  - !ruby/object:Gem::Version
181
- version: 3.10.0
187
+ version: 3.3.0
182
188
  - !ruby/object:Gem::Dependency
183
189
  name: rspec-retry
184
190
  requirement: !ruby/object:Gem::Requirement
@@ -225,30 +231,30 @@ dependencies:
225
231
  name: bundler
226
232
  requirement: !ruby/object:Gem::Requirement
227
233
  requirements:
228
- - - "~>"
234
+ - - ">="
229
235
  - !ruby/object:Gem::Version
230
- version: 2.2.1
236
+ version: 1.3.0
231
237
  type: :development
232
238
  prerelease: false
233
239
  version_requirements: !ruby/object:Gem::Requirement
234
240
  requirements:
235
- - - "~>"
241
+ - - ">="
236
242
  - !ruby/object:Gem::Version
237
- version: 2.2.1
243
+ version: 1.3.0
238
244
  - !ruby/object:Gem::Dependency
239
245
  name: webmock
240
246
  requirement: !ruby/object:Gem::Requirement
241
247
  requirements:
242
248
  - - "~>"
243
249
  - !ruby/object:Gem::Version
244
- version: '2.2'
250
+ version: '3.11'
245
251
  type: :development
246
252
  prerelease: false
247
253
  version_requirements: !ruby/object:Gem::Requirement
248
254
  requirements:
249
255
  - - "~>"
250
256
  - !ruby/object:Gem::Version
251
- version: '2.2'
257
+ version: '3.11'
252
258
  - !ruby/object:Gem::Dependency
253
259
  name: coveralls
254
260
  requirement: !ruby/object:Gem::Requirement
@@ -314,13 +320,15 @@ extensions: []
314
320
  extra_rdoc_files: []
315
321
  files:
316
322
  - ".editorconfig"
323
+ - ".github/workflows/check.yml"
317
324
  - ".gitignore"
318
325
  - ".gitmodules"
319
326
  - ".rspec"
320
- - ".travis.yml"
321
327
  - CHANGELOG.md
328
+ - COPYRIGHT
322
329
  - Gemfile
323
330
  - LICENSE
331
+ - MAINTAINERS.md
324
332
  - README.md
325
333
  - Rakefile
326
334
  - SPEC.md
@@ -377,6 +385,7 @@ files:
377
385
  - lib/ably/realtime/auth.rb
378
386
  - lib/ably/realtime/channel.rb
379
387
  - lib/ably/realtime/channel/channel_manager.rb
388
+ - lib/ably/realtime/channel/channel_properties.rb
380
389
  - lib/ably/realtime/channel/channel_state_machine.rb
381
390
  - lib/ably/realtime/channel/publisher.rb
382
391
  - lib/ably/realtime/channel/push_channel.rb
@@ -460,6 +469,7 @@ files:
460
469
  - spec/support/protocol_helper.rb
461
470
  - spec/support/random_helper.rb
462
471
  - spec/support/rest_testapp_before_retry.rb
472
+ - spec/support/serialization_helper.rb
463
473
  - spec/support/test_app.rb
464
474
  - spec/support/test_logger_helper.rb
465
475
  - spec/unit/auth_spec.rb
@@ -512,7 +522,7 @@ homepage: http://github.com/ably/ably-ruby
512
522
  licenses:
513
523
  - Apache-2.0
514
524
  metadata: {}
515
- post_install_message:
525
+ post_install_message:
516
526
  rdoc_options: []
517
527
  require_paths:
518
528
  - lib
@@ -523,12 +533,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
523
533
  version: '0'
524
534
  required_rubygems_version: !ruby/object:Gem::Requirement
525
535
  requirements:
526
- - - ">"
536
+ - - ">="
527
537
  - !ruby/object:Gem::Version
528
- version: 1.3.1
538
+ version: '0'
529
539
  requirements: []
530
540
  rubygems_version: 3.0.3
531
- signing_key:
541
+ signing_key:
532
542
  specification_version: 4
533
543
  summary: A Ruby client library for ably.io realtime messaging implemented using EventMachine
534
544
  test_files:
@@ -574,6 +584,7 @@ test_files:
574
584
  - spec/support/protocol_helper.rb
575
585
  - spec/support/random_helper.rb
576
586
  - spec/support/rest_testapp_before_retry.rb
587
+ - spec/support/serialization_helper.rb
577
588
  - spec/support/test_app.rb
578
589
  - spec/support/test_logger_helper.rb
579
590
  - spec/unit/auth_spec.rb