ringcentral_sdk 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_setup.rb CHANGED
@@ -1,20 +1,53 @@
1
1
  require './test/test_helper.rb'
2
2
 
3
3
  class RingCentralSdkTest < Test::Unit::TestCase
4
- def testSetup
5
-
6
- rcsdk = RingCentralSdk::Sdk.new(
7
- "myAppKey",
8
- "myAppSecret",
9
- RingCentralSdk::Sdk::RC_SERVER_SANDBOX
4
+ def setup
5
+ @rcsdk = RingCentralSdk.new(
6
+ 'my_app_key',
7
+ 'my_app_secret',
8
+ RingCentralSdk::RC_SERVER_SANDBOX
10
9
  )
10
+ end
11
11
 
12
- assert_equal "RingCentralSdk::Sdk", rcsdk.class.name
13
- assert_equal "RingCentralSdk::Platform", rcsdk.platform.class.name
12
+ def test_main
13
+ assert_equal 'RingCentralSdk::Platform', @rcsdk.class.name
14
14
 
15
15
  assert_raise do
16
- rcsdk.request(nil)
16
+ @rcsdk.request(nil)
17
17
  end
18
18
 
19
+ rcsdk = RingCentralSdk.new(
20
+ 'my_app_key',
21
+ 'my_app_secret',
22
+ RingCentralSdk::RC_SERVER_SANDBOX
23
+ )
24
+ assert_equal 'RingCentralSdk::Platform', rcsdk.class.name
25
+ end
26
+
27
+ def test_login
28
+ stub_token_hash = data_auth_token
29
+ stub_token = OAuth2::AccessToken::from_hash(@rcsdk.oauth2client, stub_token_hash)
30
+
31
+ OAuth2::Strategy::Password.any_instance.stubs(:get_token).returns(stub_token)
32
+ rcsdk = RingCentralSdk.new(
33
+ 'my_app_key',
34
+ 'my_app_secret',
35
+ RingCentralSdk::RC_SERVER_SANDBOX,
36
+ {:username => 'my_username', :password => 'my_password'}
37
+ )
38
+ end
39
+
40
+ def data_auth_token
41
+ json = '{
42
+ "access_token": "my_test_access_token",
43
+ "token_type": "bearer",
44
+ "expires_in": 3599,
45
+ "refresh_token": "my_test_refresh_token",
46
+ "refresh_token_expires_in": 604799,
47
+ "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",
48
+ "owner_id": "1234567890"
49
+ }'
50
+ data = JSON.parse(json, :symbolize_names=>true)
51
+ return data
19
52
  end
20
53
  end
