ringcentral-sdk 1.0.0.pre.beta.2 → 1.0.0.pre.beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/lib/ringcentral.rb +1 -0
- data/lib/subscription.rb +30 -1
- data/ringcentral-sdk.gemspec +1 -1
- data/spec/mms_spec.rb +14 -13
- data/spec/pubnub_subscription_spec.rb +10 -10
- data/spec/ringcentral_spec.rb +11 -10
- data/spec/websocket_subscription_spec.rb +6 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bb9f1c796f3fc2ac90aa28d1a33090d5e26fdc8445edb312fd9b1937add7add
|
4
|
+
data.tar.gz: 394c158641dfe6d4f6301eec2527107eeb3909b6aff782b1af5224f700aca7ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cc88ac631aca239ecb0a644d2f399e86cd055d11a50021adb0aab66d6a3bc30be7e03c448541fa5309cfed9b336ec1ef183348b3383c29f006357093bb9c24d
|
7
|
+
data.tar.gz: 10a25f56bc1afbd4b3c04df79ccfecf9f7a1cd019023d6417b38b43f80fa829f651fea02a1fdf677f64c3ca8fa11457bd31d23d1f30d2bad190bfbd2958228d8
|
data/README.md
CHANGED
@@ -149,6 +149,22 @@ subscription = WS.new(rc, events, lambda { |message|
|
|
149
149
|
subscription.subscribe()
|
150
150
|
```
|
151
151
|
|
152
|
+
#### How to keep a subscription running 24 * 7?
|
153
|
+
|
154
|
+
There are two main cases that a subscription will be terminated:
|
155
|
+
|
156
|
+
- Absolute time out. The maximum time for a subscription to run is 24 hours. After that, the websocket connection will be closed by the server.
|
157
|
+
- Network issue. It could be your local network issue or the server's network issue. In either case, your websocket connection will be closed
|
158
|
+
|
159
|
+
In order to keep a subscription running 24 * 7, you need to re-subscribe when the connection is closed.
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
subscription.on_ws_closed = lambda { |event|
|
163
|
+
# make sure that there is no network issue and re-subscribe
|
164
|
+
subscription.subscribe()
|
165
|
+
}
|
166
|
+
```
|
167
|
+
|
152
168
|
### (deprecated) PubNub Subscriptions
|
153
169
|
|
154
170
|
```ruby
|
data/lib/ringcentral.rb
CHANGED
data/lib/subscription.rb
CHANGED
@@ -7,10 +7,15 @@ require 'securerandom'
|
|
7
7
|
require 'eventmachine'
|
8
8
|
|
9
9
|
class WS
|
10
|
-
def initialize(ringcentral, events, callback)
|
10
|
+
def initialize(ringcentral, events, callback, debugMode = false)
|
11
11
|
@rc = ringcentral
|
12
12
|
@events = events
|
13
13
|
@callback = callback
|
14
|
+
@debugMode = debugMode
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_ws_closed=(callback)
|
18
|
+
@on_ws_closed = callback
|
14
19
|
end
|
15
20
|
|
16
21
|
def subscribe
|
@@ -18,18 +23,42 @@ class WS
|
|
18
23
|
@t = Thread.new do
|
19
24
|
EM.run {
|
20
25
|
@ws = Faye::WebSocket::Client.new(r['uri'] + '?access_token=' + r['ws_access_token'])
|
26
|
+
if @debugMode
|
27
|
+
class << @ws
|
28
|
+
def send(message)
|
29
|
+
puts "Sending...\n" + message
|
30
|
+
super(message)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
21
34
|
@ws.on :open do
|
22
35
|
@ws.send([
|
23
36
|
{ type: 'ClientRequest', method: 'POST', path: '/restapi/v1.0/subscription', messageId: SecureRandom.uuid },
|
24
37
|
{ deliveryMode: { transportType: 'WebSocket' }, eventFilters: @events }
|
25
38
|
].to_json())
|
39
|
+
|
40
|
+
# send a heartbeat every 10 minutes
|
41
|
+
@task = Concurrent::TimerTask.new(execution_interval: 600) do
|
42
|
+
@ws.send([
|
43
|
+
{ type: 'Heartbeat', messageId: SecureRandom.uuid },
|
44
|
+
].to_json())
|
45
|
+
end
|
46
|
+
@task.execute
|
26
47
|
end
|
27
48
|
@ws.on :message do |event|
|
49
|
+
if @debugMode
|
50
|
+
puts "Receiving...\n" + event.data
|
51
|
+
end
|
28
52
|
header, body = JSON.parse(event.data)
|
29
53
|
if header['type'] == 'ServerNotification'
|
30
54
|
@callback.call(body)
|
31
55
|
end
|
32
56
|
end
|
57
|
+
@ws.on :close do |event|
|
58
|
+
if @on_ws_closed
|
59
|
+
@on_ws_closed.call(event)
|
60
|
+
end
|
61
|
+
end
|
33
62
|
}
|
34
63
|
end
|
35
64
|
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-beta.
|
3
|
+
gem.version = '1.0.0-beta.4'
|
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.'
|
data/spec/mms_spec.rb
CHANGED
@@ -8,19 +8,20 @@ RSpec.describe 'MMS' do
|
|
8
8
|
rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
|
9
9
|
rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
11
|
+
# comment out because sandbox doesn't support mms any more.
|
12
|
+
# r = rc.post('/restapi/v1.0/account/~/extension/~/sms',
|
13
|
+
# payload: {
|
14
|
+
# to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }],
|
15
|
+
# from: { phoneNumber: ENV['RINGCENTRAL_SENDER'] },
|
16
|
+
# text: 'hello world'
|
17
|
+
# },
|
18
|
+
# files: [
|
19
|
+
# ['spec/test.png', 'image/png']
|
20
|
+
# ]
|
21
|
+
# )
|
22
|
+
# expect(r).not_to be_nil
|
23
|
+
# message = r.body
|
24
|
+
# expect('SMS').to eq(message['type'])
|
24
25
|
|
25
26
|
rc.revoke()
|
26
27
|
end
|
@@ -9,7 +9,7 @@ $rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECR
|
|
9
9
|
RSpec.describe 'PubNub Subscription' do
|
10
10
|
def createSubscription(callback)
|
11
11
|
events = [
|
12
|
-
'/restapi/v1.0/account/~/extension/~/message-store',
|
12
|
+
'/restapi/v1.0/account/~/extension/~/message-store?type=Pager',
|
13
13
|
]
|
14
14
|
subscription = PubNub.new($rc, events, lambda { |message|
|
15
15
|
callback.call(message)
|
@@ -26,9 +26,9 @@ RSpec.describe 'PubNub Subscription' do
|
|
26
26
|
count += 1
|
27
27
|
})
|
28
28
|
|
29
|
-
$rc.post('/restapi/v1.0/account/~/extension/~/
|
30
|
-
to: [{
|
31
|
-
from: {
|
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
32
|
text: 'Hello world'
|
33
33
|
})
|
34
34
|
sleep(20)
|
@@ -46,9 +46,9 @@ RSpec.describe 'PubNub Subscription' do
|
|
46
46
|
|
47
47
|
subscription.refresh()
|
48
48
|
|
49
|
-
$rc.post('/restapi/v1.0/account/~/extension/~/
|
50
|
-
to: [{
|
51
|
-
from: {
|
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
52
|
text: 'Hello world'
|
53
53
|
})
|
54
54
|
sleep(20)
|
@@ -66,9 +66,9 @@ RSpec.describe 'PubNub Subscription' do
|
|
66
66
|
|
67
67
|
subscription.revoke()
|
68
68
|
|
69
|
-
$rc.post('/restapi/v1.0/account/~/extension/~/
|
70
|
-
to: [{
|
71
|
-
from: {
|
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
72
|
text: 'Hello world'
|
73
73
|
})
|
74
74
|
sleep(20)
|
data/spec/ringcentral_spec.rb
CHANGED
@@ -49,14 +49,14 @@ RSpec.describe 'RingCentral' do
|
|
49
49
|
expect('101').to eq(r.body['extensionNumber'])
|
50
50
|
|
51
51
|
# post
|
52
|
-
r = rc.post('/restapi/v1.0/account/~/extension/~/
|
53
|
-
to: [{
|
54
|
-
from: {
|
52
|
+
r = rc.post('/restapi/v1.0/account/~/extension/~/company-pager', payload: {
|
53
|
+
to: [{extensionId: rc.token['owner_id']}],
|
54
|
+
from: {extensionId: rc.token['owner_id']},
|
55
55
|
text: 'Hello world'
|
56
56
|
})
|
57
57
|
expect(r).not_to be_nil
|
58
58
|
message = r.body
|
59
|
-
expect('
|
59
|
+
expect('Pager').to eq(message['type'])
|
60
60
|
messageUrl = "/restapi/v1.0/account/~/extension/~/message-store/#{message['id']}"
|
61
61
|
|
62
62
|
# put
|
@@ -72,12 +72,13 @@ RSpec.describe 'RingCentral' do
|
|
72
72
|
# todo: test patch
|
73
73
|
|
74
74
|
# delete
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
75
|
+
# todo: delete "availability" is broken, because of sandbox env
|
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'])
|
81
82
|
|
82
83
|
rc.revoke()
|
83
84
|
end
|
@@ -15,6 +15,9 @@ RSpec.describe 'WebSocket Subscription' do
|
|
15
15
|
callback.call(message)
|
16
16
|
})
|
17
17
|
subscription.subscribe()
|
18
|
+
# subscription.on_ws_closed = lambda { |event|
|
19
|
+
# puts 'WebSocket closed'
|
20
|
+
# }
|
18
21
|
return subscription
|
19
22
|
end
|
20
23
|
|
@@ -57,9 +60,9 @@ RSpec.describe 'WebSocket Subscription' do
|
|
57
60
|
|
58
61
|
subscription.revoke()
|
59
62
|
|
60
|
-
$rc.post('/restapi/v1.0/account/~/extension/~/
|
61
|
-
to: [{
|
62
|
-
from: {
|
63
|
+
$rc.post('/restapi/v1.0/account/~/extension/~/company-pager', payload: {
|
64
|
+
to: [{extensionId: $rc.token['owner_id']}],
|
65
|
+
from: {extensionId: $rc.token['owner_id']},
|
63
66
|
text: 'Hello world'
|
64
67
|
})
|
65
68
|
sleep(20)
|
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.pre.beta.
|
4
|
+
version: 1.0.0.pre.beta.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Liu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|