ringcentral_sdk 0.5.2 → 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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/Gemfile +3 -1
  4. data/Gemfile.lock +96 -0
  5. data/README.md +66 -92
  6. data/Rakefile +3 -3
  7. data/lib/ringcentral_sdk/{cache → rest/cache}/extensions.rb +17 -19
  8. data/lib/ringcentral_sdk/rest/cache.rb +3 -0
  9. data/lib/ringcentral_sdk/{platform.rb → rest/client.rb} +61 -55
  10. data/lib/ringcentral_sdk/rest/config.rb +93 -0
  11. data/lib/ringcentral_sdk/rest/extension.rb +12 -0
  12. data/lib/ringcentral_sdk/rest/extension_presence.rb +104 -0
  13. data/lib/ringcentral_sdk/rest/messages.rb +46 -0
  14. data/lib/ringcentral_sdk/{helpers/request.rb → rest/request/base.rb} +2 -2
  15. data/lib/ringcentral_sdk/rest/request/fax.rb +121 -0
  16. data/lib/ringcentral_sdk/{helpers → rest/request}/inflator/contact_info.rb +1 -1
  17. data/lib/ringcentral_sdk/rest/request/inflator.rb +3 -0
  18. data/lib/ringcentral_sdk/rest/request.rb +5 -0
  19. data/lib/ringcentral_sdk/{simple.rb → rest/simple_client.rb} +10 -10
  20. data/lib/ringcentral_sdk/{subscription.rb → rest/subscription.rb} +8 -8
  21. data/lib/ringcentral_sdk/rest.rb +15 -0
  22. data/lib/ringcentral_sdk.rb +3 -7
  23. data/mkdocs.yml +30 -0
  24. data/ringcentral_sdk-0.5.2.gem +0 -0
  25. data/ringcentral_sdk.gemspec +31 -0
  26. data/test/{test_helper.rb → test_base.rb} +3 -3
  27. data/test/{test_platform.rb → test_client.rb} +58 -28
  28. data/test/test_config.rb +29 -0
  29. data/test/test_extension_presence.rb +154 -0
  30. data/test/test_helper_fax.rb +42 -39
  31. data/test/test_helper_inflator_contact_info.rb +3 -3
  32. data/test/test_helper_request.rb +3 -4
  33. data/test/test_setup.rb +4 -4
  34. data/test/test_subscription.rb +9 -9
  35. metadata +95 -48
  36. data/lib/ringcentral_sdk/cache.rb +0 -3
  37. data/lib/ringcentral_sdk/helpers/extension_presence.rb +0 -129
  38. data/lib/ringcentral_sdk/helpers/fax.rb +0 -160
  39. data/lib/ringcentral_sdk/helpers/inflator.rb +0 -3
  40. data/lib/ringcentral_sdk/helpers/messages.rb +0 -19
  41. data/lib/ringcentral_sdk/helpers.rb +0 -7
@@ -6,7 +6,7 @@ require 'openssl'
6
6
  require 'pubnub'
7
7
  require 'timers'
8
8
 
9
- module RingCentralSdk
9
+ module RingCentralSdk::REST
10
10
  class Subscription
11
11
  include Observable
12
12
 
@@ -14,8 +14,8 @@ module RingCentralSdk
14
14
 
15
15
  attr_reader :event_filters
16
16
 
17
- def initialize(platform)
18
- @_platform = platform
17
+ def initialize(client)
18
+ @_client = client
19
19
  @event_filters = []
20
20
  @_timeout = nil
21
21
  @_subscription = nil_subscription()
@@ -72,10 +72,10 @@ module RingCentralSdk
72
72
  end
73
73
 
74
74
  begin
75
- response = @_platform.client.post do |req|
75
+ response = @_client.http.post do |req|
76
76
  req.url 'subscription'
