ringcentral-sdk 1.0.0.pre.beta.3 → 1.0.0
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 +14 -13
- data/lib/ringcentral.rb +1 -6
- data/lib/subscription.rb +30 -80
- data/ringcentral-sdk.gemspec +5 -6
- data/spec/fax_spec.rb +2 -0
- data/spec/mms_spec.rb +2 -0
- data/spec/query_params_spec.rb +2 -0
- data/spec/ringcentral_spec.rb +17 -17
- data/spec/websocket_subscription_spec.rb +12 -7
- 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.
|
@@ -149,26 +149,27 @@ subscription = WS.new(rc, events, lambda { |message|
|
|
149
149
|
subscription.subscribe()
|
150
150
|
```
|
151
151
|
|
152
|
-
|
152
|
+
#### How to keep a subscription running 24 * 7?
|
153
153
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
subscription = PubNub.new(rc, events, lambda { |message|
|
159
|
-
puts message
|
160
|
-
})
|
161
|
-
subscription.subscribe()
|
162
|
-
```
|
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
|
163
158
|
|
159
|
+
In order to keep a subscription running 24 * 7, you need to re-subscribe when the connection is closed.
|
164
160
|
|
165
|
-
|
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
|
+
```
|
166
167
|
|
167
168
|
|
168
169
|
## How to test
|
169
170
|
|
170
171
|
```
|
171
|
-
bundle install
|
172
|
+
bundle install
|
172
173
|
```
|
173
174
|
|
174
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,16 +1,18 @@
|
|
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'
|
8
5
|
|
9
6
|
class WS
|
10
|
-
def initialize(ringcentral, events, callback)
|
7
|
+
def initialize(ringcentral, events, callback, debugMode = false)
|
11
8
|
@rc = ringcentral
|
12
9
|
@events = events
|
13
10
|
@callback = callback
|
11
|
+
@debugMode = debugMode
|
12
|
+
end
|
13
|
+
|
14
|
+
def on_ws_closed=(callback)
|
15
|
+
@on_ws_closed = callback
|
14
16
|
end
|
15
17
|
|
16
18
|
def subscribe
|
@@ -18,18 +20,42 @@ class WS
|
|
18
20
|
@t = Thread.new do
|
19
21
|
EM.run {
|
20
22
|
@ws = Faye::WebSocket::Client.new(r['uri'] + '?access_token=' + r['ws_access_token'])
|
23
|
+
if @debugMode
|
24
|
+
class << @ws
|
25
|
+
def send(message)
|
26
|
+
puts "Sending...\n" + message
|
27
|
+
super(message)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
21
31
|
@ws.on :open do
|
22
32
|
@ws.send([
|
23
33
|
{ type: 'ClientRequest', method: 'POST', path: '/restapi/v1.0/subscription', messageId: SecureRandom.uuid },
|
24
34
|
{ deliveryMode: { transportType: 'WebSocket' }, eventFilters: @events }
|
25
35
|
].to_json())
|
36
|
+
|
37
|
+
# send a heartbeat every 10 minutes
|
38
|
+
@task = Concurrent::TimerTask.new(execution_interval: 600) do
|
39
|
+
@ws.send([
|
40
|
+
{ type: 'Heartbeat', messageId: SecureRandom.uuid },
|
41
|
+
].to_json())
|
42
|
+
end
|
43
|
+
@task.execute
|
26
44
|
end
|
27
45
|
@ws.on :message do |event|
|
46
|
+
if @debugMode
|
47
|
+
puts "Receiving...\n" + event.data
|
48
|
+
end
|
28
49
|
header, body = JSON.parse(event.data)
|
29
50
|
if header['type'] == 'ServerNotification'
|
30
51
|
@callback.call(body)
|
31
52
|
end
|
32
53
|
end
|
54
|
+
@ws.on :close do |event|
|
55
|
+
if @on_ws_closed
|
56
|
+
@on_ws_closed.call(event)
|
57
|
+
end
|
58
|
+
end
|
33
59
|
}
|
34
60
|
end
|
35
61
|
end
|
@@ -38,79 +64,3 @@ class WS
|
|
38
64
|
@t.kill
|
39
65
|
end
|
40
66
|
end
|
41
|
-
|
42
|
-
class PubNub
|
43
|
-
attr_accessor :events
|
44
|
-
|
45
|
-
def initialize(ringcentral, events, message_callback, status_callback = nil, presence_callback = nil)
|
46
|
-
warn('PubNub is deprecated. Use WS (WebSocket) instead.')
|
47
|
-
@rc = ringcentral
|
48
|
-
@events = events
|
49
|
-
@callback = Pubnub::SubscribeCallback.new(
|
50
|
-
message: lambda { |envelope|
|
51
|
-
message = envelope.result[:data][:message]
|
52
|
-
cipher = OpenSSL::Cipher::AES.new(128, :ECB)
|
53
|
-
cipher.decrypt
|
54
|
-
cipher.key = Base64.decode64(@subscription['deliveryMode']['encryptionKey'])
|
55
|
-
ciphertext = Base64.decode64(message)
|
56
|
-
plaintext = cipher.update(ciphertext) + cipher.final
|
57
|
-
message_callback.call(JSON.parse(plaintext))
|
58
|
-
},
|
59
|
-
presence: lambda { |envelope|
|
60
|
-
presence_callback != nil && presence_callback.call(envelope)
|
61
|
-
},
|
62
|
-
status: lambda { |envelope|
|
63
|
-
status_callback != nil && status_callback.call(envelope)
|
64
|
-
}
|
65
|
-
)
|
66
|
-
@subscription = nil
|
67
|
-
@timer = nil
|
68
|
-
@pubnub = nil
|
69
|
-
end
|
70
|
-
|
71
|
-
def subscription=(value)
|
72
|
-
@subscription = value
|
73
|
-
if @timer != nil
|
74
|
-
@timer.shutdown
|
75
|
-
@timer = nil
|
76
|
-
end
|
77
|
-
if value != nil
|
78
|
-
@timer = Concurrent::TimerTask.new(execution_interval: value['expiresIn'] - 120) do
|
79
|
-
self.refresh
|
80
|
-
end
|
81
|
-
@timer.execute
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def subscribe
|
86
|
-
r = @rc.post('/restapi/v1.0/subscription', payload: request_body)
|
87
|
-
self.subscription = r.body
|
88
|
-
@pubnub = Pubnub.new(subscribe_key: @subscription['deliveryMode']['subscriberKey'], user_id: @rc.token['owner_id'])
|
89
|
-
@pubnub.add_listener(name: 'default', callback: @callback)
|
90
|
-
@pubnub.subscribe(channels: @subscription['deliveryMode']['address'])
|
91
|
-
end
|
92
|
-
|
93
|
-
def refresh
|
94
|
-
return if @subscription == nil
|
95
|
-
r = @rc.put("/restapi/v1.0/subscription/#{@subscription['id']}", payload: request_body)
|
96
|
-
self.subscription = r.body
|
97
|
-
end
|
98
|
-
|
99
|
-
def revoke
|
100
|
-
return if @subscription == nil
|
101
|
-
@pubnub.unsubscribe(channel: @subscription['deliveryMode']['address'])
|
102
|
-
@pubnub.remove_listener(name: 'default')
|
103
|
-
@pubnub = nil
|
104
|
-
@rc.delete("/restapi/v1.0/subscription/#{@subscription['id']}")
|
105
|
-
self.subscription = nil
|
106
|
-
end
|
107
|
-
|
108
|
-
private
|
109
|
-
|
110
|
-
def request_body
|
111
|
-
{
|
112
|
-
'deliveryMode': { 'transportType': 'PubNub', 'encryption': true },
|
113
|
-
'eventFilters': @events
|
114
|
-
}
|
115
|
-
end
|
116
|
-
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
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,17 +47,17 @@ 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
|
-
r = rc.post('/restapi/v1.0/account/~/extension/~/
|
53
|
-
to: [{
|
54
|
-
from: {
|
53
|
+
r = rc.post('/restapi/v1.0/account/~/extension/~/company-pager', payload: {
|
54
|
+
to: [{extensionId: rc.token['owner_id']}],
|
55
|
+
from: {extensionId: rc.token['owner_id']},
|
55
56
|
text: 'Hello world'
|
56
57
|
})
|
57
58
|
expect(r).not_to be_nil
|
58
59
|
message = r.body
|
59
|
-
expect('
|
60
|
+
expect('Pager').to eq(message['type'])
|
60
61
|
messageUrl = "/restapi/v1.0/account/~/extension/~/message-store/#{message['id']}"
|
61
62
|
|
62
63
|
# put
|
@@ -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'])
|
@@ -15,6 +17,9 @@ RSpec.describe 'WebSocket Subscription' do
|
|
15
17
|
callback.call(message)
|
16
18
|
})
|
17
19
|
subscription.subscribe()
|
20
|
+
# subscription.on_ws_closed = lambda { |event|
|
21
|
+
# puts 'WebSocket closed'
|
22
|
+
# }
|
18
23
|
return subscription
|
19
24
|
end
|
20
25
|
|
@@ -31,17 +36,17 @@ RSpec.describe 'WebSocket Subscription' do
|
|
31
36
|
from: {extensionId: $rc.token['owner_id']},
|
32
37
|
text: 'Hello world'
|
33
38
|
})
|
34
|
-
sleep(
|
39
|
+
sleep(10)
|
35
40
|
expect(count).to be > 0
|
36
41
|
|
37
42
|
# sleep for some time and see if the websocket is still alive
|
38
|
-
sleep(
|
43
|
+
sleep(20)
|
39
44
|
$rc.post('/restapi/v1.0/account/~/extension/~/company-pager', payload: {
|
40
45
|
to: [{extensionId: $rc.token['owner_id']}],
|
41
46
|
from: {extensionId: $rc.token['owner_id']},
|
42
47
|
text: 'Hello world'
|
43
48
|
})
|
44
|
-
sleep(
|
49
|
+
sleep(10)
|
45
50
|
expect(count).to be > 1
|
46
51
|
|
47
52
|
sub.revoke()
|
@@ -57,12 +62,12 @@ RSpec.describe 'WebSocket Subscription' do
|
|
57
62
|
|
58
63
|
subscription.revoke()
|
59
64
|
|
60
|
-
$rc.post('/restapi/v1.0/account/~/extension/~/
|
61
|
-
to: [{
|
62
|
-
from: {
|
65
|
+
$rc.post('/restapi/v1.0/account/~/extension/~/company-pager', payload: {
|
66
|
+
to: [{extensionId: $rc.token['owner_id']}],
|
67
|
+
from: {extensionId: $rc.token['owner_id']},
|
63
68
|
text: 'Hello world'
|
64
69
|
})
|
65
|
-
sleep(
|
70
|
+
sleep(10)
|
66
71
|
|
67
72
|
expect(count).to eq(0)
|
68
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',
|
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/~/sms', payload: {
|
30
|
-
to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
|
31
|
-
from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
|
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/~/sms', payload: {
|
50
|
-
to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
|
51
|
-
from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
|
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/~/sms', payload: {
|
70
|
-
to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
|
71
|
-
from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
|
72
|
-
text: 'Hello world'
|
73
|
-
})
|
74
|
-
sleep(20)
|
75
|
-
|
76
|
-
expect(count).to eq(0)
|
77
|
-
$rc.revoke()
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|