ringcentral-sdk 0.9.8 → 1.0.0.pre.beta.1
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 +28 -27
- data/lib/ringcentral.rb +68 -18
- data/lib/subscription.rb +36 -0
- data/ringcentral-sdk.gemspec +2 -1
- data/spec/fax_spec.rb +1 -1
- data/spec/mms_spec.rb +2 -2
- data/spec/{subscription_spec.rb → pubnub_subscription_spec.rb} +21 -16
- data/spec/query_params_spec.rb +1 -1
- data/spec/ringcentral_spec.rb +5 -5
- data/spec/websocket_subscription_spec.rb +71 -0
- metadata +29 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ba4479cc28e3446e48379b32aab9395ce0de7636e4119e0158f983eb0956951
|
4
|
+
data.tar.gz: 05beacfb1ebcb18e558f25fc0e6376343d27aa5e6fbaa136cf51d1a652c8e093
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 876b6195fc109fcfdbf2acb0c97a4c6659891af75b21c2d5bafc106aa08d4daf2506dca7fced204315b676aee96e0c60ebd22107cfd9be309ddb8514b7c9f75e
|
7
|
+
data.tar.gz: d954ef415d9f9c61ecad642ac9773805dc8cc09227e0bb746ac224408afdb9539c999aee5667788ca8b35936c9cb212750526b539cb89b195b68687df410228c
|
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
|
|
@@ -41,7 +43,7 @@ https://developer.ringcentral.com/api-docs/latest/index.html
|
|
41
43
|
require 'ringcentral'
|
42
44
|
|
43
45
|
rc = RingCentral.new('clientID', 'clientSecret', 'serverURL')
|
44
|
-
rc.authorize(
|
46
|
+
rc.authorize(jwt: 'jwt-token')
|
45
47
|
|
46
48
|
# get
|
47
49
|
r = rc.get('/restapi/v1.0/account/~/extension/~')
|
@@ -98,7 +100,7 @@ rc.token = { access_token: 'the token string' }
|
|
98
100
|
```ruby
|
99
101
|
r = rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
|
100
102
|
to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
|
101
|
-
from: {phoneNumber: ENV['
|
103
|
+
from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
|
102
104
|
text: 'Hello world'
|
103
105
|
})
|
104
106
|
```
|
@@ -123,7 +125,7 @@ payload: { to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }] },
|
|
123
125
|
r = rc.post('/restapi/v1.0/account/~/extension/~/sms',
|
124
126
|
payload: {
|
125
127
|
to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }],
|
126
|
-
from: { phoneNumber: ENV['
|
128
|
+
from: { phoneNumber: ENV['RINGCENTRAL_SENDER'] },
|
127
129
|
text: 'hello world'
|
128
130
|
},
|
129
131
|
files: [
|
@@ -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
|
+
### 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
|
|
@@ -162,17 +171,9 @@ For more sample codes, please refer to the [test cases](/spec).
|
|
162
171
|
bundle install --path vendor/bundle
|
163
172
|
```
|
164
173
|
|
165
|
-
|
174
|
+
Rename `.env.sample` to `.env`.
|
166
175
|
|
167
|
-
|
168
|
-
RINGCENTRAL_SERVER_URL=https://platform.devtest.ringcentral.com
|
169
|
-
RINGCENTRAL_CLIENT_ID=
|
170
|
-
RINGCENTRAL_CLIENT_SECRET=
|
171
|
-
RINGCENTRAL_USERNAME=
|
172
|
-
RINGCENTRAL_EXTENSION=
|
173
|
-
RINGCENTRAL_PASSWORD=
|
174
|
-
RINGCENTRAL_RECEIVER=
|
175
|
-
```
|
176
|
+
Edit `.env` file to specify credentials.
|
176
177
|
|
177
178
|
`RINGCENTRAL_RECEIVER` is a phone number to receive SMS, Fax..etc.
|
178
179
|
|
data/lib/ringcentral.rb
CHANGED
@@ -16,13 +16,14 @@ class RingCentral
|
|
16
16
|
end
|
17
17
|
|
18
18
|
attr_reader :client_id, :client_secret, :server, :token
|
19
|
-
attr_accessor :auto_refresh
|
19
|
+
attr_accessor :auto_refresh, :debug_mode
|
20
20
|
|
21
|
-
def initialize(client_id, client_secret, server)
|
21
|
+
def initialize(client_id, client_secret, server, debug_mode = false)
|
22
22
|
@client_id = client_id
|
23
23
|
@client_secret = client_secret
|
24
24
|
@server = server
|
25
25
|
@auto_refresh = false
|
26
|
+
@debug_mode = debug_mode
|
26
27
|
@token = nil
|
27
28
|
@timer = nil
|
28
29
|
@faraday = Faraday.new(url: server, request: { params_encoder: Faraday::FlatParamsEncoder }) do |faraday|
|
@@ -91,31 +92,36 @@ class RingCentral
|
|
91
92
|
self.post('/restapi/oauth/revoke', payload: payload)
|
92
93
|
end
|
93
94
|
|
94
|
-
def authorize_uri(redirect_uri,
|
95
|
+
def authorize_uri(redirect_uri, hash = {})
|
96
|
+
hash[:response_type] = 'code'
|
97
|
+
hash[:redirect_uri] = redirect_uri
|
98
|
+
hash[:client_id] = @client_id
|
95
99
|
uri = Addressable::URI.parse(@server) + '/restapi/oauth/authorize'
|
96
|
-
uri.query_values =
|
97
|
-
response_type: 'code',
|
98
|
-
state: state,
|
99
|
-
redirect_uri: redirect_uri,
|
100
|
-
client_id: @client_id
|
101
|
-
}
|
102
|
-
if challenge != nil
|
103
|
-
uri.query_values["code_challenge"] = challenge
|
104
|
-
uri.query_values["code_challenge_method"] = challenge_method
|
105
|
-
end
|
100
|
+
uri.query_values = hash
|
106
101
|
uri.to_s
|
107
102
|
end
|
108
103
|
|
109
104
|
def get(endpoint, params = {})
|
110
|
-
@faraday.get do |req|
|
105
|
+
r = @faraday.get do |req|
|
111
106
|
req.url endpoint
|
112
107
|
req.params = params
|
113
108
|
req.headers = headers
|
114
109
|
end
|
110
|
+
if @debug_mode
|
111
|
+
puts r.status, r.body
|
112
|
+
end
|
113
|
+
if r.status >= 400
|
114
|
+
raise "HTTP status #{r.status}:
|
115
|
+
|
116
|
+
headers: #{r.headers}
|
117
|
+
|
118
|
+
body: #{r.body}"
|
119
|
+
end
|
120
|
+
return r
|
115
121
|
end
|
116
122
|
|
117
123
|
def post(endpoint, payload: nil, params: {}, files: nil)
|
118
|
-
@faraday.post do |req|
|
124
|
+
r = @faraday.post do |req|
|
119
125
|
req.url endpoint
|
120
126
|
req.params = params
|
121
127
|
if files != nil && files.size > 0 # send fax or MMS
|
@@ -133,32 +139,76 @@ class RingCentral
|
|
133
139
|
req.body = payload
|
134
140
|
end
|
135
141
|
end
|
142
|
+
if @debug_mode
|
143
|
+
puts r.status, r.body
|
144
|
+
end
|
145
|
+
if r.status >= 400
|
146
|
+
raise "HTTP status #{r.status}:
|
147
|
+
|
148
|
+
headers: #{r.headers}
|
149
|
+
|
150
|
+
body: #{r.body}"
|
151
|
+
end
|
152
|
+
return r
|
136
153
|
end
|
137
154
|
|
138
155
|
def put(endpoint, payload: nil, params: {}, files: nil)
|
139
|
-
@faraday.put do |req|
|
156
|
+
r = @faraday.put do |req|
|
140
157
|
req.url endpoint
|
141
158
|
req.params = params
|
142
159
|
req.headers = headers.merge({ 'Content-Type': 'application/json' })
|
143
160
|
req.body = payload.to_json
|
144
161
|
end
|
162
|
+
if @debug_mode
|
163
|
+
puts r.status, r.body
|
164
|
+
end
|
165
|
+
if r.status >= 400
|
166
|
+
raise "HTTP status #{r.status}:
|
167
|
+
|
168
|
+
headers: #{r.headers}
|
169
|
+
|
170
|
+
body: #{r.body}"
|
171
|
+
end
|
172
|
+
return r
|
145
173
|
end
|
146
174
|
|
147
175
|
def patch(endpoint, payload: nil, params: {}, files: nil)
|
148
|
-
@faraday.patch do |req|
|
176
|
+
r = @faraday.patch do |req|
|
149
177
|
req.url endpoint
|
150
178
|
req.params = params
|
151
179
|
req.headers = headers.merge({ 'Content-Type': 'application/json' })
|
152
180
|
req.body = payload.to_json
|
153
181
|
end
|
182
|
+
if @debug_mode
|
183
|
+
puts r.status, r.body
|
184
|
+
end
|
185
|
+
if r.status >= 400
|
186
|
+
raise "HTTP status #{r.status}:
|
187
|
+
|
188
|
+
headers: #{r.headers}
|
189
|
+
|
190
|
+
body: #{r.body}"
|
191
|
+
end
|
192
|
+
return r
|
154
193
|
end
|
155
194
|
|
156
195
|
def delete(endpoint, params = {})
|
157
|
-
@faraday.delete do |req|
|
196
|
+
r = @faraday.delete do |req|
|
158
197
|
req.url endpoint
|
159
198
|
req.params = params
|
160
199
|
req.headers = headers
|
161
200
|
end
|
201
|
+
if @debug_mode
|
202
|
+
puts r.status, r.body
|
203
|
+
end
|
204
|
+
if r.status >= 400
|
205
|
+
raise "HTTP status #{r.status}:
|
206
|
+
|
207
|
+
headers: #{r.headers}
|
208
|
+
|
209
|
+
body: #{r.body}"
|
210
|
+
end
|
211
|
+
return r
|
162
212
|
end
|
163
213
|
|
164
214
|
private
|
data/lib/subscription.rb
CHANGED
@@ -2,6 +2,42 @@ 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
|
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.1'
|
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
|
data/spec/fax_spec.rb
CHANGED
@@ -6,7 +6,7 @@ RSpec.describe 'Fax' do
|
|
6
6
|
it 'should send a fax' do
|
7
7
|
Dotenv.load
|
8
8
|
rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
|
9
|
-
rc.authorize(
|
9
|
+
rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
10
10
|
r = rc.post('/restapi/v1.0/account/~/extension/~/fax',
|
11
11
|
payload: { to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }] },
|
12
12
|
files: [
|
data/spec/mms_spec.rb
CHANGED
@@ -6,12 +6,12 @@ RSpec.describe 'MMS' do
|
|
6
6
|
it 'should send an MMS' do
|
7
7
|
Dotenv.load
|
8
8
|
rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
|
9
|
-
rc.authorize(
|
9
|
+
rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
10
10
|
|
11
11
|
r = rc.post('/restapi/v1.0/account/~/extension/~/sms',
|
12
12
|
payload: {
|
13
13
|
to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }],
|
14
|
-
from: { phoneNumber: ENV['
|
14
|
+
from: { phoneNumber: ENV['RINGCENTRAL_SENDER'] },
|
15
15
|
text: 'hello world'
|
16
16
|
},
|
17
17
|
files: [
|
@@ -5,22 +5,22 @@ require 'rspec'
|
|
5
5
|
|
6
6
|
Dotenv.load
|
7
7
|
$rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
|
8
|
-
$rc.authorize(username: ENV['RINGCENTRAL_USERNAME'], extension: ENV['RINGCENTRAL_EXTENSION'], password: ENV['RINGCENTRAL_PASSWORD'])
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
20
|
|
21
|
-
|
22
|
-
describe 'subscription' do
|
21
|
+
describe 'PubNub Subscription' do
|
23
22
|
it 'receives message notification' do
|
23
|
+
$rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
24
24
|
count = 0
|
25
25
|
createSubscription(lambda { |message|
|
26
26
|
count += 1
|
@@ -28,15 +28,17 @@ RSpec.describe 'Subscription' do
|
|
28
28
|
|
29
29
|
$rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
|
30
30
|
to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
|
31
|
-
from: {phoneNumber: ENV['
|
31
|
+
from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
|
32
32
|
text: 'Hello world'
|
33
33
|
})
|
34
34
|
sleep(20)
|
35
35
|
|
36
36
|
expect(count).to be > 0
|
37
|
+
$rc.revoke()
|
37
38
|
end
|
38
39
|
|
39
40
|
it 'refresh' do
|
41
|
+
$rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
40
42
|
count = 0
|
41
43
|
subscription = createSubscription(lambda { |message|
|
42
44
|
count += 1
|
@@ -46,15 +48,17 @@ RSpec.describe 'Subscription' do
|
|
46
48
|
|
47
49
|
$rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
|
48
50
|
to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
|
49
|
-
from: {phoneNumber: ENV['
|
51
|
+
from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
|
50
52
|
text: 'Hello world'
|
51
53
|
})
|
52
54
|
sleep(20)
|
53
55
|
|
54
56
|
expect(count).to be > 0
|
57
|
+
$rc.revoke()
|
55
58
|
end
|
56
59
|
|
57
60
|
it 'revoke' do
|
61
|
+
$rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
58
62
|
count = 0
|
59
63
|
subscription = createSubscription(lambda { |message|
|
60
64
|
count += 1
|
@@ -64,12 +68,13 @@ RSpec.describe 'Subscription' do
|
|
64
68
|
|
65
69
|
$rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
|
66
70
|
to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
|
67
|
-
from: {phoneNumber: ENV['
|
71
|
+
from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
|
68
72
|
text: 'Hello world'
|
69
73
|
})
|
70
74
|
sleep(20)
|
71
75
|
|
72
76
|
expect(count).to eq(0)
|
77
|
+
$rc.revoke()
|
73
78
|
end
|
74
79
|
end
|
75
80
|
end
|
data/spec/query_params_spec.rb
CHANGED
@@ -6,7 +6,7 @@ RSpec.describe 'query params' do
|
|
6
6
|
it 'contain single query param' do
|
7
7
|
Dotenv.load
|
8
8
|
rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
|
9
|
-
rc.authorize(
|
9
|
+
rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
10
10
|
r = rc.get('/restapi/v1.0/account/~/extension/~/address-book/contact', { phoneNumber: '666' })
|
11
11
|
expect(r).not_to be_nil
|
12
12
|
message = r.body
|
data/spec/ringcentral_spec.rb
CHANGED
@@ -17,16 +17,16 @@ RSpec.describe 'RingCentral' do
|
|
17
17
|
|
18
18
|
it 'test_authorize_uri' do
|
19
19
|
rc = RingCentral.new('client_id', 'client_secret', RingCentral.SANDBOX_SERVER)
|
20
|
-
expect(RingCentral.SANDBOX_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', 'mystate'))
|
20
|
+
expect(RingCentral.SANDBOX_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
21
|
end
|
22
22
|
|
23
|
-
it '
|
23
|
+
it 'test_jwt_flow' do
|
24
24
|
Dotenv.load
|
25
25
|
rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
|
26
26
|
expect(rc.token).to be_nil
|
27
27
|
|
28
28
|
# create token
|
29
|
-
rc.authorize(
|
29
|
+
rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
30
30
|
expect(rc.token).not_to be_nil
|
31
31
|
|
32
32
|
# refresh token
|
@@ -41,7 +41,7 @@ RSpec.describe 'RingCentral' do
|
|
41
41
|
it 'test_http_methods' do
|
42
42
|
Dotenv.load
|
43
43
|
rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
|
44
|
-
rc.authorize(
|
44
|
+
rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
|
45
45
|
|
46
46
|
# get
|
47
47
|
r = rc.get('/restapi/v1.0/account/~/extension/~')
|
@@ -51,7 +51,7 @@ RSpec.describe 'RingCentral' do
|
|
51
51
|
# post
|
52
52
|
r = rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
|
53
53
|
to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
|
54
|
-
from: {phoneNumber: ENV['
|
54
|
+
from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
|
55
55
|
text: 'Hello world'
|
56
56
|
})
|
57
57
|
expect(r).not_to be_nil
|
@@ -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.1
|
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-05-
|
11
|
+
date: 2023-05-09 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,17 +162,18 @@ 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
|
-
rubygems_version: 3.
|
169
|
+
rubygems_version: 3.4.10
|
149
170
|
signing_key:
|
150
171
|
specification_version: 4
|
151
172
|
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
|