@@ -0,0 +1,202 @@
1
+ require './test/test_helper.rb'
2
+
3
+ class RingCentralSdkSubscriptionTest < Test::Unit::TestCase
4
+ def setup
5
+ @rcsdk = RingCentralSdk.new(
6
+ 'myAppKey',
7
+ 'myAppSecret',
8
+ RingCentralSdk::RC_SERVER_SANDBOX
9
+ )
10
+ end
11
+
12
+ def test_main
13
+ sub = @rcsdk.create_subscription()
14
+ assert_equal "RingCentralSdk::Subscription", sub.class.name
15
+
16
+ assert_equal 0, sub.event_filters.length
17
+
18
+ sub.add_events(['/restapi/v1.0/account/~/extension/~/message-store'])
19
+ assert_equal 1, sub.event_filters.length
20
+
21
+ sub.add_events(['/restapi/v1.0/account/~/extension/~/presence'])
22
+ assert_equal 2, sub.event_filters.length
23
+
24
+ sub.set_events(['/restapi/v1.0/account/~/extension/~/presence'])
25
+ assert_equal 1, sub.event_filters.length
26
+
27
+ assert_equal false, sub.alive?
28
+
29
+ assert_raise do
30
+ sub.add_events(nil)
31
+ end
32
+
33
+ assert_raise do
34
+ sub.set_events(nil)
35
+ end
36
+
37
+ assert_raise do
38
+ sub.subscribe(nil)
39
+ end
40
+
41
+ assert_raise do
42
+ sub.renew(nil)
43
+ end
44
+
45
+ sub.set_events([])
46
+
47
+ assert_raise do
48
+ sub.subscribe()
49
+ end
50
+
51
+ assert_raise do
52
+ sub.renew()
53
+ end
54
+
55
+ # sub.subscribe(['/restapi/v1.0/account/~/extension/~/presence'])
56
+
57
+ sub_data = sub.subscription()
58
+ assert_equal sub_data['deliveryMode']['transportType'], 'PubNub'
59
+ assert_equal sub_data['deliveryMode']['encryption'], false
60
+ sub_data['deliveryMode']['encryption'] = true
61
+ sub.set_subscription(sub_data)
62
+ sub_data = sub.subscription()
63
+ assert_equal sub_data['deliveryMode']['encryption'], true
64
+
65
+ assert_equal nil, sub.pubnub()
66
+
67
+ sub.destroy()
68
+ sub_data = sub.subscription()
69
+ assert_equal sub_data['deliveryMode']['encryption'], false
70
+
71
+ end
72
+
73
+ def get_rcsdk_authorized
74
+ rcsdk = RingCentralSdk.new(
75
+ 'myAppKey',
76
+ 'myAppSecret',
77
+ RingCentralSdk::RC_SERVER_SANDBOX
78
+ )
79
+ rcsdk.set_oauth2_client()
80
+
81
+ stub_token_hash = data_test_auth_token
82
+ stub_token = OAuth2::AccessToken::from_hash(rcsdk.oauth2client, stub_token_hash)
83
+
84
+ rcsdk.oauth2client.password.stubs(:get_token).returns(stub_token)
85
+
86
+ token = rcsdk.authorize('my_test_username', 'my_test_extension', 'my_test_password')
87
+ return rcsdk
88
+ end
89
+
90
+ def test_subscribe_renew_delete_with_exceptions
91
+ # Get RCSDK Authroized
92
+ rcsdk = get_rcsdk_authorized()
93
+ # Stub Subscribe RC Response
94
+ data = data_test_subscribe()
95
+ response = Faraday::Response.new
96
+ response.stubs(:body).returns(data)
97
+ rcsdk.client.stubs(:post).returns(response)
98
+ rcsdk.client.stubs(:put).returns(response)
99
+ responseDel = Faraday::Response.new
100
+ responseDel.stubs(:body).returns('')
101
+ rcsdk.client.stubs(:delete).returns(responseDel)
102
+ # Stub Pubnub Response
103
+ Pubnub::Client.any_instance.stubs(:subscribe).returns(nil)
104
+ Pubnub::Client.any_instance.stubs(:unsubscribe).returns(nil)
105
+ # Create Subscription
106
+ sub = rcsdk.create_subscription()
107
+ # Test subscribe()
108
+ sub.subscribe(['/restapi/v1.0/account/~/extension/~/presence'])
109
+ # Test renew()
110
+ sub.renew(['/restapi/v1.0/account/~/extension/~/presence'])
111
+ assert_raise do
112
+ sub.renew([])
113
+ end
114
+ # Test subscription data
115
+ id = data['id']
116
+ data = sub.subscription()
117
+ assert_equal id.to_s, data['id'].to_s
118
+ id_new = data['id'] += 'modified'
119
+ sub.set_subscription(data)
120
+ assert_equal id_new.to_s, data['id'].to_s
121
+ # Test register()
122
+ sub.register(['/restapi/v1.0/account/~/extension/~/presence'])
123
+ # Test remove()
124
+ sub.remove()
125
+ # Test Exceptions
126
+ rcsdk2 = get_rcsdk_authorized()
127
+ rcsdk2.client.stubs(:post).raises('error')
128
+ rcsdk2.client.stubs(:put).raises('error')
129
+ rcsdk2.client.stubs(:delete).raises('error')
130
+ sub2 = rcsdk2.create_subscription()
131
+ assert_raise do
132
+ sub2.subscribe(['/restapi/v1.0/account/~/extension/~/presence'])
133
+ end
134
+ assert_raise do
135
+ sub2.renew(['/restapi/v1.0/account/~/extension/~/presence'])
136
+ end
137
+ assert_raise do
138
+ sub2.remove()
139
+ end
140
+ end
141
+
142
+ def test_decrypt_encrypted
143
+ rcsdk = get_rcsdk_authorized()
144
+ sub = rcsdk.create_subscription()
145
+ data = data_test_subscribe()
146
+ sub.set_subscription(data)
147
+ plaintext_src = '{"hello":"world"}'
148
+ # Encrypt test data
149
+ cipher = OpenSSL::Cipher::AES.new(128, :ECB)
150
+ cipher.encrypt
151
+ cipher.key = Base64.decode64(data['deliveryMode']['encryptionKey'])
152
+ ciphertext = cipher.update(plaintext_src) + cipher.final
153
+ ciphertext64 = Base64.encode64(ciphertext)
154
+ # Decrypt to JSON decoded as hash
155
+ plaintext_out = sub._decrypt(ciphertext64)
156
+ assert_equal 'world', plaintext_out['hello']
157
+ end
158
+
159
+ def data_test_auth_token
160
+ json = '{
161
+ "access_token": "my_test_access_token",
162
+ "token_type": "bearer",
163
+ "expires_in": 3599,
164
+ "refresh_token": "my_test_refresh_token",
165
+ "refresh_token_expires_in": 604799,
166
+ "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",
167
+ "owner_id": "1234567890"
168
+ }'
169
+ data = JSON.parse(json, :symbolize_names=>true)
170
+ return data
171
+ end
172
+
173
+ def data_test_subscribe
174
+ json = '{
175
+ "id": "mySubscriptionId",
176
+ "creationTime": "2015-10-18T16:41:30.048Z",
177
+ "status": "Active",
178
+ "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/subscription/mySubscriptionId",
179
+ "eventFilters": [
180
+ "/restapi/v1.0/account/1234567890/extension/1234567890/presence"
181
+ ],
182
+ "expirationTime": "2015-10-18T16:56:30.048Z",
183
+ "expiresIn": 899,
184
+ "deliveryMode": {
185
+ "transportType": "PubNub",
186
+ "encryption": true,
187
+ "address": "1234567890_deadbeef",
188
+ "subscriberKey": "sub-c-deadbeef",
189
+ "encryptionAlgorithm": "AES",
190
+ "encryptionKey": "/UjxdHILResI0XWzhXIilQ=="
191
+ }
192
+ }'
193
+ return JSON.parse(json)
194
+ end
195
+
196
+ def test_pubnub
197
+ sub = @rcsdk.create_subscription()
198
+ pub = sub.new_pubnub()
199
+
200
+ assert_equal 'Pubnub::Client', pub.class.name
201
+ end
202
+ 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.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Wang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2015-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -168,23 +168,26 @@ executables: []
168
168
  extensions: []
