ringcentral_sdk 1.3.4 → 2.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/CHANGELOG.md +12 -0
- data/Gemfile.lock +70 -33
- data/{LICENSE.txt → LICENSE.md} +0 -0
- data/README.md +40 -76
- data/lib/ringcentral_sdk.rb +4 -3
- data/lib/ringcentral_sdk/rest.rb +18 -17
- data/lib/ringcentral_sdk/rest/cache.rb +9 -3
- data/lib/ringcentral_sdk/rest/cache/extensions.rb +91 -94
- data/lib/ringcentral_sdk/rest/client.rb +196 -202
- data/lib/ringcentral_sdk/rest/configuration.rb +91 -0
- data/lib/ringcentral_sdk/rest/event.rb +44 -43
- data/lib/ringcentral_sdk/rest/extension.rb +12 -9
- data/lib/ringcentral_sdk/rest/extension_presence.rb +73 -78
- data/lib/ringcentral_sdk/rest/messages.rb +40 -31
- data/lib/ringcentral_sdk/rest/messages_retriever.rb +30 -33
- data/lib/ringcentral_sdk/rest/request.rb +10 -5
- data/lib/ringcentral_sdk/rest/request/base.rb +24 -19
- data/lib/ringcentral_sdk/rest/request/fax.rb +88 -91
- data/lib/ringcentral_sdk/rest/request/inflator.rb +9 -2
- data/lib/ringcentral_sdk/rest/request/inflator/contact_info.rb +19 -12
- data/lib/ringcentral_sdk/rest/request/simple.rb +24 -34
- data/lib/ringcentral_sdk/rest/simple_client.rb +63 -78
- data/lib/ringcentral_sdk/rest/subscription.rb +223 -228
- data/test/test_base.rb +5 -5
- data/test/test_client.rb +87 -88
- data/test/test_event.rb +28 -11
- data/test/test_extension_presence.rb +64 -62
- data/test/test_helper_fax.rb +46 -47
- data/test/test_helper_inflator_contact_info.rb +8 -10
- data/test/test_helper_request.rb +1 -1
- data/test/test_setup.rb +24 -21
- data/test/test_subscription.rb +46 -48
- metadata +72 -33
- data/lib/ringcentral_sdk/rest/config.rb +0 -102
- data/test/test_config.rb +0 -29
data/test/test_base.rb
CHANGED
@@ -5,8 +5,8 @@ require 'test/unit'
|
|
5
5
|
require 'mocha/test_unit'
|
6
6
|
require 'ringcentral_sdk'
|
7
7
|
|
8
|
-
|
9
|
-
'my_app_key'
|
10
|
-
'my_app_secret'
|
11
|
-
RingCentralSdk::RC_SERVER_SANDBOX
|
12
|
-
|
8
|
+
RingCentralSdk::REST::Client.new do |config|
|
9
|
+
config.app_key = 'my_app_key'
|
10
|
+
config.app_secret = 'my_app_secret'
|
11
|
+
config.server_url = RingCentralSdk::RC_SERVER_SANDBOX
|
12
|
+
end
|
data/test/test_client.rb
CHANGED
@@ -5,53 +5,50 @@ require 'oauth2'
|
|
5
5
|
|
6
6
|
class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
7
7
|
def setup
|
8
|
-
@rcsdk = RingCentralSdk.new
|
9
|
-
|
10
|
-
'
|
11
|
-
|
12
|
-
|
8
|
+
@rcsdk = RingCentralSdk::REST::Client.new do |config|
|
9
|
+
config.server_url = RingCentralSdk::RC_SERVER_SANDBOX
|
10
|
+
config.app_key = 'my_app_key'
|
11
|
+
config.app_secret = 'my_app_secret'
|
12
|
+
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_main
|
16
|
-
assert_equal
|
16
|
+
assert_equal 'bXlfYXBwX2tleTpteV9hcHBfc2VjcmV0', @rcsdk.send(:api_key)
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_config
|
20
20
|
redirect_url = 'http://localhost:4567/oauth'
|
21
|
-
client = RingCentralSdk.new
|
22
|
-
|
23
|
-
'
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
)
|
29
|
-
assert_equal redirect_url, client.app_config.redirect_url
|
21
|
+
client = RingCentralSdk::REST::Client.new do |config|
|
22
|
+
config.server_url = RingCentralSdk::RC_SERVER_SANDBOX
|
23
|
+
config.app_key = 'my_app_key'
|
24
|
+
config.app_secret = 'my_app_secret'
|
25
|
+
config.redirect_url = redirect_url
|
26
|
+
end
|
27
|
+
assert_equal redirect_url, client.config.redirect_url
|
30
28
|
end
|
31
29
|
|
32
30
|
def test_set_client
|
33
|
-
rcsdk = new_client
|
31
|
+
rcsdk = new_client
|
34
32
|
assert_equal true, rcsdk.oauth2client.is_a?(OAuth2::Client)
|
35
33
|
|
36
|
-
rcsdk.set_oauth2_client
|
34
|
+
rcsdk.set_oauth2_client
|
37
35
|
assert_equal true, rcsdk.oauth2client.is_a?(OAuth2::Client)
|
38
36
|
|
39
|
-
rcsdk = new_client
|
37
|
+
rcsdk = new_client
|
40
38
|
oauth2client = OAuth2::Client.new(
|
41
39
|
'my_app_key',
|
42
40
|
'my_app_secret',
|
43
41
|
site: RingCentralSdk::RC_SERVER_SANDBOX,
|
44
|
-
token_url: rcsdk.class::TOKEN_ENDPOINT
|
45
|
-
|
46
|
-
|
42
|
+
token_url: rcsdk.class::TOKEN_ENDPOINT
|
43
|
+
)
|
44
|
+
rcsdk.set_oauth2_client oauth2client
|
45
|
+
assert_equal true, rcsdk.oauth2client.is_a?(OAuth2::Client)
|
47
46
|
|
48
|
-
assert_raise
|
49
|
-
@rcsdk.set_oauth2_client('test')
|
50
|
-
end
|
47
|
+
assert_raise { @rcsdk.set_oauth2_client('test') }
|
51
48
|
end
|
52
49
|
|
53
50
|
def test_set_token
|
54
|
-
token_data = {access_token: 'test_token'}
|
51
|
+
token_data = { access_token: 'test_token' }
|
55
52
|
|
56
53
|
@rcsdk.set_token(token_data)
|
57
54
|
|
@@ -66,26 +63,27 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
66
63
|
end
|
67
64
|
|
68
65
|
def test_authorize_url_default
|
69
|
-
rcsdk = RingCentralSdk.new
|
70
|
-
'my_app_key'
|
71
|
-
'my_app_secret'
|
72
|
-
RingCentralSdk::RC_SERVER_PRODUCTION
|
73
|
-
|
74
|
-
|
75
|
-
|
66
|
+
rcsdk = RingCentralSdk::REST::Client.new do |config|
|
67
|
+
config.app_key = 'my_app_key'
|
68
|
+
config.app_secret = 'my_app_secret'
|
69
|
+
config.server_url = RingCentralSdk::RC_SERVER_PRODUCTION
|
70
|
+
config.redirect_url = 'http://localhost:4567/oauth'
|
71
|
+
end
|
72
|
+
|
73
|
+
authorize_url = rcsdk.authorize_url
|
76
74
|
|
77
75
|
puts authorize_url
|
78
76
|
|
79
77
|
assert_equal true, authorize_url.is_a?(String)
|
80
78
|
assert_equal 0, authorize_url.index(RingCentralSdk::RC_SERVER_PRODUCTION)
|
81
|
-
assert_equal true,
|
79
|
+
assert_equal true, authorize_url.index('localhost') > 0 ? true : false
|
82
80
|
end
|
83
81
|
|
84
82
|
def test_authorize_url_explicit
|
85
|
-
authorize_url = @rcsdk.authorize_url(
|
83
|
+
authorize_url = @rcsdk.authorize_url(redirect_uri: 'http://localhost:4567/oauth')
|
86
84
|
|
87
85
|
assert_equal 0, authorize_url.index(RingCentralSdk::RC_SERVER_SANDBOX)
|
88
|
-
assert_equal true,
|
86
|
+
assert_equal true, authorize_url.index('localhost') > 0 ? true : false
|
89
87
|
end
|
90
88
|
|
91
89
|
def test_create_url
|
@@ -106,11 +104,11 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
106
104
|
end
|
107
105
|
|
108
106
|
def test_authorize_code
|
109
|
-
rcsdk = new_client
|
110
|
-
rcsdk.set_oauth2_client
|
107
|
+
rcsdk = new_client
|
108
|
+
rcsdk.set_oauth2_client
|
111
109
|
|
112
110
|
stub_token_hash = data_auth_token_with_refresh
|
113
|
-
stub_token = OAuth2::AccessToken
|
111
|
+
stub_token = OAuth2::AccessToken.from_hash(rcsdk.oauth2client, stub_token_hash)
|
114
112
|
|
115
113
|
rcsdk.oauth2client.auth_code.stubs(:get_token).returns(stub_token)
|
116
114
|
|
@@ -118,11 +116,17 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
118
116
|
assert_equal 'OAuth2::AccessToken', token.class.name
|
119
117
|
assert_equal 'OAuth2::AccessToken', rcsdk.token.class.name
|
120
118
|
|
121
|
-
rcsdk =
|
122
|
-
|
119
|
+
rcsdk = RingCentralSdk::REST::Client.new do |config|
|
120
|
+
config.app_key = 'my_app_key'
|
121
|
+
config.app_secret = 'my_app_secret'
|
122
|
+
config.server_url = RingCentralSdk::RC_SERVER_SANDBOX
|
123
|
+
config.redirect_url = 'http://localhost:4567/oauth'
|
124
|
+
end
|
125
|
+
|
126
|
+
rcsdk.set_oauth2_client
|
123
127
|
|
124
128
|
stub_token_hash = data_auth_token_with_refresh
|
125
|
-
stub_token = OAuth2::AccessToken
|
129
|
+
stub_token = OAuth2::AccessToken.from_hash(rcsdk.oauth2client, stub_token_hash)
|
126
130
|
|
127
131
|
rcsdk.oauth2client.auth_code.stubs(:get_token).returns(stub_token)
|
128
132
|
|
@@ -130,11 +134,11 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
130
134
|
assert_equal 'OAuth2::AccessToken', token.class.name
|
131
135
|
assert_equal 'OAuth2::AccessToken', rcsdk.token.class.name
|
132
136
|
|
133
|
-
rcsdk = new_client
|
134
|
-
rcsdk.set_oauth2_client
|
137
|
+
rcsdk = new_client
|
138
|
+
rcsdk.set_oauth2_client
|
135
139
|
|
136
140
|
stub_token_hash = data_auth_token
|
137
|
-
stub_token = OAuth2::AccessToken
|
141
|
+
stub_token = OAuth2::AccessToken.from_hash(rcsdk.oauth2client, stub_token_hash)
|
138
142
|
|
139
143
|
rcsdk.oauth2client.auth_code.stubs(:get_token).returns(stub_token)
|
140
144
|
|
@@ -142,25 +146,25 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
142
146
|
assert_equal 'OAuth2::AccessToken', token.class.name
|
143
147
|
assert_equal 'OAuth2::AccessToken', rcsdk.token.class.name
|
144
148
|
|
145
|
-
rcsdk = new_client
|
146
|
-
rcsdk.set_oauth2_client
|
149
|
+
rcsdk = new_client
|
150
|
+
rcsdk.set_oauth2_client
|
147
151
|
|
148
152
|
stub_token_hash = data_auth_token
|
149
|
-
stub_token = OAuth2::AccessToken
|
153
|
+
stub_token = OAuth2::AccessToken.from_hash(rcsdk.oauth2client, stub_token_hash)
|
150
154
|
|
151
155
|
rcsdk.oauth2client.auth_code.stubs(:get_token).returns(stub_token)
|
152
156
|
|
153
|
-
token = rcsdk.authorize_code('my_test_auth_code',
|
157
|
+
token = rcsdk.authorize_code('my_test_auth_code', redirect_uri: 'http://localhost:4567/oauth')
|
154
158
|
assert_equal 'OAuth2::AccessToken', token.class.name
|
155
159
|
assert_equal 'OAuth2::AccessToken', rcsdk.token.class.name
|
156
160
|
end
|
157
161
|
|
158
162
|
def test_authorize_password_with_refresh
|
159
|
-
rcsdk = new_client
|
160
|
-
rcsdk.set_oauth2_client
|
163
|
+
rcsdk = new_client
|
164
|
+
rcsdk.set_oauth2_client
|
161
165
|
|
162
166
|
stub_token_hash = data_auth_token_with_refresh
|
163
|
-
stub_token = OAuth2::AccessToken
|
167
|
+
stub_token = OAuth2::AccessToken.from_hash(rcsdk.oauth2client, stub_token_hash)
|
164
168
|
|
165
169
|
rcsdk.oauth2client.password.stubs(:get_token).returns(stub_token)
|
166
170
|
|
@@ -171,11 +175,11 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
171
175
|
end
|
172
176
|
|
173
177
|
def test_authorize_password_without_refresh
|
174
|
-
rcsdk = new_client
|
175
|
-
rcsdk.set_oauth2_client
|
178
|
+
rcsdk = new_client
|
179
|
+
rcsdk.set_oauth2_client
|
176
180
|
|
177
181
|
stub_token_hash = data_auth_token_without_refresh
|
178
|
-
stub_token = OAuth2::AccessToken
|
182
|
+
stub_token = OAuth2::AccessToken.from_hash(rcsdk.oauth2client, stub_token_hash)
|
179
183
|
|
180
184
|
rcsdk.oauth2client.password.stubs(:get_token).returns(stub_token)
|
181
185
|
|
@@ -187,28 +191,28 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
187
191
|
|
188
192
|
def test_request
|
189
193
|
assert_raise do
|
190
|
-
@rcsdk.request
|
194
|
+
@rcsdk.request
|
191
195
|
end
|
192
196
|
|
193
|
-
client = new_client
|
194
|
-
client.set_oauth2_client
|
197
|
+
client = new_client
|
198
|
+
client.set_oauth2_client
|
195
199
|
|
196
200
|
stub_token_hash = data_auth_token_with_refresh
|
197
|
-
stub_token = OAuth2::AccessToken
|
201
|
+
stub_token = OAuth2::AccessToken.from_hash(client.oauth2client, stub_token_hash)
|
198
202
|
|
199
203
|
client.oauth2client.password.stubs(:get_token).returns(stub_token)
|
200
204
|
|
201
205
|
client.authorize('my_test_username', 'my_test_extension', 'my_test_password')
|
202
206
|
|
203
|
-
|
207
|
+
# @rcsdk.client.stubs(:post).returns(Faraday::Response.new)
|
204
208
|
Faraday::Connection.any_instance.stubs(:post).returns(Faraday::Response.new)
|
205
209
|
|
206
210
|
fax = RingCentralSdk::REST::Request::Fax.new(
|
207
211
|
# phone numbers are in E.164 format with or without leading '+'
|
208
|
-
:
|
209
|
-
:
|
210
|
-
:
|
211
|
-
:
|
212
|
+
to: '+16505551212',
|
213
|
+
faxResolution: 'High',
|
214
|
+
coverPageText: 'RingCentral fax demo using Ruby SDK!',
|
215
|
+
text: 'RingCentral fax demo using Ruby SDK!'
|
212
216
|
)
|
213
217
|
res = client.send_request(fax)
|
214
218
|
assert_equal 'Faraday::Response', res.class.name
|
@@ -218,10 +222,10 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
218
222
|
end
|
219
223
|
|
220
224
|
res = client.messages.fax.create(
|
221
|
-
:
|
222
|
-
:
|
223
|
-
:
|
224
|
-
:
|
225
|
+
to: '+16505551212',
|
226
|
+
faxResolution: 'High',
|
227
|
+
coverPageText: 'RingCentral fax demo using Ruby SDK!',
|
228
|
+
text: 'RingCentral fax demo using Ruby SDK!'
|
225
229
|
)
|
226
230
|
assert_equal 'Faraday::Response', res.class.name
|
227
231
|
|
@@ -247,9 +251,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
247
251
|
request = RingCentralSdk::REST::Request::Simple.new(
|
248
252
|
method: 'put',
|
249
253
|
url: 'account/~/extension/~/message-store/11111111',
|
250
|
-
body: {
|
251
|
-
readStatus: 'Read'
|
252
|
-
}
|
254
|
+
body: { readStatus: 'Read' }
|
253
255
|
)
|
254
256
|
assert_equal 'put', request.method
|
255
257
|
|
@@ -261,7 +263,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
261
263
|
######
|
262
264
|
request = RingCentralSdk::REST::Request::Simple.new(
|
263
265
|
method: 'delete',
|
264
|
-
url: 'account/~/extension/~/message-store/11111111'
|
266
|
+
url: 'account/~/extension/~/message-store/11111111'
|
265
267
|
)
|
266
268
|
assert_equal 'delete', request.method
|
267
269
|
|
@@ -270,11 +272,11 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
270
272
|
end
|
271
273
|
|
272
274
|
def test_sms
|
273
|
-
client = new_client
|
274
|
-
client.set_oauth2_client
|
275
|
+
client = new_client
|
276
|
+
client.set_oauth2_client
|
275
277
|
|
276
278
|
stub_token_hash = data_auth_token_with_refresh
|
277
|
-
stub_token = OAuth2::AccessToken
|
279
|
+
stub_token = OAuth2::AccessToken.from_hash(client.oauth2client, stub_token_hash)
|
278
280
|
|
279
281
|
client.oauth2client.password.stubs(:get_token).returns(stub_token)
|
280
282
|
|
@@ -291,21 +293,20 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
291
293
|
method: 'post',
|
292
294
|
url: 'account/~/extension/~/sms',
|
293
295
|
body: {
|
294
|
-
from: {phoneNumber: '+16505551212'},
|
295
|
-
to: {phoneNumber: '+14155551212'},
|
296
|
+
from: { phoneNumber: '+16505551212' },
|
297
|
+
to: { phoneNumber: '+14155551212' },
|
296
298
|
text: 'Hi there!'
|
297
299
|
}
|
298
300
|
)
|
299
301
|
assert_equal 'Faraday::Response', res.class.name
|
300
302
|
end
|
301
303
|
|
302
|
-
def new_client
|
303
|
-
|
304
|
-
'my_app_key'
|
305
|
-
'my_app_secret'
|
306
|
-
RingCentralSdk::RC_SERVER_PRODUCTION
|
307
|
-
|
308
|
-
)
|
304
|
+
def new_client
|
305
|
+
RingCentralSdk::REST::Client.new do |config|
|
306
|
+
config.app_key = 'my_app_key'
|
307
|
+
config.app_secret = 'my_app_secret'
|
308
|
+
config.server_url = RingCentralSdk::RC_SERVER_PRODUCTION
|
309
|
+
end
|
309
310
|
end
|
310
311
|
|
311
312
|
def data_auth_token_with_refresh
|
@@ -318,8 +319,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
318
319
|
"scope": "ReadCallLog DirectRingOut EditCallLog ReadAccounts Contacts EditExtensions ReadContacts SMS EditPresence RingOut EditCustomData ReadPresence EditPaymentInfo Interoperability Accounts NumberLookup InternalMessages ReadCallRecording EditAccounts Faxes EditReportingSettings ReadClientInfo EditMessages VoipCalling ReadMessages",
|
319
320
|
"owner_id": "1234567890"
|
320
321
|
}'
|
321
|
-
|
322
|
-
return data
|
322
|
+
JSON.parse(json, symbolize_names: true)
|
323
323
|
end
|
324
324
|
|
325
325
|
def data_auth_token_without_refresh
|
@@ -330,9 +330,8 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
|
|
330
330
|
"scope": "ReadCallLog DirectRingOut EditCallLog ReadAccounts Contacts EditExtensions ReadContacts SMS EditPresence RingOut EditCustomData ReadPresence EditPaymentInfo Interoperability Accounts NumberLookup InternalMessages ReadCallRecording EditAccounts Faxes EditReportingSettings ReadClientInfo EditMessages VoipCalling ReadMessages",
|
331
331
|
"owner_id": "1234567890"
|
332
332
|
}'
|
333
|
-
|
334
|
-
return data
|
333
|
+
JSON.parse(json, symbolize_names: true)
|
335
334
|
end
|
336
335
|
|
337
|
-
|
336
|
+
alias data_auth_token data_auth_token_with_refresh
|
338
337
|
end
|
data/test/test_event.rb
CHANGED
@@ -3,7 +3,7 @@ require 'multi_json'
|
|
3
3
|
|
4
4
|
class RingCentralSdkRESTEventTest < Test::Unit::TestCase
|
5
5
|
def test_new_sms_count
|
6
|
-
data = data_test_json_sms
|
6
|
+
data = data_test_json_sms
|
7
7
|
|
8
8
|
event = RingCentralSdk::REST::Event.new data
|
9
9
|
|
@@ -13,7 +13,7 @@ class RingCentralSdkRESTEventTest < Test::Unit::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_new_fax_count
|
16
|
-
data = data_test_json_fax
|
16
|
+
data = data_test_json_fax
|
17
17
|
|
18
18
|
event = RingCentralSdk::REST::Event.new data
|
19
19
|
|
@@ -29,23 +29,40 @@ class RingCentralSdkRESTEventTest < Test::Unit::TestCase
|
|
29
29
|
|
30
30
|
def test_new_failure
|
31
31
|
assert_raise do
|
32
|
-
|
32
|
+
RingCentralSdk::REST::Event.new ''
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def data_test_hash
|
37
|
-
json = data_test_json
|
38
|
-
|
39
|
-
return hash
|
36
|
+
def data_test_hash
|
37
|
+
json = data_test_json
|
38
|
+
MultiJson.decode json, symbolize_keys: false
|
40
39
|
end
|
41
40
|
|
42
41
|
def data_test_json_sms
|
43
|
-
json = '{
|
44
|
-
|
42
|
+
json = '{
|
43
|
+
"uuid":"11112222-3333-4444-5555-666677778888",
|
44
|
+
"event":"/restapi/v1.0/account/~/extension/22222222/message-store",
|
45
|
+
"timestamp":"2016-01-31T00:15:30.196Z",
|
46
|
+
"body":{
|
47
|
+
"extensionId":22222222,
|
48
|
+
"lastUpdated":"2016-01-31T00:15:15.923+0000",
|
49
|
+
"changes":[{"type":"SMS","newCount":1,"updatedCount":1}]
|
50
|
+
}
|
51
|
+
}'
|
52
|
+
MultiJson.decode json, symbolize_keys: true
|
45
53
|
end
|
46
54
|
|
47
55
|
def data_test_json_fax
|
48
|
-
json = '{
|
49
|
-
|
56
|
+
json = '{
|
57
|
+
"uuid":"11112222-3333-4444-5555-666677778888",
|
58
|
+
"event":"/restapi/v1.0/account/~/extension/22222222/message-store",
|
59
|
+
"timestamp":"2016-02-07T14:28:29.010Z",
|
60
|
+
"body":{
|
61
|
+
"extensionId":22222222,
|
62
|
+
"lastUpdated":"2016-02-07T14:28:21.961+0000",
|
63
|
+
"changes":[{"type":"Fax","newCount":1,"updatedCount":0}]
|
64
|
+
}
|
65
|
+
}'
|
66
|
+
MultiJson.decode json, symbolize_keys: false
|
50
67
|
end
|
51
68
|
end
|
@@ -2,50 +2,59 @@ require './test/test_base.rb'
|
|
2
2
|
|
3
3
|
class RingCentralSdkRESTExtensionPresenceTest < Test::Unit::TestCase
|
4
4
|
def new_client
|
5
|
-
|
6
|
-
'my_app_key'
|
7
|
-
'my_app_secret'
|
8
|
-
RingCentralSdk::RC_SERVER_SANDBOX
|
9
|
-
|
10
|
-
return client
|
5
|
+
RingCentralSdk::REST::Client.new do |config|
|
6
|
+
config.app_key = 'my_app_key'
|
7
|
+
config.app_secret = 'my_app_secret'
|
8
|
+
config.server_url = RingCentralSdk::RC_SERVER_SANDBOX
|
9
|
+
end
|
11
10
|
end
|
12
11
|
|
13
12
|
def test_department_calls_enable
|
14
|
-
presence = RingCentralSdk::REST::ExtensionPresence.new(
|
13
|
+
presence = RingCentralSdk::REST::ExtensionPresence.new(111_111)
|
15
14
|
|
16
15
|
new_statuses = {
|
17
|
-
:
|
16
|
+
enable: {
|
18
17
|
'DoNotAcceptAnyCalls' => 'TakeDepartmentCallsOnly',
|
19
18
|
'DoNotAcceptDepartmentCalls' => 'TakeAllCalls'
|
20
19
|
},
|
21
|
-
:
|
20
|
+
disable: {
|
22
21
|
'TakeAllCalls' => 'DoNotAcceptDepartmentCalls',
|
23
22
|
'TakeDepartmentCallsOnly' => 'DoNotAcceptAnyCalls'
|
24
23
|
}
|
25
24
|
}
|
26
25
|
|
27
26
|
cur_status = 'TakeAllCalls'
|
28
|
-
assert_equal
|
27
|
+
assert_equal \
|
28
|
+
'DoNotAcceptDepartmentCalls', \
|
29
29
|
presence.new_status_dnd_department_calls(cur_status, false)
|
30
|
-
|
30
|
+
|
31
|
+
assert_equal \
|
32
|
+
'TakeAllCalls', \
|
31
33
|
presence.new_status_dnd_department_calls(cur_status, true)
|
32
34
|
|
33
35
|
cur_status = 'TakeDepartmentCallsOnly'
|
34
|
-
assert_equal
|
36
|
+
assert_equal \
|
37
|
+
'DoNotAcceptAnyCalls', \
|
35
38
|
presence.new_status_dnd_department_calls(cur_status, false)
|
36
|
-
assert_equal
|
39
|
+
assert_equal \
|
40
|
+
'TakeDepartmentCallsOnly', \
|
37
41
|
presence.new_status_dnd_department_calls(cur_status, true)
|
38
42
|
|
39
43
|
cur_status = 'DoNotAcceptAnyCalls'
|
40
|
-
|
44
|
+
|
45
|
+
assert_equal \
|
46
|
+
'DoNotAcceptAnyCalls', \
|
41
47
|
presence.new_status_dnd_department_calls(cur_status, false)
|
42
|
-
assert_equal
|
48
|
+
assert_equal \
|
49
|
+
'TakeDepartmentCallsOnly', \
|
43
50
|
presence.new_status_dnd_department_calls(cur_status, true)
|
44
51
|
|
45
52
|
cur_status = 'DoNotAcceptDepartmentCalls'
|
46
|
-
assert_equal
|
53
|
+
assert_equal \
|
54
|
+
'DoNotAcceptDepartmentCalls', \
|
47
55
|
presence.new_status_dnd_department_calls(cur_status, false)
|
48
|
-
assert_equal
|
56
|
+
assert_equal \
|
57
|
+
'TakeAllCalls', \
|
49
58
|
presence.new_status_dnd_department_calls(cur_status, true)
|
50
59
|
end
|
51
60
|
|
@@ -57,16 +66,16 @@ class RingCentralSdkRESTExtensionPresenceTest < Test::Unit::TestCase
|
|
57
66
|
Faraday::Connection.any_instance.stubs(:get).returns(Faraday::Response.new)
|
58
67
|
Faraday::Connection.any_instance.stubs(:put).returns(Faraday::Response.new)
|
59
68
|
|
60
|
-
presence = RingCentralSdk::REST::ExtensionPresence.new(
|
61
|
-
presence.retrieve
|
69
|
+
presence = RingCentralSdk::REST::ExtensionPresence.new(111_111, client: client)
|
70
|
+
presence.retrieve
|
62
71
|
presence.presence_data = stub_presence
|
63
72
|
|
64
73
|
assert_equal 'TakeAllCalls', presence.presence_data['dndStatus']
|
65
74
|
|
66
75
|
assert_equal true, presence.department_calls_enabled?
|
67
76
|
|
68
|
-
#new_status = presence.department_calls_enable false
|
69
|
-
#assert_equal 'DoNotAcceptDepartmentCalls', new_status
|
77
|
+
# new_status = presence.department_calls_enable false
|
78
|
+
# assert_equal 'DoNotAcceptDepartmentCalls', new_status
|
70
79
|
|
71
80
|
presence.extension_id = 'abc'
|
72
81
|
assert_raise do
|
@@ -77,7 +86,7 @@ class RingCentralSdkRESTExtensionPresenceTest < Test::Unit::TestCase
|
|
77
86
|
presence.update nil
|
78
87
|
end
|
79
88
|
|
80
|
-
presence.update(
|
89
|
+
presence.update(dndStatus: 'TakeAllCalls')
|
81
90
|
|
82
91
|
######
|
83
92
|
# Test with good data
|
@@ -104,59 +113,52 @@ class RingCentralSdkRESTExtensionPresenceTest < Test::Unit::TestCase
|
|
104
113
|
"ringOnMonitoredCall": false,
|
105
114
|
"pickUpCallsOnHold": false
|
106
115
|
}'
|
107
|
-
|
108
|
-
return data
|
116
|
+
JSON.parse json, symbolize_names: false
|
109
117
|
end
|
110
118
|
end
|
111
119
|
|
112
120
|
class RingCentralSdkTestSubAuth
|
113
|
-
|
114
121
|
def new_client
|
115
|
-
|
116
|
-
'my_app_key'
|
117
|
-
'my_app_secret'
|
118
|
-
RingCentralSdk::RC_SERVER_SANDBOX
|
119
|
-
|
120
|
-
return client
|
122
|
+
RingCentralSdk::REST::Client.new do |config|
|
123
|
+
config.app_key = 'my_app_key'
|
124
|
+
config.app_secret = 'my_app_secret'
|
125
|
+
config.server_url = RingCentralSdk::RC_SERVER_SANDBOX
|
126
|
+
end
|
121
127
|
end
|
122
128
|
|
123
|
-
def new_client_with_auth
|
124
|
-
client = new_client
|
125
|
-
client.set_oauth2_client
|
129
|
+
def new_client_with_auth
|
130
|
+
client = new_client
|
131
|
+
client.set_oauth2_client
|
126
132
|
|
127
133
|
stub_token_hash = data_auth_token_with_refresh
|
128
|
-
stub_token = OAuth2::AccessToken
|
134
|
+
stub_token = OAuth2::AccessToken.from_hash(client.oauth2client, stub_token_hash)
|
129
135
|
|
130
136
|
client.oauth2client.password.stubs(:get_token).returns(stub_token)
|
131
|
-
|
132
|
-
|
133
|
-
return client
|
137
|
+
client.authorize('my_test_username', 'my_test_extension', 'my_test_password')
|
138
|
+
client
|
134
139
|
end
|
135
140
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
141
|
+
def data_auth_token_with_refresh
|
142
|
+
json = '{
|
143
|
+
"access_token": "my_test_access_token_with_refresh",
|
144
|
+
"token_type": "bearer",
|
145
|
+
"expires_in": 3599,
|
146
|
+
"refresh_token": "my_test_refresh_token",
|
147
|
+
"refresh_token_expires_in": 604799,
|
148
|
+
"scope": "ReadCallLog DirectRingOut EditCallLog ReadAccounts Contacts EditExtensions ReadContacts SMS EditPresence RingOut EditCustomData ReadPresence EditPaymentInfo Interoperability Accounts NumberLookup InternalMessages ReadCallRecording EditAccounts Faxes EditReportingSettings ReadClientInfo EditMessages VoipCalling ReadMessages",
|
149
|
+
"owner_id": "1234567890"
|
145
150
|
}'
|
146
|
-
|
147
|
-
|
148
|
-
end
|
151
|
+
JSON.parse(json, symbolize_names: true)
|
152
|
+
end
|
149
153
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
154
|
+
def data_auth_token_without_refresh
|
155
|
+
json = '{
|
156
|
+
"access_token": "my_test_access_token_without_refresh",
|
157
|
+
"token_type": "bearer",
|
158
|
+
"expires_in": 3599,
|
159
|
+
"scope": "ReadCallLog DirectRingOut EditCallLog ReadAccounts Contacts EditExtensions ReadContacts SMS EditPresence RingOut EditCustomData ReadPresence EditPaymentInfo Interoperability Accounts NumberLookup InternalMessages ReadCallRecording EditAccounts Faxes EditReportingSettings ReadClientInfo EditMessages VoipCalling ReadMessages",
|
160
|
+
"owner_id": "1234567890"
|
157
161
|
}'
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
end
|
162
|
+
JSON.parse(json, symbolize_names: true)
|
163
|
+
end
|
164
|
+
end
|