ringcentral-sdk 1.0.0.pre.beta.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -17
- data/lib/ringcentral.rb +1 -6
- data/lib/subscription.rb +0 -79
- data/ringcentral-sdk.gemspec +5 -6
- data/spec/fax_spec.rb +2 -0
- data/spec/mms_spec.rb +15 -14
- data/spec/query_params_spec.rb +2 -0
- data/spec/ringcentral_spec.rb +13 -13
- data/spec/websocket_subscription_spec.rb +6 -4
- metadata +14 -36
- data/spec/pubnub_subscription_spec.rb +0 -80
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb3d49139090020a404bb081c1468d4439c2628afc355df576ac27c36bc29f6f
|
4
|
+
data.tar.gz: 44f29f3245d3766e87ee46b725f0f737e085e6d7e42d764fedc156b7095d503d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6351380d085117dfd916d66693be085e7785de57cff373344e8800a8f204a2632ca3cfd7aa382cfb16b30d9f5c67eb18d62a4662b3437a3f4ab0bd154019c7f6
|
7
|
+
data.tar.gz: 2e4f4b03ceb67b5d8aa4df33335b395c0f2241f63c1dd2bd356afd1048d0dec0ed5bba990738e6d747721edaf69bee87db5da60be25c016875d2e492e0c82a14
|
data/README.md
CHANGED
@@ -81,7 +81,7 @@ Access token expires. You need to call `rc.refresh()` before it expires.
|
|
81
81
|
If you want the SDK to do auto refresh please `rc.auto_refresh = true` before authorization.
|
82
82
|
|
83
83
|
|
84
|
-
### Load
|
84
|
+
### Load pre-existing token
|
85
85
|
|
86
86
|
Let's say you already have a token. Then you can load it like this: `rc.token = your_token_object`.
|
87
87
|
The benefit of loading a preexisting token is you don't need to go through any authorization flow.
|
@@ -165,26 +165,11 @@ subscription.on_ws_closed = lambda { |event|
|
|
165
165
|
}
|
166
166
|
```
|
167
167
|
|
168
|
-
### (deprecated) PubNub Subscriptions
|
169
|
-
|
170
|
-
```ruby
|
171
|
-
events = [
|
172
|
-
'/restapi/v1.0/account/~/extension/~/message-store',
|
173
|
-
]
|
174
|
-
subscription = PubNub.new(rc, events, lambda { |message|
|
175
|
-
puts message
|
176
|
-
})
|
177
|
-
subscription.subscribe()
|
178
|
-
```
|
179
|
-
|
180
|
-
|
181
|
-
For more sample codes, please refer to the [test cases](/spec).
|
182
|
-
|
183
168
|
|
184
169
|
## How to test
|
185
170
|
|
186
171
|
```
|
187
|
-
bundle install
|
172
|
+
bundle install
|
188
173
|
```
|
189
174
|
|
190
175
|
Rename `.env.sample` to `.env`.
|
data/lib/ringcentral.rb
CHANGED
@@ -4,13 +4,8 @@ require 'json'
|
|
4
4
|
require 'concurrent'
|
5
5
|
require 'faraday'
|
6
6
|
require 'faraday/multipart'
|
7
|
-
require 'tmpdir'
|
8
7
|
|
9
8
|
class RingCentral
|
10
|
-
def self.SANDBOX_SERVER
|
11
|
-
'https://platform.devtest.ringcentral.com'
|
12
|
-
end
|
13
|
-
|
14
9
|
def self.PRODUCTION_SERVER
|
15
10
|
'https://platform.ringcentral.com'
|
16
11
|
end
|
@@ -18,7 +13,7 @@ class RingCentral
|
|
18
13
|
attr_reader :client_id, :client_secret, :server, :token
|
19
14
|
attr_accessor :auto_refresh, :debug_mode
|
20
15
|
|
21
|
-
def initialize(client_id, client_secret, server, debug_mode = false)
|
16
|
+
def initialize(client_id, client_secret, server = self.PRODUCTION_SERVER, debug_mode = false)
|
22
17
|
@client_id = client_id
|
23
18
|
@client_secret = client_secret
|
24
19
|
@server = server
|
data/lib/subscription.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
require 'pubnub'
|
2
1
|
require 'concurrent'
|
3
|
-
require 'openssl'
|
4
|
-
require 'base64'
|
5
2
|
require 'faye/websocket'
|
6
3
|
require 'securerandom'
|
7
4
|
require 'eventmachine'
|
@@ -67,79 +64,3 @@ class WS
|
|
67
64
|
@t.kill
|
68
65
|
end
|
69
66
|
end
|
70
|
-
|
71
|
-
class PubNub
|
72
|
-
attr_accessor :events
|
73
|
-
|
74
|
-
def initialize(ringcentral, events, message_callback, status_callback = nil, presence_callback = nil)
|
75
|
-
warn('PubNub is deprecated. Use WS (WebSocket) instead.')
|
76
|
-
@rc = ringcentral
|
77
|
-
@events = events
|
78
|
-
@callback = Pubnub::SubscribeCallback.new(
|
79
|
-
message: lambda { |envelope|
|
80
|
-
message = envelope.result[:data][:message]
|
81
|
-
cipher = OpenSSL::Cipher::AES.new(128, :ECB)
|
82
|
-
cipher.decrypt
|
83
|
-
cipher.key = Base64.decode64(@subscription['deliveryMode']['encryptionKey'])
|
84
|
-
ciphertext = Base64.decode64(message)
|
85
|
-
plaintext = cipher.update(ciphertext) + cipher.final
|
86
|
-
message_callback.call(JSON.parse(plaintext))
|
87
|
-
},
|
88
|
-
presence: lambda { |envelope|
|
89
|
-
presence_callback != nil && presence_callback.call(envelope)
|
90
|
-
},
|
91
|
-
status: lambda { |envelope|
|
92
|
-
status_callback != nil && status_callback.call(envelope)
|
93
|
-
}
|
94
|
-
)
|
95
|
-
@subscription = nil
|
96
|
-
@timer = nil
|
97
|
-
@pubnub = nil
|
98
|
-
end
|
99
|
-
|
100
|
-
def subscription=(value)
|
101
|
-
@subscription = value
|
102
|
-
if @timer != nil
|
103
|
-
@timer.shutdown
|
104
|
-
@timer = nil
|
105
|
-
end
|
106
|
-
if value != nil
|
107
|
-
@timer = Concurrent::TimerTask.new(execution_interval: value['expiresIn'] - 120) do
|
108
|
-
self.refresh
|
109
|
-
end
|
110
|
-
@timer.execute
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def subscribe
|
115
|
-
r = @rc.post('/restapi/v1.0/subscription', payload: request_body)
|
116
|
-
self.subscription = r.body
|
117
|
-
@pubnub = Pubnub.new(subscribe_key: @subscription['deliveryMode']['subscriberKey'], user_id: @rc.token['owner_id'])
|
118
|
-
@pubnub.add_listener(name: 'default', callback: @callback)
|
119
|
-
@pubnub.subscribe(channels: @subscription['deliveryMode']['address'])
|
120
|
-
end
|
121
|
-
|
122
|
-
def refresh
|
123
|
-
return if @subscription == nil
|
124
|
-
r = @rc.put("/restapi/v1.0/subscription/#{@subscription['id']}", payload: request_body)
|
125
|
-
self.subscription = r.body
|
126
|
-
end
|
127
|
-
|
128
|
-
def revoke
|
129
|
-
return if @subscription == nil
|
130
|
-
@pubnub.unsubscribe(channel: @subscription['deliveryMode']['address'])
|
131
|
-
@pubnub.remove_listener(name: 'default')
|
132
|
-
@pubnub = nil
|
133
|
-
@rc.delete("/restapi/v1.0/subscription/#{@subscription['id']}")
|
134
|
-
self.subscription = nil
|
135
|
-
end
|
136
|
-
|
137
|
-
private
|
138
|
-
|
139
|
-
def request_body
|
140
|
-
{
|
141
|
-
'deliveryMode': { 'transportType': 'PubNub', 'encryption': true },
|
142
|
-
'eventFilters': @events
|
143
|
-
}
|
144
|
-
end
|
145
|
-
end
|
data/ringcentral-sdk.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'ringcentral-sdk'
|
3
|
-
gem.version = '1.0.0
|
3
|
+
gem.version = '1.0.0'
|
4
4
|
gem.authors = ['Tyler Liu']
|
5
5
|
gem.email = ['tyler.liu@ringcentral.com']
|
6
6
|
gem.description = 'Ruby SDK for you to access RingCentral platform API.'
|
@@ -13,10 +13,9 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.files += Dir['lib/**/*.rb']
|
14
14
|
gem.test_files = Dir['spec/**/*.rb']
|
15
15
|
|
16
|
-
gem.add_dependency('addressable', '~> 2.8', '>= 2.8.
|
17
|
-
gem.add_dependency('concurrent-ruby', '~> 1.2', '>= 1.2.
|
18
|
-
gem.add_dependency('
|
19
|
-
gem.add_dependency('faraday', '~> 2.7', '>= 2.7.4')
|
16
|
+
gem.add_dependency('addressable', '~> 2.8', '>= 2.8.6')
|
17
|
+
gem.add_dependency('concurrent-ruby', '~> 1.2', '>= 1.2.3')
|
18
|
+
gem.add_dependency('faraday', '~> 2.9', '>= 2.9.0')
|
20
19
|
gem.add_dependency('faraday-multipart', '~> 1.0', '>= 1.0.4')
|
21
|
-
gem.add_dependency('faye-websocket', '~> 0.11', '>= 0.11.
|
20
|
+
gem.add_dependency('faye-websocket', '~> 0.11', '>= 0.11.3')
|
22
21
|
end
|
data/spec/fax_spec.rb
CHANGED
data/spec/mms_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'dotenv'
|
2
2
|
require 'ringcentral'
|
3
|
+
require "simplecov"
|
4
|
+
SimpleCov.start
|
3
5
|
|
4
6
|
RSpec.describe 'MMS' do
|
5
7
|
describe 'send MMS' do
|
@@ -8,20 +10,19 @@ RSpec.describe 'MMS' do
|
|
8
10
|
rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
|
9
11
|
rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# expect('SMS').to eq(message['type'])
|
13
|
+
r = rc.post('/restapi/v1.0/account/~/extension/~/sms',
|
14
|
+
payload: {
|
15
|
+
to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }],
|
16
|
+
from: { phoneNumber: ENV['RINGCENTRAL_SENDER'] },
|
17
|
+
text: 'hello world'
|
18
|
+
},
|
19
|
+
files: [
|
20
|
+
['spec/test.png', 'image/png']
|
21
|
+
]
|
22
|
+
)
|
23
|
+
expect(r).not_to be_nil
|
24
|
+
message = r.body
|
25
|
+
expect('SMS').to eq(message['type'])
|
25
26
|
|
26
27
|
rc.revoke()
|
27
28
|
end
|
data/spec/query_params_spec.rb
CHANGED
data/spec/ringcentral_spec.rb
CHANGED
@@ -1,23 +1,24 @@
|
|
1
1
|
require 'ringcentral'
|
2
|
+
require "simplecov"
|
3
|
+
SimpleCov.start
|
2
4
|
|
3
5
|
RSpec.describe 'RingCentral' do
|
4
6
|
describe 'ringcentral' do
|
5
7
|
it 'test_class_variables' do
|
6
|
-
expect('https://platform.devtest.ringcentral.com').to eq(RingCentral.SANDBOX_SERVER)
|
7
8
|
expect('https://platform.ringcentral.com').to eq(RingCentral.PRODUCTION_SERVER)
|
8
9
|
end
|
9
10
|
|
10
11
|
it 'test_initializer' do
|
11
|
-
rc = RingCentral.new('client_id', 'client_secret', RingCentral.
|
12
|
+
rc = RingCentral.new('client_id', 'client_secret', RingCentral.PRODUCTION_SERVER)
|
12
13
|
expect('client_id').to eq(rc.client_id)
|
13
14
|
expect('client_secret').to eq(rc.client_secret)
|
14
|
-
expect('https://platform.
|
15
|
+
expect('https://platform.ringcentral.com').to eq(rc.server)
|
15
16
|
expect(false).to eq(rc.auto_refresh)
|
16
17
|
end
|
17
18
|
|
18
19
|
it 'test_authorize_uri' do
|
19
|
-
rc = RingCentral.new('client_id', 'client_secret', RingCentral.
|
20
|
-
expect(RingCentral.
|
20
|
+
rc = RingCentral.new('client_id', 'client_secret', RingCentral.PRODUCTION_SERVER)
|
21
|
+
expect(RingCentral.PRODUCTION_SERVER + '/restapi/oauth/authorize?client_id=client_id&redirect_uri=https%3A%2F%2Fexample.com&response_type=code&state=mystate').to eq(rc.authorize_uri('https://example.com', {state: 'mystate'}))
|
21
22
|
end
|
22
23
|
|
23
24
|
it 'test_jwt_flow' do
|
@@ -46,7 +47,7 @@ RSpec.describe 'RingCentral' do
|
|
46
47
|
# get
|
47
48
|
r = rc.get('/restapi/v1.0/account/~/extension/~')
|
48
49
|
expect(r).not_to be_nil
|
49
|
-
expect(
|
50
|
+
expect(r.body['extensionNumber']).not_to be_nil
|
50
51
|
|
51
52
|
# post
|
52
53
|
r = rc.post('/restapi/v1.0/account/~/extension/~/company-pager', payload: {
|
@@ -72,13 +73,12 @@ RSpec.describe 'RingCentral' do
|
|
72
73
|
# todo: test patch
|
73
74
|
|
74
75
|
# delete
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
# expect('Deleted').to eq(message['availability'])
|
76
|
+
r = rc.delete(messageUrl)
|
77
|
+
expect(r).not_to be_nil
|
78
|
+
r = rc.get(messageUrl)
|
79
|
+
expect(r).not_to be_nil
|
80
|
+
message = r.body
|
81
|
+
expect('Deleted').to eq(message['availability'])
|
82
82
|
|
83
83
|
rc.revoke()
|
84
84
|
end
|
@@ -2,6 +2,8 @@ require 'ringcentral'
|
|
2
2
|
require 'subscription'
|
3
3
|
require 'dotenv'
|
4
4
|
require 'rspec'
|
5
|
+
require "simplecov"
|
6
|
+
SimpleCov.start
|
5
7
|
|
6
8
|
Dotenv.load
|
7
9
|
$rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
|
@@ -34,17 +36,17 @@ RSpec.describe 'WebSocket Subscription' do
|
|
34
36
|
from: {extensionId: $rc.token['owner_id']},
|
35
37
|
text: 'Hello world'
|
36
38
|
})
|
37
|
-
sleep(
|
39
|
+
sleep(10)
|
38
40
|
expect(count).to be > 0
|
39
41
|
|
40
42
|
# sleep for some time and see if the websocket is still alive
|
41
|
-
sleep(
|
43
|
+
sleep(20)
|
42
44
|
$rc.post('/restapi/v1.0/account/~/extension/~/company-pager', payload: {
|
43
45
|
to: [{extensionId: $rc.token['owner_id']}],
|
44
46
|
from: {extensionId: $rc.token['owner_id']},
|
45
47
|
text: 'Hello world'
|
46
48
|
})
|
47
|
-
sleep(
|
49
|
+
sleep(10)
|
48
50
|
expect(count).to be > 1
|
49
51
|
|
50
52
|
sub.revoke()
|
@@ -65,7 +67,7 @@ RSpec.describe 'WebSocket Subscription' do
|
|
65
67
|
from: {extensionId: $rc.token['owner_id']},
|
66
68
|
text: 'Hello world'
|
67
69
|
})
|
68
|
-
sleep(
|
70
|
+
sleep(10)
|
69
71
|
|
70
72
|
expect(count).to eq(0)
|
71
73
|
$rc.revoke()
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ringcentral-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Liu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '2.8'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 2.8.
|
22
|
+
version: 2.8.6
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '2.8'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 2.8.
|
32
|
+
version: 2.8.6
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: concurrent-ruby
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: '1.2'
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 1.2.
|
42
|
+
version: 1.2.3
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,47 +49,27 @@ dependencies:
|
|
49
49
|
version: '1.2'
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: 1.2.
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: pubnub
|
55
|
-
requirement: !ruby/object:Gem::Requirement
|
56
|
-
requirements:
|
57
|
-
- - "~>"
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: '5.2'
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 5.2.2
|
63
|
-
type: :runtime
|
64
|
-
prerelease: false
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
66
|
-
requirements:
|
67
|
-
- - "~>"
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '5.2'
|
70
|
-
- - ">="
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
version: 5.2.2
|
52
|
+
version: 1.2.3
|
73
53
|
- !ruby/object:Gem::Dependency
|
74
54
|
name: faraday
|
75
55
|
requirement: !ruby/object:Gem::Requirement
|
76
56
|
requirements:
|
77
57
|
- - "~>"
|
78
58
|
- !ruby/object:Gem::Version
|
79
|
-
version: '2.
|
59
|
+
version: '2.9'
|
80
60
|
- - ">="
|
81
61
|
- !ruby/object:Gem::Version
|
82
|
-
version: 2.
|
62
|
+
version: 2.9.0
|
83
63
|
type: :runtime
|
84
64
|
prerelease: false
|
85
65
|
version_requirements: !ruby/object:Gem::Requirement
|
86
66
|
requirements:
|
87
67
|
- - "~>"
|
88
68
|
- !ruby/object:Gem::Version
|
89
|
-
version: '2.
|
69
|
+
version: '2.9'
|
90
70
|
- - ">="
|
91
71
|
- !ruby/object:Gem::Version
|
92
|
-
version: 2.
|
72
|
+
version: 2.9.0
|
93
73
|
- !ruby/object:Gem::Dependency
|
94
74
|
name: faraday-multipart
|
95
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,7 +99,7 @@ dependencies:
|
|
119
99
|
version: '0.11'
|
120
100
|
- - ">="
|
121
101
|
- !ruby/object:Gem::Version
|
122
|
-
version: 0.11.
|
102
|
+
version: 0.11.3
|
123
103
|
type: :runtime
|
124
104
|
prerelease: false
|
125
105
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -129,7 +109,7 @@ dependencies:
|
|
129
109
|
version: '0.11'
|
130
110
|
- - ">="
|
131
111
|
- !ruby/object:Gem::Version
|
132
|
-
version: 0.11.
|
112
|
+
version: 0.11.3
|
133
113
|
description: Ruby SDK for you to access RingCentral platform API.
|
134
114
|
email:
|
135
115
|
- tyler.liu@ringcentral.com
|
@@ -143,7 +123,6 @@ files:
|
|
143
123
|
- ringcentral-sdk.gemspec
|
144
124
|
- spec/fax_spec.rb
|
145
125
|
- spec/mms_spec.rb
|
146
|
-
- spec/pubnub_subscription_spec.rb
|
147
126
|
- spec/query_params_spec.rb
|
148
127
|
- spec/ringcentral_spec.rb
|
149
128
|
- spec/websocket_subscription_spec.rb
|
@@ -162,9 +141,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
141
|
version: '0'
|
163
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
143
|
requirements:
|
165
|
-
- - "
|
144
|
+
- - ">="
|
166
145
|
- !ruby/object:Gem::Version
|
167
|
-
version:
|
146
|
+
version: '0'
|
168
147
|
requirements: []
|
169
148
|
rubygems_version: 3.4.10
|
170
149
|
signing_key:
|
@@ -173,7 +152,6 @@ summary: RingCentral Ruby SDK.
|
|
173
152
|
test_files:
|
174
153
|
- spec/fax_spec.rb
|
175
154
|
- spec/mms_spec.rb
|
176
|
-
- spec/pubnub_subscription_spec.rb
|
177
155
|
- spec/query_params_spec.rb
|
178
156
|
- spec/ringcentral_spec.rb
|
179
157
|
- spec/websocket_subscription_spec.rb
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'ringcentral'
|
2
|
-
require 'subscription'
|
3
|
-
require 'dotenv'
|
4
|
-
require 'rspec'
|
5
|
-
|
6
|
-
Dotenv.load
|
7
|
-
$rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
|
8
|
-
|
9
|
-
RSpec.describe 'PubNub Subscription' do
|
10
|
-
def createSubscription(callback)
|
11
|
-
events = [
|
12
|
-
'/restapi/v1.0/account/~/extension/~/message-store?type=Pager',
|
13
|
-
]
|
14
|
-
subscription = PubNub.new($rc, events, lambda { |message|
|
15
|
-
callback.call(message)
|
16
|
-
})
|
17
|
-
subscription.subscribe()
|
18
|
-
return subscription
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'PubNub Subscription' do
|
22
|
-
it 'receives message notification' do
|
23
|
-
$rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
24
|
-
count = 0
|
25
|
-
createSubscription(lambda { |message|
|
26
|
-
count += 1
|
27
|
-
})
|
28
|
-
|
29
|
-
$rc.post('/restapi/v1.0/account/~/extension/~/company-pager', payload: {
|
30
|
-
to: [{extensionId: $rc.token['owner_id']}],
|
31
|
-
from: {extensionId: $rc.token['owner_id']},
|
32
|
-
text: 'Hello world'
|
33
|
-
})
|
34
|
-
sleep(20)
|
35
|
-
|
36
|
-
expect(count).to be > 0
|
37
|
-
$rc.revoke()
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'refresh' do
|
41
|
-
$rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
42
|
-
count = 0
|
43
|
-
subscription = createSubscription(lambda { |message|
|
44
|
-
count += 1
|
45
|
-
})
|
46
|
-
|
47
|
-
subscription.refresh()
|
48
|
-
|
49
|
-
$rc.post('/restapi/v1.0/account/~/extension/~/company-pager', payload: {
|
50
|
-
to: [{extensionId: $rc.token['owner_id']}],
|
51
|
-
from: {extensionId: $rc.token['owner_id']},
|
52
|
-
text: 'Hello world'
|
53
|
-
})
|
54
|
-
sleep(20)
|
55
|
-
|
56
|
-
expect(count).to be > 0
|
57
|
-
$rc.revoke()
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'revoke' do
|
61
|
-
$rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
62
|
-
count = 0
|
63
|
-
subscription = createSubscription(lambda { |message|
|
64
|
-
count += 1
|
65
|
-
})
|
66
|
-
|
67
|
-
subscription.revoke()
|
68
|
-
|
69
|
-
$rc.post('/restapi/v1.0/account/~/extension/~/company-pager', payload: {
|
70
|
-
to: [{extensionId: $rc.token['owner_id']}],
|
71
|
-
from: {extensionId: $rc.token['owner_id']},
|
72
|
-
text: 'Hello world'
|
73
|
-
})
|
74
|
-
sleep(20)
|
75
|
-
|
76
|
-
expect(count).to eq(0)
|
77
|
-
$rc.revoke()
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|