ringcentral-sdk 0.9.9 → 1.0.0.pre.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -14
- data/lib/subscription.rb +37 -0
- data/ringcentral-sdk.gemspec +2 -1
- data/spec/{subscription_spec.rb → pubnub_subscription_spec.rb} +12 -13
- data/spec/websocket_subscription_spec.rb +71 -0
- metadata +28 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbfb68b0fa5c60f0ab8dd33013d773a81568e424e616be7ba8aa1b3aaa8ffc00
|
4
|
+
data.tar.gz: c74ff9b328b54394693d696f186c9ef590ef3b3d5a66d0c110fcb31a85514906
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2bb2ff1d5fb1de2217470ab049435b49fadc236c49e3da87573554d95001b517c041cc33c56a2346a92878b675b6ed855f786e8f0c1e4bd15f5493084117456
|
7
|
+
data.tar.gz: 7c815de3a1679926ae14966403445217c16224702468f1807026484a4f24a8516ca12915f5f5d5d74e1be819b9cf8e60319708da174bcd120aec5e995e14b6f7
|
data/README.md
CHANGED
@@ -20,6 +20,8 @@ If you are having difficulty using this SDK, or working with the RingCentral API
|
|
20
20
|
gem install ringcentral-sdk
|
21
21
|
```
|
22
22
|
|
23
|
+
If for some reason `eventmachine` failed to install, please check [this](https://stackoverflow.com/a/31516586/862862).
|
24
|
+
|
23
25
|
|
24
26
|
### Name collision with `ringcentral` gem
|
25
27
|
|
@@ -133,23 +135,30 @@ r = rc.post('/restapi/v1.0/account/~/extension/~/sms',
|
|
133
135
|
```
|
134
136
|
|
135
137
|
|
136
|
-
|
138
|
+
## Subscriptions
|
139
|
+
|
140
|
+
### WebSocket Subscriptions
|
137
141
|
|
138
142
|
```ruby
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
143
|
+
events = [
|
144
|
+
'/restapi/v1.0/account/~/extension/~/message-store',
|
145
|
+
]
|
146
|
+
subscription = WS.new(rc, events, lambda { |message|
|
147
|
+
puts message
|
148
|
+
})
|
149
|
+
subscription.subscribe()
|
150
|
+
```
|
151
|
+
|
152
|
+
### (deprecated) PubNub Subscriptions
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
events = [
|
156
|
+
'/restapi/v1.0/account/~/extension/~/message-store',
|
157
|
+
]
|
158
|
+
subscription = PubNub.new(rc, events, lambda { |message|
|
159
|
+
puts message
|
152
160
|
})
|
161
|
+
subscription.subscribe()
|
153
162
|
```
|
154
163
|
|
155
164
|
|
data/lib/subscription.rb
CHANGED
@@ -2,11 +2,48 @@ require 'pubnub'
|
|
2
2
|
require 'concurrent'
|
3
3
|
require 'openssl'
|
4
4
|
require 'base64'
|
5
|
+
require 'faye/websocket'
|
6
|
+
require 'securerandom'
|
7
|
+
require 'eventmachine'
|
8
|
+
|
9
|
+
class WS
|
10
|
+
def initialize(ringcentral, events, callback)
|
11
|
+
@rc = ringcentral
|
12
|
+
@events = events
|
13
|
+
@callback = callback
|
14
|
+
end
|
15
|
+
|
16
|
+
def subscribe
|
17
|
+
r = @rc.post('/restapi/oauth/wstoken').body
|
18
|
+
@t = Thread.new do
|
19
|
+
EM.run {
|
20
|
+
@ws = Faye::WebSocket::Client.new(r['uri'] + '?access_token=' + r['ws_access_token'])
|
21
|
+
@ws.on :open do
|
22
|
+
@ws.send([
|
23
|
+
{ type: 'ClientRequest', method: 'POST', path: '/restapi/v1.0/subscription', messageId: SecureRandom.uuid },
|
24
|
+
{ deliveryMode: { transportType: 'WebSocket' }, eventFilters: @events }
|
25
|
+
].to_json())
|
26
|
+
end
|
27
|
+
@ws.on :message do |event|
|
28
|
+
header, body = JSON.parse(event.data)
|
29
|
+
if header['type'] == 'ServerNotification'
|
30
|
+
@callback.call(body)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def revoke
|
38
|
+
@t.kill
|
39
|
+
end
|
40
|
+
end
|
5
41
|
|
6
42
|
class PubNub
|
7
43
|
attr_accessor :events
|
8
44
|
|
9
45
|
def initialize(ringcentral, events, message_callback, status_callback = nil, presence_callback = nil)
|
46
|
+
warn('PubNub is deprecated. Use WS (WebSocket) instead.')
|
10
47
|
@rc = ringcentral
|
11
48
|
@events = events
|
12
49
|
@callback = Pubnub::SubscribeCallback.new(
|
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 = '0.
|
3
|
+
gem.version = '1.0.0-beta.2'
|
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.'
|
@@ -18,4 +18,5 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_dependency('pubnub', '~> 5.2', '>= 5.2.2')
|
19
19
|
gem.add_dependency('faraday', '~> 2.7', '>= 2.7.4')
|
20
20
|
gem.add_dependency('faraday-multipart', '~> 1.0', '>= 1.0.4')
|
21
|
+
gem.add_dependency('faye-websocket', '~> 0.11', '>= 0.11.2')
|
21
22
|
end
|
@@ -6,20 +6,19 @@ require 'rspec'
|
|
6
6
|
Dotenv.load
|
7
7
|
$rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
|
8
8
|
|
9
|
+
RSpec.describe 'PubNub Subscription' do
|
10
|
+
def createSubscription(callback)
|
11
|
+
events = [
|
12
|
+
'/restapi/v1.0/account/~/extension/~/message-store',
|
13
|
+
]
|
14
|
+
subscription = PubNub.new($rc, events, lambda { |message|
|
15
|
+
callback.call(message)
|
16
|
+
})
|
17
|
+
subscription.subscribe()
|
18
|
+
return subscription
|
19
|
+
end
|
9
20
|
|
10
|
-
|
11
|
-
events = [
|
12
|
-
'/restapi/v1.0/account/~/extension/~/message-store',
|
13
|
-
]
|
14
|
-
subscription = PubNub.new($rc, events, lambda { |message|
|
15
|
-
callback.call(message)
|
16
|
-
})
|
17
|
-
subscription.subscribe()
|
18
|
-
return subscription
|
19
|
-
end
|
20
|
-
|
21
|
-
RSpec.describe 'Subscription' do
|
22
|
-
describe 'subscription' do
|
21
|
+
describe 'PubNub Subscription' do
|
23
22
|
it 'receives message notification' do
|
24
23
|
$rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
25
24
|
count = 0
|
@@ -0,0 +1,71 @@
|
|
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 'WebSocket Subscription' do
|
10
|
+
def createSubscription(callback)
|
11
|
+
events = [
|
12
|
+
'/restapi/v1.0/account/~/extension/~/message-store?type=Pager',
|
13
|
+
]
|
14
|
+
subscription = WS.new($rc, events, lambda { |message|
|
15
|
+
callback.call(message)
|
16
|
+
})
|
17
|
+
subscription.subscribe()
|
18
|
+
return subscription
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'WebSocket Subscription' do
|
22
|
+
it 'receives message notification' do
|
23
|
+
$rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
24
|
+
count = 0
|
25
|
+
sub = 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
|
+
expect(count).to be > 0
|
36
|
+
|
37
|
+
# sleep for some time and see if the websocket is still alive
|
38
|
+
sleep(60)
|
39
|
+
$rc.post('/restapi/v1.0/account/~/extension/~/company-pager', payload: {
|
40
|
+
to: [{extensionId: $rc.token['owner_id']}],
|
41
|
+
from: {extensionId: $rc.token['owner_id']},
|
42
|
+
text: 'Hello world'
|
43
|
+
})
|
44
|
+
sleep(20)
|
45
|
+
expect(count).to be > 1
|
46
|
+
|
47
|
+
sub.revoke()
|
48
|
+
$rc.revoke()
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'revoke' do
|
52
|
+
$rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
53
|
+
count = 0
|
54
|
+
subscription = createSubscription(lambda { |message|
|
55
|
+
count += 1
|
56
|
+
})
|
57
|
+
|
58
|
+
subscription.revoke()
|
59
|
+
|
60
|
+
$rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
|
61
|
+
to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
|
62
|
+
from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
|
63
|
+
text: 'Hello world'
|
64
|
+
})
|
65
|
+
sleep(20)
|
66
|
+
|
67
|
+
expect(count).to eq(0)
|
68
|
+
$rc.revoke()
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
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: 0.
|
4
|
+
version: 1.0.0.pre.beta.2
|
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-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -110,6 +110,26 @@ dependencies:
|
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: 1.0.4
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: faye-websocket
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - "~>"
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0.11'
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 0.11.2
|
123
|
+
type: :runtime
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0.11'
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 0.11.2
|
113
133
|
description: Ruby SDK for you to access RingCentral platform API.
|
114
134
|
email:
|
115
135
|
- tyler.liu@ringcentral.com
|
@@ -123,9 +143,10 @@ files:
|
|
123
143
|
- ringcentral-sdk.gemspec
|
124
144
|
- spec/fax_spec.rb
|
125
145
|
- spec/mms_spec.rb
|
146
|
+
- spec/pubnub_subscription_spec.rb
|
126
147
|
- spec/query_params_spec.rb
|
127
148
|
- spec/ringcentral_spec.rb
|
128
|
-
- spec/
|
149
|
+
- spec/websocket_subscription_spec.rb
|
129
150
|
homepage: https://github.com/ringcentral/ringcentral-ruby
|
130
151
|
licenses:
|
131
152
|
- MIT
|
@@ -141,9 +162,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
162
|
version: '0'
|
142
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
164
|
requirements:
|
144
|
-
- - "
|
165
|
+
- - ">"
|
145
166
|
- !ruby/object:Gem::Version
|
146
|
-
version:
|
167
|
+
version: 1.3.1
|
147
168
|
requirements: []
|
148
169
|
rubygems_version: 3.4.10
|
149
170
|
signing_key:
|
@@ -152,6 +173,7 @@ summary: RingCentral Ruby SDK.
|
|
152
173
|
test_files:
|
153
174
|
- spec/fax_spec.rb
|
154
175
|
- spec/mms_spec.rb
|
176
|
+
- spec/pubnub_subscription_spec.rb
|
155
177
|
- spec/query_params_spec.rb
|
156
178
|
- spec/ringcentral_spec.rb
|
157
|
-
- spec/
|
179
|
+
- spec/websocket_subscription_spec.rb
|