ringcentral-sdk 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -8
- data/ringcentral-sdk.gemspec +4 -4
- data/spec/ringcentral_spec.rb +81 -0
- data/spec/subscription_spec.rb +31 -0
- metadata +6 -7
- data/Rakefile +0 -8
- data/test/test_ringcentral.rb +0 -81
- data/test/test_subscription.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 985e9f0cf6416e2288c2330b596fde160e32a381
|
4
|
+
data.tar.gz: 631d59c2a2c13baa8178fadfc466c6044209b9c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b44f5dddcbc5c65b8c1484844665ce01c2944f42f71d708992bfacbd54f0a977c98b8f87a566a456afc2bc17056328e7663e279aca1559e44059556bfecb906
|
7
|
+
data.tar.gz: 1206c7a15bb653e5cb412e1b814031c4b7726f53f39875a56e2cb8688096a1abe68ae6d7aef7c552c2a0f5d2842eeea35d1e03d7002dab44c976ad556205875f
|
data/README.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# ringcentral-ruby
|
2
|
+
|
3
|
+
Ruby SDK for RingCentral.
|
2
4
|
|
3
5
|
|
4
6
|
## Installation
|
5
7
|
|
6
|
-
|
8
|
+
```
|
9
|
+
gem install ringcentral-sdk
|
10
|
+
```
|
7
11
|
|
8
12
|
|
9
13
|
## Documentation
|
@@ -21,12 +25,12 @@ rc.authorize(username: ENV['username'], extension: ENV['extension'], password: E
|
|
21
25
|
|
22
26
|
# get
|
23
27
|
r = rc.get('/restapi/v1.0/account/~/extension/~')
|
24
|
-
|
25
|
-
|
28
|
+
expect(r).not_to be_nil
|
29
|
+
expect('101').to eq(JSON.parse(r.body)['extensionNumber'])
|
26
30
|
```
|
27
31
|
|
28
32
|
|
29
|
-
For more sample code, please refer to the [test cases](/
|
33
|
+
For more sample code, please refer to the [test cases](/spec).
|
30
34
|
|
31
35
|
|
32
36
|
## How to test
|
@@ -44,7 +48,7 @@ password=password
|
|
44
48
|
receiver=number-to-receiver-sms
|
45
49
|
```
|
46
50
|
|
47
|
-
Run `
|
51
|
+
Run `rspec`
|
48
52
|
|
49
53
|
|
50
54
|
## License
|
@@ -55,5 +59,6 @@ MIT
|
|
55
59
|
## Todo
|
56
60
|
|
57
61
|
- Travis CI
|
58
|
-
-
|
59
|
-
-
|
62
|
+
- Code coverage
|
63
|
+
- Batch requests
|
64
|
+
- Fax & SMS
|
data/ringcentral-sdk.gemspec
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'ringcentral-sdk'
|
3
|
-
gem.version = '0.
|
3
|
+
gem.version = '0.3.0'
|
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.'
|
7
7
|
gem.summary = 'RingCentral Ruby SDK.'
|
8
|
-
gem.homepage = 'https://github.com/
|
8
|
+
gem.homepage = 'https://github.com/ringcentral/ringcentral-ruby'
|
9
9
|
gem.license = 'MIT'
|
10
10
|
|
11
11
|
gem.require_paths = ['lib']
|
12
|
-
gem.files = %w(
|
12
|
+
gem.files = %w(README.md ringcentral-sdk.gemspec)
|
13
13
|
gem.files += Dir['lib/**/*.rb']
|
14
|
-
gem.test_files = Dir['
|
14
|
+
gem.test_files = Dir['spec/**/*.rb']
|
15
15
|
|
16
16
|
gem.add_dependency('rest-client', '~> 2.0', '>= 2.0.2')
|
17
17
|
gem.add_dependency('addressable', '~> 2.5', '>= 2.5.2')
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'ringcentral'
|
2
|
+
|
3
|
+
RSpec.describe 'RingCentral' do
|
4
|
+
describe 'ringcentral' do
|
5
|
+
it 'test_class_variables' do
|
6
|
+
expect('https://platform.devtest.ringcentral.com').to eq(RingCentral.SANDBOX_SERVER)
|
7
|
+
expect('https://platform.ringcentral.com').to eq(RingCentral.PRODUCTION_SERVER)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'test_initializer' do
|
11
|
+
rc = RingCentral.new('app_key', 'app_secret', RingCentral.SANDBOX_SERVER)
|
12
|
+
expect('app_key').to eq(rc.app_key)
|
13
|
+
expect('app_secret').to eq(rc.app_secret)
|
14
|
+
expect('https://platform.devtest.ringcentral.com').to eq(rc.server)
|
15
|
+
expect(true).to eq(rc.auto_refresh)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'test_authorize_uri' do
|
19
|
+
rc = RingCentral.new('app_key', 'app_secret', RingCentral.SANDBOX_SERVER)
|
20
|
+
expect(RingCentral.SANDBOX_SERVER + '/restapi/oauth/authorize?client_id=app_secret&redirect_uri=https%3A%2F%2Fexample.com&response_type=code&state=mystate').to eq(rc.authorize_uri('https://example.com', 'mystate'))
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'test_password_flow' do
|
24
|
+
Dotenv.load
|
25
|
+
rc = RingCentral.new(ENV['appKey'], ENV['appSecret'], ENV['server'])
|
26
|
+
expect(rc.token).to be_nil
|
27
|
+
|
28
|
+
# create token
|
29
|
+
rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
|
30
|
+
expect(rc.token).not_to be_nil
|
31
|
+
|
32
|
+
# refresh token
|
33
|
+
rc.refresh
|
34
|
+
expect(rc.token).not_to be_nil
|
35
|
+
|
36
|
+
# revoke token
|
37
|
+
rc.revoke
|
38
|
+
expect(rc.token).to be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'test_http_methods' do
|
42
|
+
Dotenv.load
|
43
|
+
rc = RingCentral.new(ENV['appKey'], ENV['appSecret'], ENV['server'])
|
44
|
+
rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
|
45
|
+
|
46
|
+
# get
|
47
|
+
r = rc.get('/restapi/v1.0/account/~/extension/~')
|
48
|
+
expect(r).not_to be_nil
|
49
|
+
expect('101').to eq(JSON.parse(r.body)['extensionNumber'])
|
50
|
+
|
51
|
+
# post
|
52
|
+
r = rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
|
53
|
+
to: [{phoneNumber: ENV['receiver']}],
|
54
|
+
from: {phoneNumber: ENV['username']},
|
55
|
+
text: 'Hello world'
|
56
|
+
})
|
57
|
+
expect(r).not_to be_nil
|
58
|
+
message = JSON.parse(r.body)
|
59
|
+
expect('SMS').to eq(message['type'])
|
60
|
+
messageUrl = "/restapi/v1.0/account/~/extension/~/message-store/#{message['id']}"
|
61
|
+
|
62
|
+
# put
|
63
|
+
r = rc.put(messageUrl, payload: { readStatus: 'Unread' })
|
64
|
+
expect(r).not_to be_nil
|
65
|
+
message = JSON.parse(r.body)
|
66
|
+
expect('Unread').to eq(message['readStatus'])
|
67
|
+
r = rc.put(messageUrl, payload: { readStatus: 'Read' })
|
68
|
+
expect(r).not_to be_nil
|
69
|
+
message = JSON.parse(r.body)
|
70
|
+
expect('Read').to eq(message['readStatus'])
|
71
|
+
|
72
|
+
# delete
|
73
|
+
r = rc.delete(messageUrl)
|
74
|
+
expect(r).not_to be_nil
|
75
|
+
r = rc.get(messageUrl)
|
76
|
+
expect(r).not_to be_nil
|
77
|
+
message = JSON.parse(r.body)
|
78
|
+
expect('Deleted').to eq(message['availability'])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'ringcentral'
|
2
|
+
require 'dotenv'
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
RSpec.describe 'Subscription' do
|
6
|
+
describe 'subscription' do
|
7
|
+
it 'receives message notification' do
|
8
|
+
Dotenv.load
|
9
|
+
rc = RingCentral.new(ENV['appKey'], ENV['appSecret'], ENV['server'])
|
10
|
+
rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
|
11
|
+
|
12
|
+
events = [
|
13
|
+
'/restapi/v1.0/account/~/extension/~/message-store',
|
14
|
+
]
|
15
|
+
count = 0
|
16
|
+
subscription = rc.subscription(events, lambda { |message|
|
17
|
+
count += 1
|
18
|
+
})
|
19
|
+
subscription.subscribe()
|
20
|
+
|
21
|
+
rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
|
22
|
+
to: [{phoneNumber: ENV['receiver']}],
|
23
|
+
from: {phoneNumber: ENV['username']},
|
24
|
+
text: 'Hello world'
|
25
|
+
})
|
26
|
+
sleep(20)
|
27
|
+
|
28
|
+
expect(count).to be > 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ringcentral-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Liu
|
@@ -98,13 +98,12 @@ extensions: []
|
|
98
98
|
extra_rdoc_files: []
|
99
99
|
files:
|
100
100
|
- README.md
|
101
|
-
- Rakefile
|
102
101
|
- lib/ringcentral.rb
|
103
102
|
- lib/subscription.rb
|
104
103
|
- ringcentral-sdk.gemspec
|
105
|
-
-
|
106
|
-
-
|
107
|
-
homepage: https://github.com/
|
104
|
+
- spec/ringcentral_spec.rb
|
105
|
+
- spec/subscription_spec.rb
|
106
|
+
homepage: https://github.com/ringcentral/ringcentral-ruby
|
108
107
|
licenses:
|
109
108
|
- MIT
|
110
109
|
metadata: {}
|
@@ -129,5 +128,5 @@ signing_key:
|
|
129
128
|
specification_version: 4
|
130
129
|
summary: RingCentral Ruby SDK.
|
131
130
|
test_files:
|
132
|
-
-
|
133
|
-
-
|
131
|
+
- spec/ringcentral_spec.rb
|
132
|
+
- spec/subscription_spec.rb
|
data/Rakefile
DELETED
data/test/test_ringcentral.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'ringcentral'
|
3
|
-
require 'dotenv'
|
4
|
-
|
5
|
-
class RingCentralTest < Test::Unit::TestCase
|
6
|
-
def test_class_variables
|
7
|
-
assert_equal 'https://platform.devtest.ringcentral.com', RingCentral.SANDBOX_SERVER
|
8
|
-
assert_equal 'https://platform.ringcentral.com', RingCentral.PRODUCTION_SERVER
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_initializer
|
12
|
-
rc = RingCentral.new('app_key', 'app_secret', RingCentral.SANDBOX_SERVER)
|
13
|
-
assert_equal 'app_key', rc.app_key
|
14
|
-
assert_equal 'app_secret', rc.app_secret
|
15
|
-
assert_equal 'https://platform.devtest.ringcentral.com', rc.server
|
16
|
-
assert_equal true, rc.auto_refresh
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_authorize_uri
|
20
|
-
rc = RingCentral.new('app_key', 'app_secret', RingCentral.SANDBOX_SERVER)
|
21
|
-
assert_equal RingCentral.SANDBOX_SERVER + '/restapi/oauth/authorize?client_id=app_secret&redirect_uri=https%3A%2F%2Fexample.com&response_type=code&state=mystate', rc.authorize_uri('https://example.com', 'mystate')
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_password_flow
|
25
|
-
Dotenv.load
|
26
|
-
rc = RingCentral.new(ENV['appKey'], ENV['appSecret'], ENV['server'])
|
27
|
-
assert_equal nil, rc.token
|
28
|
-
|
29
|
-
# create token
|
30
|
-
rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
|
31
|
-
assert_not_equal nil, rc.token
|
32
|
-
|
33
|
-
# refresh token
|
34
|
-
rc.refresh
|
35
|
-
assert_not_equal nil, rc.token
|
36
|
-
|
37
|
-
# revoke token
|
38
|
-
rc.revoke
|
39
|
-
assert_equal nil, rc.token
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_http_methods
|
43
|
-
Dotenv.load
|
44
|
-
rc = RingCentral.new(ENV['appKey'], ENV['appSecret'], ENV['server'])
|
45
|
-
rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
|
46
|
-
|
47
|
-
# get
|
48
|
-
r = rc.get('/restapi/v1.0/account/~/extension/~')
|
49
|
-
assert_not_equal nil, r
|
50
|
-
assert_equal '101', JSON.parse(r.body)['extensionNumber']
|
51
|
-
|
52
|
-
# post
|
53
|
-
r = rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
|
54
|
-
to: [{phoneNumber: ENV['receiver']}],
|
55
|
-
from: {phoneNumber: ENV['username']},
|
56
|
-
text: 'Hello world'
|
57
|
-
})
|
58
|
-
assert_not_equal nil, r
|
59
|
-
message = JSON.parse(r.body)
|
60
|
-
assert_equal 'SMS', message['type']
|
61
|
-
messageUrl = "/restapi/v1.0/account/~/extension/~/message-store/#{message['id']}"
|
62
|
-
|
63
|
-
# put
|
64
|
-
r = rc.put(messageUrl, payload: { readStatus: 'Unread' })
|
65
|
-
assert_not_equal nil, r
|
66
|
-
message = JSON.parse(r.body)
|
67
|
-
assert_equal 'Unread', message['readStatus']
|
68
|
-
r = rc.put(messageUrl, payload: { readStatus: 'Read' })
|
69
|
-
assert_not_equal nil, r
|
70
|
-
message = JSON.parse(r.body)
|
71
|
-
assert_equal 'Read', message['readStatus']
|
72
|
-
|
73
|
-
# delete
|
74
|
-
r = rc.delete(messageUrl)
|
75
|
-
assert_not_equal nil, r
|
76
|
-
r = rc.get(messageUrl)
|
77
|
-
assert_not_equal nil, r
|
78
|
-
message = JSON.parse(r.body)
|
79
|
-
assert_equal 'Deleted', message['availability']
|
80
|
-
end
|
81
|
-
end
|
data/test/test_subscription.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'ringcentral'
|
3
|
-
require 'dotenv'
|
4
|
-
|
5
|
-
class SubscriptionTest < Test::Unit::TestCase
|
6
|
-
def test_create_subscription
|
7
|
-
# Dotenv.load
|
8
|
-
# rc = RingCentral.new(ENV['appKey'], ENV['appSecret'], ENV['server'])
|
9
|
-
# rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
|
10
|
-
# events = [
|
11
|
-
# '/restapi/v1.0/account/~/extension/~/message-store',
|
12
|
-
# ]
|
13
|
-
# subscription = rc.subscription(events, ->(message) {
|
14
|
-
# puts message
|
15
|
-
# })
|
16
|
-
# subscription.subscribe()
|
17
|
-
end
|
18
|
-
end
|