ringcentral-sdk 0.9.9 → 1.0.0.pre.beta.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c82aa5b359e0d18f0096e856d81cebb7c00990208cc210a217d49d470ee19eb
4
- data.tar.gz: 5a4f3973076393c86fa95ea47aa7b467c0b01abd3c46fcd819a5c976ab625717
3
+ metadata.gz: 0ba4479cc28e3446e48379b32aab9395ce0de7636e4119e0158f983eb0956951
4
+ data.tar.gz: 05beacfb1ebcb18e558f25fc0e6376343d27aa5e6fbaa136cf51d1a652c8e093
5
5
  SHA512:
6
- metadata.gz: 1cd78622b101fbf1ef52b717af4ea587fdf98517613d9de858f432c3954e89c4c8393a16f67a43bfa29fe938d2711970200133ad9fc7362307b214d0a807f094
7
- data.tar.gz: 9a98212a1550ee2cd269d8b935fb25115f31f9ece0609498e6a5fa2efd701107da6e3ed58a48fb266e118934e85b8ded88860529f93c13142ea2d87cb315e94b
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
 
@@ -133,23 +135,30 @@ r = rc.post('/restapi/v1.0/account/~/extension/~/sms',
133
135
  ```
134
136
 
135
137
 
136
- ### PubNub subscription
138
+ ## Subscriptions
139
+
140
+ ### WebSocket Subscriptions
137
141
 
138
142
  ```ruby
139
- def createSubscription(callback)
140
- events = [
141
- '/restapi/v1.0/account/~/extension/~/message-store',
142
- ]
143
- subscription = PubNub.new(rc, events, lambda { |message|
144
- callback.call(message)
145
- })
146
- subscription.subscribe()
147
- return subscription
148
- end
149
-
150
- createSubscription(lambda { |message|
151
- puts message
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
 
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'ringcentral-sdk'
3
- gem.version = '0.9.9'
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
@@ -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
- 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
- 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.9.9
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-05 00:00:00.000000000 Z
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/subscription_spec.rb
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: '0'
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/subscription_spec.rb
179
+ - spec/websocket_subscription_spec.rb