77
77
  req.body = {
78
- :eventFilters => @_platform.create_urls(@event_filters),
78
+ :eventFilters => @_client.create_urls(@event_filters),
79
79
  :deliveryMode => {
80
80
  :transportType => 'PubNub'
81
81
  }
@@ -109,10 +109,10 @@ module RingCentralSdk
109
109
  _clear_timeout()
110
110
 
111
111
  begin
112
- response = @_platform.client.put do |req|
112
+ response = @_client.http.put do |req|
113
113
  req.url 'subscription/' + @_subscription['id'].to_s
114
114
  req.body = {
115
- :eventFilters => @_platform.create_urls(@event_filters),
115
+ :eventFilters => @_client.create_urls(@event_filters),
116
116
  }
117
117
  end
118
118
 
@@ -135,7 +135,7 @@ module RingCentralSdk
135
135
 
136
136
  begin
137
137
  url = 'subscription/' + @_subscription['id'].to_s
138
- response = @_platform.client.delete do |req|
138
+ response = @_client.http.delete do |req|
139
139
  req.url = 'subscription' + @_subscription['id']
140
140
  end
141
141
  reset()
@@ -0,0 +1,15 @@
1
+ module RingCentralSdk::REST
2
+ autoload :Cache, 'ringcentral_sdk/rest/cache'
3
+ autoload :Client, 'ringcentral_sdk/rest/client'
4
+ autoload :Config, 'ringcentral_sdk/rest/config'
5
+ autoload :ConfigApp, 'ringcentral_sdk/rest/config'
6
+ autoload :ConfigUser, 'ringcentral_sdk/rest/config'
7
+ autoload :ConfigEnvRc, 'ringcentral_sdk/rest/config'
8
+ autoload :Extension, 'ringcentral_sdk/rest/extension'
9
+ autoload :ExtensionPresence, 'ringcentral_sdk/rest/extension_presence'
10
+ autoload :Messages, 'ringcentral_sdk/rest/messages'
11
+ autoload :MessagesFax, 'ringcentral_sdk/rest/messages'
12
+ autoload :MessagesSMS, 'ringcentral_sdk/rest/messages'
13
+ autoload :Request, 'ringcentral_sdk/rest/request'
14
+ autoload :Subscription, 'ringcentral_sdk/rest/subscription'
15
+ end
@@ -1,19 +1,15 @@
1
1
  module RingCentralSdk
2
2
 
3
- VERSION = '0.5.2'
3
+ VERSION = '1.0.0'
4
4
 
5
5
  RC_SERVER_PRODUCTION = 'https://platform.ringcentral.com'
6
6
  RC_SERVER_SANDBOX = 'https://platform.devtest.ringcentral.com'
7
7
 
8
- autoload :Cache, 'ringcentral_sdk/cache'
9
- autoload :Helpers, 'ringcentral_sdk/helpers'
10
- autoload :Platform, 'ringcentral_sdk/platform'
11
- autoload :Simple, 'ringcentral_sdk/simple'
12
- autoload :Subscription, 'ringcentral_sdk/subscription'
8
+ autoload :REST, 'ringcentral_sdk/rest'
13
9
 
14
10
  class << self
15
11
  def new(app_key, app_secret, server_url=RC_SERVER_SANDBOX, opts={})
16
- RingCentralSdk::Platform.new(app_key, app_secret, server_url, opts)
12
+ RingCentralSdk::REST::Client.new(app_key, app_secret, server_url, opts)
17
13
  end
18
14
  end
19
15
 
data/mkdocs.yml ADDED
@@ -0,0 +1,30 @@
1
+ site_name: RingCentral SDK for Ruby
2
+ site_url: https://github.com/grokify/ringcentral-sdk-ruby
3
+ repo_url: https://github.com/grokify/ringcentral-sdk-ruby.git
4
+ docs_dir: docs
5
+ theme: readthedocs
6
+ pages:
7
+ # Introduction:
8
+ - ['index.md', 'About', 'RingCentral SDK']
9
+ - ['quickstart.md', 'About', 'Quickstart']
10
+
11
+ ## Authorization:
12
+ - ['usage/authorization/Authorization.md', 'Authorization', 'Authorization']
13
+
14
+ ## Generic HTTP
15
+ - ['usage/http-client.md', 'Generic Requests', 'HTTP Client']
16
+
17
+ ## Messaging:
18
+ - ['usage/messages/SMS-Messages.md', 'Messaging', 'SMS Messages']
19
+ - ['usage/messages/Fax-Messages.md', 'Messaging', 'Fax Messages']
20
+
21
+ ## Voice:
22
+ - ['usage/voice/Click-To-Call.md', 'Voice', 'Click-To-Call']
23
+ - ['usage/messages/Call-Recordings.md', 'Voice', 'Call Recordings']
24
+
25
+ ## Call Queues:
26
+ - ['usage/callqueues/Member-Status.md', 'Call Queues', 'Member Status']
27
+
28
+ ## Notifications:
29
+ - ['usage/notifications/Subscriptions.md', 'Notifications', 'Subscriptions']
30
+ - ['usage/notifications/Subscriptions-All-Extensions.md', 'Notifications', 'Subscribe to All Extensions']
Binary file
@@ -0,0 +1,31 @@
1
+ lib = 'ringcentral_sdk'
2
+ lib_file = File.expand_path("../lib/#{lib}.rb", __FILE__)
3
+ File.read(lib_file) =~ /\bVERSION\s*=\s*["'](.+?)["']/
4
+ version = $1
5
+ #require File.expand_path('../lib/ringcentral_sdk/version', __FILE__)
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'ringcentral_sdk'
9
+ s.version = version
10
+ s.date = '2016-01-21'
11
+ s.summary = 'RingCentral SDK - Ruby SDK for the RingCentral Connect Platform API'
12
+ s.description = 'A Ruby SDK for the RingCentral Connect Platform API'
13
+ s.authors = ['John Wang']
14
+ s.email = 'johncwang@gmail.com'
15
+ s.homepage = 'https://github.com/grokify/'
16
+ s.licenses = ['MIT']
17
+ s.files = Dir['lib/**/**/*'] # + Dir['bin/*']
18
+ s.files += Dir['[A-Z]*'] + Dir['test/**/*']
19
+ # s.files.reject! { |fn| fn.include? "CVS" }
20
+ # s.required_ruby_version = '>= 1.8.7' # 1.8.7+ is tested
21
+ s.add_dependency 'dotenv', '~> 2.1', '>= 2.1.0'
22
+ s.add_dependency 'faraday', '~> 0.9', '>= 0.9'
23
+ s.add_dependency 'faraday_middleware', '~> 0', '>= 0'
24
+ s.add_dependency 'faraday_middleware-oauth2_refresh', '~> 0'
25
+ s.add_dependency 'mime', '~> 0.4', '>= 0.4.3'
26
+ s.add_dependency 'mime-types', '~> 1.25' # >= 1.9 '~> 2.5', '>= 2.5'
27
+ s.add_dependency 'multi_json', '~> 1.3'
28
+ s.add_dependency 'oauth2', '~> 1.0', '>= 1.0.0'
29
+ s.add_dependency 'pubnub', '~> 3.7', '>= 3.7.3'
30
+ s.add_dependency 'timers', '~> 0'
31
+ end
@@ -2,11 +2,11 @@ require 'coveralls'
2
2
  Coveralls.wear!
3
3
 
4
4
  require 'test/unit'
5
- require "mocha/test_unit"
5
+ require 'mocha/test_unit'
6
6
  require 'ringcentral_sdk'
7
7
 
8
- rcsdk = RingCentralSdk.new(
8
+ client = RingCentralSdk.new(
9
9
  'my_app_key',
10
10
  'my_app_secret',
11
11
  RingCentralSdk::RC_SERVER_SANDBOX
12
- )
12
+ )
@@ -1,4 +1,4 @@
1
- require './test/test_helper.rb'
1
+ require './test/test_base.rb'
2
2
 
3
3
  require 'faraday'
4
4
  require 'oauth2'
@@ -17,13 +17,13 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_set_client
20
- rcsdk = new_rcsdk()
20
+ rcsdk = new_client()
21
21
  assert_equal true, rcsdk.oauth2client.is_a?(OAuth2::Client)
22
22
 
23
23
  rcsdk.set_oauth2_client()
24
24
  assert_equal true, rcsdk.oauth2client.is_a?(OAuth2::Client)
25
25
 
26
- rcsdk = new_rcsdk()
26
+ rcsdk = new_client()
27
27
  oauth2client = OAuth2::Client.new(
28
28
  'my_app_key',
29
29
  'my_app_secret',
@@ -43,7 +43,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
43
43
  @rcsdk.set_token(token_data)
44
44
 
45
45
  assert_equal 'OAuth2::AccessToken', @rcsdk.token.class.name
46
- assert_equal 'Faraday::Connection', @rcsdk.client.class.name
46
+ assert_equal 'Faraday::Connection', @rcsdk.http.class.name
47
47
 
48
48
  assert_raise do
49
49
  @rcsdk.set_token('test')
@@ -55,10 +55,12 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
55
55
  'my_app_key',
56
56
  'my_app_secret',
57
57
  RingCentralSdk::RC_SERVER_PRODUCTION,
58
- {:redirect_uri => 'http://localhost:4567/oauth'}
58
+ {:redirect_url => 'http://localhost:4567/oauth'}
59
59
  )
60
60
  authorize_url = rcsdk.authorize_url()
61
61
 
62
+ puts authorize_url
63
+
62
64
  assert_equal true, authorize_url.is_a?(String)
63
65
  assert_equal 0, authorize_url.index(RingCentralSdk::RC_SERVER_PRODUCTION)
64
66
  assert_equal true, (authorize_url.index('localhost') > 0) ? true : false
@@ -89,7 +91,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
89
91
  end
90
92
 
91
93
  def test_authorize_code
92
- rcsdk = new_rcsdk()
94
+ rcsdk = new_client()
93
95
  rcsdk.set_oauth2_client()
94
96
 
95
97
  stub_token_hash = data_auth_token_with_refresh
@@ -101,7 +103,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
101
103
  assert_equal 'OAuth2::AccessToken', token.class.name
102
104
  assert_equal 'OAuth2::AccessToken', rcsdk.token.class.name
103
105
 
104
- rcsdk = new_rcsdk({:redirect_uri => 'http://localhost:4567/oauth'})
106
+ rcsdk = new_client({:redirect_uri => 'http://localhost:4567/oauth'})
105
107
  rcsdk.set_oauth2_client()
106
108
 
107
109
  stub_token_hash = data_auth_token_with_refresh
@@ -113,7 +115,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
113
115
  assert_equal 'OAuth2::AccessToken', token.class.name
114
116
  assert_equal 'OAuth2::AccessToken', rcsdk.token.class.name
115
117
 
116
- rcsdk = new_rcsdk()
118
+ rcsdk = new_client()
117
119
  rcsdk.set_oauth2_client()
118
120
 
119
121
  stub_token_hash = data_auth_token
@@ -125,7 +127,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
125
127
  assert_equal 'OAuth2::AccessToken', token.class.name
126
128
  assert_equal 'OAuth2::AccessToken', rcsdk.token.class.name
127
129
 
128
- rcsdk = new_rcsdk()
130
+ rcsdk = new_client()
129
131
  rcsdk.set_oauth2_client()
130
132
 
131
133
  stub_token_hash = data_auth_token
@@ -139,7 +141,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
139
141
  end
140
142
 
141
143
  def test_authorize_password_with_refresh
142
- rcsdk = new_rcsdk()
144
+ rcsdk = new_client()
143
145
  rcsdk.set_oauth2_client()
144
146
 
145
147
  stub_token_hash = data_auth_token_with_refresh
@@ -154,7 +156,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
154
156
  end
155
157
 
156
158
  def test_authorize_password_without_refresh
157
- rcsdk = new_rcsdk()
159
+ rcsdk = new_client()
158
160
  rcsdk.set_oauth2_client()
159
161
 
160
162
  stub_token_hash = data_auth_token_without_refresh
@@ -173,34 +175,62 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
173
175
  @rcsdk.request()
174
176
  end
175
177
 
176
- rcsdk = new_rcsdk()
177
- rcsdk.set_oauth2_client()
178
+ client = new_client()
179
+ client.set_oauth2_client()
178
180
 
179
181
  stub_token_hash = data_auth_token_with_refresh
180
- stub_token = OAuth2::AccessToken::from_hash(rcsdk.oauth2client, stub_token_hash)
182
+ stub_token = OAuth2::AccessToken::from_hash(client.oauth2client, stub_token_hash)
181
183
 
182
- rcsdk.oauth2client.password.stubs(:get_token).returns(stub_token)
184
+ client.oauth2client.password.stubs(:get_token).returns(stub_token)
183
185
 
184
- token = rcsdk.authorize('my_test_username', 'my_test_extension', 'my_test_password')
186
+ token = client.authorize('my_test_username', 'my_test_extension', 'my_test_password')
185
187
 
186
188
  #@rcsdk.client.stubs(:post).returns(Faraday::Response.new)
187
189
  Faraday::Connection.any_instance.stubs(:post).returns(Faraday::Response.new)
188
190
 
189
- fax = RingCentralSdk::Helpers::CreateFaxRequest.new(
190
- nil, # Can be nil or {} for defaults '~'
191
- {
192
- # phone numbers are in E.164 format with or without leading '+'
193
- :to => '+16505551212',
194
- :faxResolution => 'High',
195
- :coverPageText => 'RingCentral fax demo using Ruby SDK!'
196
- },
197
- :text => 'RingCentral fax demo using Ruby SDK!'
191
+ fax = RingCentralSdk::REST::Request::Fax.new(
192
+ # phone numbers are in E.164 format with or without leading '+'
193
+ :to => '+16505551212',
194
+ :faxResolution => 'High',
195
+ :coverPageText => 'RingCentral fax demo using Ruby SDK!',
196
+ :text => 'RingCentral fax demo using Ruby SDK!'
197
+ )
198
+ res = client.send_request(fax)
199
+ assert_equal 'Faraday::Response', res.class.name
200
+
201
+ assert_raise do
202
+ res = client.send_request('non-fax')
203
+ end
204
+
205
+ res = client.messages.fax.create(
206
+ :to => '+16505551212',
207
+ :faxResolution => 'High',
208
+ :coverPageText => 'RingCentral fax demo using Ruby SDK!',
209
+ :text => 'RingCentral fax demo using Ruby SDK!'
210
+ )
211
+ assert_equal 'Faraday::Response', res.class.name
212
+ end
213
+
214
+ def test_sms
215
+ client = new_client()
216
+ client.set_oauth2_client()
217
+
218
+ stub_token_hash = data_auth_token_with_refresh
219
+ stub_token = OAuth2::AccessToken::from_hash(client.oauth2client, stub_token_hash)
220
+
221
+ client.oauth2client.password.stubs(:get_token).returns(stub_token)
222
+
223
+ token = client.authorize('my_test_username', 'my_test_extension', 'my_test_password')
224
+
225
+ res = client.messages.sms.create(
226
+ :from => '+16505551212',
227
+ :to => '+14155551212',
228
+ :text => 'test'
198
229
  )
199
- res = rcsdk.request(fax)
200
230
  assert_equal 'Faraday::Response', res.class.name
201
231
  end
202
232
 
203
- def new_rcsdk(opts={})
233
+ def new_client(opts={})
204
234
  return RingCentralSdk.new(
205
235
  'my_app_key',
206
236
  'my_app_secret',
@@ -236,4 +266,4 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
236
266
  end
237
267
 
238
268
  alias_method :data_auth_token, :data_auth_token_with_refresh
239
- end
269
+ end
@@ -0,0 +1,29 @@
1
+ require './test/test_base.rb'
2
+
3
+ require 'faraday'
4
+ require 'oauth2'
5
+
6
+ class RingCentralSdkRESTConfigTest < Test::Unit::TestCase
7
+ def setup
8
+ @config = RingCentralSdk::REST::Config.new.load_dotenv
9
+ end
10
+
11
+ def test_main
12
+ @config = RingCentralSdk::REST::Config.new.load_dotenv
13
+ assert_equal 'myAppKey', @config.app.key
14
+ assert_equal 'myAppSecret', @config.app.secret
15
+ assert_equal 'myRcApiServerUrl', @config.app.server_url
16
+ assert_equal 'myRcApiRedirectUrl', @config.app.redirect_url
17
+
18
+ assert_equal 'myUsername', @config.user.username
19
+ assert_equal 'myExtension', @config.user.extension
20
+ assert_equal 'myPassword', @config.user.password
21
+
22
+ assert_equal 'demoFaxToPhoneNumber', @config.env.data['RC_DEMO_FAX_TO']
23
+
24
+ @config.user.nilify
25
+ assert_equal '', @config.user.username
26
+ assert_equal '', @config.user.extension
27
+ assert_equal '', @config.user.password
28
+ end
29
+ end
@@ -0,0 +1,154 @@
1
+ require './test/test_base.rb'
2
+
3
+ class RingCentralSdkRESTExtensionPresenceTest < Test::Unit::TestCase
4
+ def new_client
5
+ client = RingCentralSdk::REST::Client.new(
6
+ 'my_app_key',
7
+ 'my_app_secret',
8
+ RingCentralSdk::RC_SERVER_SANDBOX
9
+ )
10
+ return client
11
+ end
12
+
13
+ def test_department_calls_enable
14
+ presence = RingCentralSdk::REST::ExtensionPresence.new(111111)
15
+
16
+ new_statuses = {
17
+ :enable => {
18
+ 'DoNotAcceptAnyCalls' => 'TakeDepartmentCallsOnly',
19
+ 'DoNotAcceptDepartmentCalls' => 'TakeAllCalls'
20
+ },
21
+ :disable => {
22
+ 'TakeAllCalls' => 'DoNotAcceptDepartmentCalls',
23
+ 'TakeDepartmentCallsOnly' => 'DoNotAcceptAnyCalls'
24
+ }
25
+ }
26
+
27
+ cur_status = 'TakeAllCalls'
28
+ assert_equal 'DoNotAcceptDepartmentCalls', \
29
+ presence.new_status_dnd_department_calls(cur_status, false)
30
+ assert_equal 'TakeAllCalls', \
31
+ presence.new_status_dnd_department_calls(cur_status, true)
32
+
33
+ cur_status = 'TakeDepartmentCallsOnly'
34
+ assert_equal 'DoNotAcceptAnyCalls', \
35
+ presence.new_status_dnd_department_calls(cur_status, false)
36
+ assert_equal 'TakeDepartmentCallsOnly', \
37
+ presence.new_status_dnd_department_calls(cur_status, true)
38
+
39
+ cur_status = 'DoNotAcceptAnyCalls'
40
+ assert_equal 'DoNotAcceptAnyCalls', \
41
+ presence.new_status_dnd_department_calls(cur_status, false)
42
+ assert_equal 'TakeDepartmentCallsOnly', \
43
+ presence.new_status_dnd_department_calls(cur_status, true)
44
+
45
+ cur_status = 'DoNotAcceptDepartmentCalls'
46
+ assert_equal 'DoNotAcceptDepartmentCalls', \
47
+ presence.new_status_dnd_department_calls(cur_status, false)
48
+ assert_equal 'TakeAllCalls', \
49
+ presence.new_status_dnd_department_calls(cur_status, true)
50
+ end
51
+
52
+ def test_retrieve
53
+ stub_auth = RingCentralSdkTestSubAuth.new
54
+ client = stub_auth.new_client_with_auth
55
+ stub_presence = data_extension_presence
56
+
57
+ Faraday::Connection.any_instance.stubs(:get).returns(Faraday::Response.new)
58
+ Faraday::Connection.any_instance.stubs(:put).returns(Faraday::Response.new)
59
+
60
+ presence = RingCentralSdk::REST::ExtensionPresence.new(111111, :client => client)
61
+ presence.retrieve()
62
+ presence.presence_data = stub_presence
63
+
64
+ assert_equal 'TakeAllCalls', presence.presence_data['dndStatus']
65
+
66
+ assert_equal true, presence.department_calls_enabled?
67
+
68
+ #new_status = presence.department_calls_enable false
69
+ #assert_equal 'DoNotAcceptDepartmentCalls', new_status
70
+
71
+ presence.extension_id = 'abc'
72
+ assert_raise do
73
+ presence.retrieve
74
+ end
75
+
76
+ assert_raise do
77
+ presence.update nil
78
+ end
79
+
80
+ presence.update({:dndStatus=>'TakeAllCalls'})
81
+ end
82
+
83
+ def data_extension_presence
84
+ json = '{
85
+ "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/111111/extension/222222/presence",
86
+ "extension": {
87
+ "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/111111/extension/222222",
88
+ "id": 222222,
89
+ "extensionNumber": "102"
90
+ },
91
+ "presenceStatus": "Available",
92
+ "telephonyStatus": "NoCall",
93
+ "userStatus": "Available",
94
+ "dndStatus": "TakeAllCalls",
95
+ "allowSeeMyPresence": true,
96
+ "ringOnMonitoredCall": false,
97
+ "pickUpCallsOnHold": false
98
+ }'
99
+ data = JSON.parse(json, :symbolize_names=>false)
100
+ return data
101
+ end
102
+ end
103
+
104
+ class RingCentralSdkTestSubAuth
105
+
106
+ def new_client
107
+ client = RingCentralSdk::REST::Client.new(
108
+ 'my_app_key',
109
+ 'my_app_secret',
110
+ RingCentralSdk::RC_SERVER_SANDBOX
111
+ )
112
+ return client
113
+ end
114
+
115
+ def new_client_with_auth()
116
+ client = new_client()
117
+ client.set_oauth2_client()
118
+
119
+ stub_token_hash = data_auth_token_with_refresh
120
+ stub_token = OAuth2::AccessToken::from_hash(client.oauth2client, stub_token_hash)
121
+
122
+ client.oauth2client.password.stubs(:get_token).returns(stub_token)
123
+
124
+ token = client.authorize('my_test_username', 'my_test_extension', 'my_test_password')
125
+ return client
126
+ end
127
+
128
+ def data_auth_token_with_refresh
129
+ json = '{
130
+ "access_token": "my_test_access_token_with_refresh",
131
+ "token_type": "bearer",
132
+ "expires_in": 3599,
133
+ "refresh_token": "my_test_refresh_token",
134
+ "refresh_token_expires_in": 604799,
135
+ "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",
136
+ "owner_id": "1234567890"
137
+ }'
138
+ data = JSON.parse(json, :symbolize_names=>true)
139
+ return data
140
+ end
141
+
142
+ def data_auth_token_without_refresh
143
+ json = '{
144
+ "access_token": "my_test_access_token_without_refresh",
145
+ "token_type": "bearer",
146
+ "expires_in": 3599,
147
+ "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",
148
+ "owner_id": "1234567890"
149
+ }'
150
+ data = JSON.parse(json, :symbolize_names=>true)
151
+ return data
152
+ end
153
+
154
+ end
@@ -1,33 +1,28 @@
1
1
  # encoding: utf-8
2
2
 
3
- require './test/test_helper.rb'
3
+ require './test/test_base.rb'
4
4
 
5
5
  class RingCentralSdkHelperFaxTest < Test::Unit::TestCase
6
6
  def testSetup
7
7
 
8
- fax = RingCentralSdk::Helpers::CreateFaxRequest.new(
9
- nil, # Can be nil or {} for defaults '~'
10
- {
11
- # phone numbers are in E.164 format with or without leading '+'
12
- :to => '+16505551212',
13
- :faxResolution => 'High',
14
- :coverPageText => 'RingCentral fax demo using Ruby SDK!'
15
- },
16
- :text => 'RingCentral fax demo using Ruby SDK!'
8
+ fax = RingCentralSdk::REST::Request::Fax.new(
9
+ # phone numbers are in E.164 format with or without leading '+'
10
+ :to => '+16505551212',
11
+ :faxResolution => 'High',
12
+ :coverPageText => 'RingCentral fax demo using Ruby SDK!',
13
+ :text => 'RingCentral fax demo using Ruby SDK!'
17
14
  )
18
15
 
19
- assert_equal "RingCentralSdk::Helpers::CreateFaxRequest", fax.class.name
16
+ assert_equal "RingCentralSdk::REST::Request::Fax", fax.class.name
20
17
  assert_equal 'account/~/extension/~/fax', fax.url()
21
18
 
22
- fax2 = RingCentralSdk::Helpers::CreateFaxRequest.new(
23
- { :account_id => '111111111', :extension_id => '222222222' }, # Can be nil or {} for defaults '~'
24
- {
25
- # phone numbers are in E.164 format with or without leading '+'
26
- "to" => { :phoneNumber => '+16505551212' },
27
- :faxResolution => 'High',
28
- :coverPageText => 'RingCentral fax demo using Ruby SDK Résolution!'
29
- },
30
- :file_name => './scripts/test_file.pdf'
19
+ fax2 = RingCentralSdk::REST::Request::Fax.new(
20
+ :accountId => '111111111',
21
+ :extensionId => '222222222',
22
+ :to => { :phoneNumber => '+16505551212' },
23
+ :faxResolution => 'High',
24
+ :coverPageText => 'RingCentral fax demo using Ruby SDK Résolution!',
25
+ :files => ['./scripts/test_file.pdf']
31
26
  )
32
27
 
33
28
  assert_equal 'account/111111111/extension/222222222/fax', fax2.url()
@@ -39,37 +34,38 @@ class RingCentralSdkHelperFaxTest < Test::Unit::TestCase
39
34
  # Test UTF-8 metadata and file MIME concatenation
40
35
  body = fax2.body
41
36
 
42
- fax3 = RingCentralSdk::Helpers::CreateFaxRequest.new(
43
- { :account_id => 111111111, :extension_id => 222222222 }, # Can be nil or {} for defaults '~'
44
- {
45
- # phone numbers are in E.164 format with or without leading '+'
46
- :to => [{ :phoneNumber => '+16505551212' }],
47
- :faxResolution => 'High',
48
- :coverPageText => 'RingCentral fax demo using Ruby SDK!'
49
- },
37
+ fax3 = RingCentralSdk::REST::Request::Fax.new(
38
+ :accountId => 111111111,
39
+ :extensionId => 222222222,
40
+ # phone numbers are in E.164 format with or without leading '+'
41
+ :to => [{ :phoneNumber => '+16505551212' }],
42
+ :faxResolution => 'High',
43
+ :coverPageText => 'RingCentral fax demo using Ruby SDK!',
50
44
  :text => 'RingCentral fax demo using Ruby SDK!'
51
45
  )
52
46
 
53
47
  assert_equal 'account/111111111/extension/222222222/fax', fax3.url()
54
48
 
55
- fax4 = RingCentralSdk::Helpers::CreateFaxRequest.new(
56
- { :account_id => 111111111, :extension_id => 222222222 }, # Can be nil or {} for defaults '~'
57
- '{"to":"+16505551212","coverPageText":"RingCentral fax demo using Ruby SDK!"}',
49
+ fax4 = RingCentralSdk::REST::Request::Fax.new(
50
+ :accountId => 111111111,
51
+ :extensionId => 222222222, # Can be nil or {} for defaults '~'
52
+ :to => '+16505551212","coverPageText":"RingCentral fax demo using Ruby SDK!"}',
58
53
  :text => 'RingCentral fax demo using Ruby SDK!'
59
54
  )
60
55
  assert_equal 'account/111111111/extension/222222222/fax', fax4.url()
61
56
 
62
- fax5 = RingCentralSdk::Helpers::CreateFaxRequest.new(
63
- { :account_id => 111111111, :extension_id => 222222222 }, # Can be nil or {} for defaults '~'
64
- '{"coverPageText":"RingCentral fax demo using Ruby SDK!"}',
57
+ fax5 = RingCentralSdk::REST::Request::Fax.new(
58
+ :accountId => 111111111,
59
+ :extensionId => 222222222, # Can be nil or {} for defaults '~'
60
+ :coverPageText => "RingCentral fax demo using Ruby SDK!",
65
61
  :text => 'RingCentral fax demo using Ruby SDK!'
66
62
  )
67
63
  assert_equal 'account/111111111/extension/222222222/fax', fax5.url()
68
64
 
69
- assert_equal 'application/pdf', fax.get_file_content_type('example.pdf')
70
- assert_equal 'attachment', fax.get_attachment_content_disposition()
71
- assert_equal 'attachment; filename="example.pdf"', fax.get_attachment_content_disposition('example.pdf')
72
- assert_equal 'attachment; filename="example.pdf"', fax.get_attachment_content_disposition('/path/to/example.pdf')
65
+ #assert_equal 'application/pdf', fax.get_file_content_type('example.pdf')
66
+ #assert_equal 'attachment', fax.get_attachment_content_disposition()
67
+ #assert_equal 'attachment; filename="example.pdf"', fax.get_attachment_content_disposition('example.pdf')
68
+ #assert_equal 'attachment; filename="example.pdf"', fax.get_attachment_content_disposition('/path/to/example.pdf')
73
69
  assert_equal 'post', fax.method()
74
70
 
75
71
  content_type = fax.content_type()
@@ -85,5 +81,12 @@ class RingCentralSdkHelperFaxTest < Test::Unit::TestCase
85
81
  assert_equal '--' + boundary, lines[0]
86
82
  assert_equal '--' + boundary + '--', lines[-1]
87
83
 
84
+ fax6 = RingCentralSdk::REST::Request::Fax.new(
85
+ :accountId => 111111111,
86
+ :extensionId => 222222222, # Can be nil or {} for defaults '~'
87
+ :coverPageText => "RingCentral fax demo using Ruby SDK!",
88
+ :parts => [{:text=>'RingCentral fax demo using Ruby SDK!'}]
89
+ )
90
+ assert_equal 'account/111111111/extension/222222222/fax', fax6.url()
88
91
  end
89
- end
92
+ end