169
169
  extra_rdoc_files: []
170
170
  files:
171
- - CHANGELOG.md
172
- - LICENSE.txt
173
- - README.md
174
- - Rakefile
175
- - VERSION.txt
176
- - lib/ringcentral_sdk.rb
177
- - lib/ringcentral_sdk/helpers.rb
178
171
  - lib/ringcentral_sdk/helpers/fax.rb
179
- - lib/ringcentral_sdk/helpers/inflator.rb
180
172
  - lib/ringcentral_sdk/helpers/inflator/contact_info.rb
173
+ - lib/ringcentral_sdk/helpers/inflator.rb
181
174
  - lib/ringcentral_sdk/helpers/request.rb
175
+ - lib/ringcentral_sdk/helpers.rb
182
176
  - lib/ringcentral_sdk/platform.rb
183
- - lib/ringcentral_sdk/pubnub_factory.rb
184
- - lib/ringcentral_sdk/sdk.rb
185
177
  - lib/ringcentral_sdk/subscription.rb
186
- - lib/ringcentral_sdk/version.rb
178
+ - lib/ringcentral_sdk.rb
179
+ - CHANGELOG.md
180
+ - Gemfile
181
+ - LICENSE.txt
182
+ - Rakefile
183
+ - README.md
184
+ - test/test_helper.rb
185
+ - test/test_helper_fax.rb
186
+ - test/test_helper_inflator_contact_info.rb
187
+ - test/test_helper_request.rb
188
+ - test/test_platform.rb
187
189
  - test/test_setup.rb
190
+ - test/test_subscription.rb
188
191
  homepage: https://github.com/grokify/
189
192
  licenses:
190
193
  - MIT
data/VERSION.txt DELETED
@@ -1 +0,0 @@
1
- 0.4.0
@@ -1,33 +0,0 @@
1
- require 'logger'
2
- require 'pubnub'
3
-
4
- module RingCentralSdk
5
- class PubnubFactory
6
-
7
- def initialize(use_mock=false)
8
- @_use_mock = use_mock
9
- end
10
-
11
- def pubnub(subscribe_key='', ssl_on=false, publish_key='', my_logger=nil)
12
- if @_use_mock
13
- raise 'PubNub Mock is not implemented'
14
- end
15
-
16
- my_logger = Logger.new(STDOUT) if my_logger.nil?
17
-
18
- pubnub = Pubnub.new(
19
- :subscribe_key => subscribe_key.to_s,
20
- :publish_key => publish_key.to_s,
21
- :error_callback => lambda { |msg|
22
- puts "Error callback says: #{msg.inspect}"
23
- },
24
- :connect_callback => lambda { |msg|
25
- puts "CONNECTED: #{msg.inspect}"
26
- },
27
- :logger => my_logger
28
- )
29
-
30
- return pubnub
31
- end
32
- end
33
- end
@@ -1,29 +0,0 @@
1
- module RingCentralSdk
2
- class Sdk
3
-
4
- RC_SERVER_PRODUCTION = 'https://platform.ringcentral.com'
5
- RC_SERVER_SANDBOX = 'https://platform.devtest.ringcentral.com'
6
-
7
- attr_reader :platform
8
-
9
- def initialize(app_key=nil,app_secret=nil,server_url=nil,opts={})
10
- use_pubnub_mock = false
11
-
12
- @platform = RingCentralSdk::Platform.new(app_key, app_secret, server_url, opts)
13
- if opts.has_key?(:username) && opts.has_key?(:password)
14
- extension = opts.has_key?(:extension) ? opts[:extension] : ''
15
- @platform.authorize(opts[:username], extension, opts[:password])
16
- end
17
-
18
- @_pubnub_factory = RingCentralSdk::PubnubFactory.new(use_pubnub_mock)
19
- end
20
-
21
- def request(helper=nil)
22
- return @platform.request(helper)
23
- end
24
-
25
- def create_subscription()
26
- return RingCentralSdk::Subscription.new(@platform, @_pubnub_factory)
27
- end
28
- end
29
- end
@@ -1,3 +0,0 @@
1
- module RingCentralSdk
2
- VERSION = '0.4.0'
3
- end