ringcentral-sdk 0.8.2 → 0.9.0

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
- SHA1:
3
- metadata.gz: d48fd9aeb0ce08172f73e2922121f31713cbd626
4
- data.tar.gz: 5ae74b326aed1c61ba8a98745174a3a7d19eb2dc
2
+ SHA256:
3
+ metadata.gz: 06ddfd78c12b59f0671d7e1972591f42b0c8ec3f840e99ae99ae4c91aa729640
4
+ data.tar.gz: 8f9db936652f2e3f26617d82d2384e7f70f34545c4cfb46ce0b92279d5f3d6f4
5
5
  SHA512:
6
- metadata.gz: d2cfe606abaa3f47c4b1b745f15eb1ce7bc2f00258ccf31aca1ab16210aba4de87488df119646eee6b6183bf19bf18ade336fd626e5125606eed2c716b4e260d
7
- data.tar.gz: e669a6ba874cf06b7190300fdeb6b23102d820801370644470619c8d1d73e1b6591370465e56eb3d54e958d4d887682952aee99bedc697ce25925cb9770cdef5
6
+ metadata.gz: 1949bd7acb065a8bff3414deca51cbb466f3f68bd75a956079aed13ebba9721b395a1282e84c6f7b4de7157eb00cb1eee3d53ca2c37167e435e3e598b0370e6a
7
+ data.tar.gz: 8a45c38e893069f78000d3a3dba132257cd7f6626fddb803fd0fd640ff784d8962ecc05035e92cf1cca0e124622fa13f7c5422af10a0774bc6bb3d13c8a05cde
data/README.md CHANGED
@@ -13,6 +13,15 @@ gem install ringcentral-sdk
13
13
  ```
14
14
 
15
15
 
16
+ ### Name collision with `ringcentral` gem
17
+
18
+ The ringcentral gem is using RingCentral's legacy API, everyone is recommended to move to the REST API.
19
+
20
+ If you have both the ringcentral and ringcentral-sdk gems installed, you will run into a collision error when attempting to initialize the ringcentral-sdk RingCentral SDK.
21
+
22
+ Solution is `gem uninstall ringcentral`
23
+
24
+
16
25
  ## Documentation
17
26
 
18
27
  https://developer.ringcentral.com/api-docs/latest/index.html
@@ -23,19 +32,19 @@ https://developer.ringcentral.com/api-docs/latest/index.html
23
32
  ```ruby
24
33
  require 'ringcentral'
25
34
 
26
- rc = RingCentral.new(ENV['clientId'], ENV['clientSecret'], ENV['server'])
27
- rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
35
+ rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
36
+ rc.authorize(username: ENV['RINGCENTRAL_USERNAME'], extension: ENV['RINGCENTRAL_EXTENSION'], password: ENV['RINGCENTRAL_PASSWORD'])
28
37
 
29
38
  # get
30
39
  r = rc.get('/restapi/v1.0/account/~/extension/~')
31
40
  expect(r).not_to be_nil
32
- expect('101').to eq(JSON.parse(r.body)['extensionNumber'])
41
+ expect('101').to eq(r.body['extensionNumber'])
33
42
  ```
34
43
 
35
44
 
36
45
  ### Token Refresh
37
46
 
38
- Access token expires. You need to call `rc.refresh()` before it expores.
47
+ Access token expires. You need to call `rc.refresh()` before it expires.
39
48
  If you want the SDK to do auto refresh please `rc.auto_refresh = true` before authorization.
40
49
 
41
50
 
@@ -43,8 +52,8 @@ If you want the SDK to do auto refresh please `rc.auto_refresh = true` before au
43
52
 
44
53
  ```ruby
45
54
  r = rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
46
- to: [{phoneNumber: ENV['receiver']}],
47
- from: {phoneNumber: ENV['username']},
55
+ to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
56
+ from: {phoneNumber: ENV['RINGCENTRAL_USERNAME']},
48
57
  text: 'Hello world'
49
58
  })
50
59
  ```
@@ -54,7 +63,7 @@ r = rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
54
63
 
55
64
  ```ruby
56
65
  rc.post('/restapi/v1.0/account/~/extension/~/fax',
57
- payload: { to: [{ phoneNumber: ENV['receiver'] }] },
66
+ payload: { to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }] },
58
67
  files: [
59
68
  ['spec/test.txt', 'text/plain'],
60
69
  ['spec/test.png', 'image/png']
@@ -68,8 +77,8 @@ payload: { to: [{ phoneNumber: ENV['receiver'] }] },
68
77
  ```ruby
69
78
  r = rc.post('/restapi/v1.0/account/~/extension/~/sms',
70
79
  payload: {
71
- to: [{ phoneNumber: ENV['receiver'] }],
72
- from: { phoneNumber: ENV['username'] },
80
+ to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }],
81
+ from: { phoneNumber: ENV['RINGCENTRAL_USERNAME'] },
73
82
  text: 'hello world'
74
83
  },
75
84
  files: [
@@ -107,16 +116,17 @@ For more sample code, please refer to the [test cases](/spec).
107
116
  Create `.env` file with the following content:
108
117
 
109
118
  ```
110
- production=false
111
- server=https://platform.devtest.ringcentral.com
112
- clientId=clientId
113
- clientSecret=clientSecret
114
- username=username
115
- extension=extension
116
- password=password
117
- receiver=number-to-receiver-sms
119
+ RINGCENTRAL_SERVER_URL=https://platform.devtest.ringcentral.com
120
+ RINGCENTRAL_CLIENT_ID=
121
+ RINGCENTRAL_CLIENT_SECRET=
122
+ RINGCENTRAL_USERNAME=
123
+ RINGCENTRAL_EXTENSION=
124
+ RINGCENTRAL_PASSWORD=
125
+ RINGCENTRAL_RECEIVER=
118
126
  ```
119
127
 
128
+ `RINGCENTRAL_RECEIVER` is a phone number to receive SMS, Fax..etc.
129
+
120
130
  Run `rspec`
121
131
 
122
132
 
@@ -3,6 +3,7 @@ require 'addressable/uri'
3
3
  require 'json'
4
4
  require 'concurrent'
5
5
  require 'faraday'
6
+ require 'faraday_middleware'
6
7
  require 'tmpdir'
7
8
 
8
9
  class RingCentral
@@ -14,12 +15,12 @@ class RingCentral
14
15
  'https://platform.ringcentral.com'
15
16
  end
16
17
 
17
- attr_reader :app_key, :app_secret, :server, :token
18
+ attr_reader :client_id, :client_secret, :server, :token
18
19
  attr_accessor :auto_refresh
19
20
 
20
- def initialize(app_key, app_secret, server)
21
- @app_key = app_key
22
- @app_secret = app_secret
21
+ def initialize(client_id, client_secret, server)
22
+ @client_id = client_id
23
+ @client_secret = client_secret
23
24
  @server = server
24
25
  @auto_refresh = false
25
26
  @token = nil
@@ -27,6 +28,7 @@ class RingCentral
27
28
  @faraday = Faraday.new(url: server) do |faraday|
28
29
  faraday.request :multipart
29
30
  faraday.request :url_encoded
31
+ faraday.response :json, :content_type => /\bjson$/
30
32
  faraday.adapter Faraday.default_adapter
31
33
  end
32
34
  end
@@ -60,7 +62,7 @@ class RingCentral
60
62
  end
61
63
  self.token = nil
62
64
  r = self.post('/restapi/oauth/token', payload: payload)
63
- self.token = JSON.parse(r.body)
65
+ self.token = r.body
64
66
  end
65
67
 
66
68
  def refresh
@@ -71,7 +73,7 @@ class RingCentral
71
73
  }
72
74
  self.token = nil
73
75
  r = self.post('/restapi/oauth/token', payload: payload)
74
- self.token = JSON.parse(r.body)
76
+ self.token = r.body
75
77
  end
76
78
 
77
79
  def revoke
@@ -87,7 +89,7 @@ class RingCentral
87
89
  response_type: 'code',
88
90
  state: state,
89
91
  redirect_uri: redirect_uri,
90
- client_id: @app_key
92
+ client_id: @client_id
91
93
  }
92
94
  uri.to_s
93
95
  end
@@ -150,7 +152,7 @@ class RingCentral
150
152
  private
151
153
 
152
154
  def basic_key
153
- Base64.encode64("#{@app_key}:#{@app_secret}").gsub(/\s/, '')
155
+ Base64.encode64("#{@client_id}:#{@client_secret}").gsub(/\s/, '')
154
156
  end
155
157
 
156
158
  def autorization_header
@@ -47,7 +47,7 @@ class PubNub
47
47
 
48
48
  def subscribe
49
49
  r = @rc.post('/restapi/v1.0/subscription', payload: request_body)
50
- self.subscription = JSON.parse(r.body)
50
+ self.subscription = r.body
51
51
  @pubnub = Pubnub.new(subscribe_key: @subscription['deliveryMode']['subscriberKey'])
52
52
  @pubnub.add_listener(name: 'default', callback: @callback)
53
53
  @pubnub.subscribe(channels: @subscription['deliveryMode']['address'])
@@ -56,7 +56,7 @@ class PubNub
56
56
  def refresh
57
57
  return if @subscription == nil
58
58
  r = @rc.put("/restapi/v1.0/subscription/#{@subscription['id']}", payload: request_body)
59
- self.subscription = JSON.parse(r.body)
59
+ self.subscription = r.body
60
60
  end
61
61
 
62
62
  def revoke
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'ringcentral-sdk'
3
- gem.version = '0.8.2'
3
+ gem.version = '0.9.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.'
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
17
17
  gem.add_dependency('concurrent-ruby', '~> 1.0', '>= 1.0.2')
18
18
  gem.add_dependency('pubnub', '~> 4.0', '>= 4.0.27')
19
19
  gem.add_dependency('faraday', '~> 0.10', '>= 0.10.0')
20
+ gem.add_dependency('faraday_middleware', '~> 0.12', '>= 0.12.2')
20
21
  end
@@ -5,17 +5,17 @@ RSpec.describe 'Fax' do
5
5
  describe 'send fax' do
6
6
  it 'should send a fax' do
7
7
  Dotenv.load
8
- rc = RingCentral.new(ENV['clientId'], ENV['clientSecret'], ENV['server'])
9
- rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
8
+ rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
9
+ rc.authorize(username: ENV['RINGCENTRAL_USERNAME'], extension: ENV['RINGCENTRAL_EXTENSION'], password: ENV['RINGCENTRAL_PASSWORD'])
10
10
  r = rc.post('/restapi/v1.0/account/~/extension/~/fax',
11
- payload: { to: [{ phoneNumber: ENV['receiver'] }] },
11
+ payload: { to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }] },
12
12
  files: [
13
13
  ['spec/test.txt', 'text/plain'],
14
14
  ['spec/test.png', 'image/png']
15
15
  ]
16
16
  )
17
17
  expect(r).not_to be_nil
18
- message = JSON.parse(r.body)
18
+ message = r.body
19
19
  expect('Fax').to eq(message['type'])
20
20
  end
21
21
  end
@@ -5,13 +5,13 @@ RSpec.describe 'MMS' do
5
5
  describe 'send MMS' do
6
6
  it 'should send an MMS' do
7
7
  Dotenv.load
8
- rc = RingCentral.new(ENV['clientId'], ENV['clientSecret'], ENV['server'])
9
- rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
8
+ rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
9
+ rc.authorize(username: ENV['RINGCENTRAL_USERNAME'], extension: ENV['RINGCENTRAL_EXTENSION'], password: ENV['RINGCENTRAL_PASSWORD'])
10
10
 
11
11
  r = rc.post('/restapi/v1.0/account/~/extension/~/sms',
12
12
  payload: {
13
- to: [{ phoneNumber: ENV['receiver'] }],
14
- from: { phoneNumber: ENV['username'] },
13
+ to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }],
14
+ from: { phoneNumber: ENV['RINGCENTRAL_USERNAME'] },
15
15
  text: 'hello world'
16
16
  },
17
17
  files: [
@@ -19,7 +19,7 @@ RSpec.describe 'MMS' do
19
19
  ]
20
20
  )
21
21
  expect(r).not_to be_nil
22
- message = JSON.parse(r.body)
22
+ message = r.body
23
23
  expect('SMS').to eq(message['type'])
24
24
  end
25
25
  end
@@ -8,25 +8,25 @@ RSpec.describe 'RingCentral' do
8
8
  end
9
9
 
10
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)
11
+ rc = RingCentral.new('client_id', 'client_secret', RingCentral.SANDBOX_SERVER)
12
+ expect('client_id').to eq(rc.client_id)
13
+ expect('client_secret').to eq(rc.client_secret)
14
14
  expect('https://platform.devtest.ringcentral.com').to eq(rc.server)
15
15
  expect(false).to eq(rc.auto_refresh)
16
16
  end
17
17
 
18
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_key&redirect_uri=https%3A%2F%2Fexample.com&response_type=code&state=mystate').to eq(rc.authorize_uri('https://example.com', 'mystate'))
19
+ rc = RingCentral.new('client_id', 'client_secret', RingCentral.SANDBOX_SERVER)
20
+ expect(RingCentral.SANDBOX_SERVER + '/restapi/oauth/authorize?client_id=client_id&redirect_uri=https%3A%2F%2Fexample.com&response_type=code&state=mystate').to eq(rc.authorize_uri('https://example.com', 'mystate'))
21
21
  end
22
22
 
23
23
  it 'test_password_flow' do
24
24
  Dotenv.load
25
- rc = RingCentral.new(ENV['clientId'], ENV['clientSecret'], ENV['server'])
25
+ rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
26
26
  expect(rc.token).to be_nil
27
27
 
28
28
  # create token
29
- rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
29
+ rc.authorize(username: ENV['RINGCENTRAL_USERNAME'], extension: ENV['RINGCENTRAL_EXTENSION'], password: ENV['RINGCENTRAL_PASSWORD'])
30
30
  expect(rc.token).not_to be_nil
31
31
 
32
32
  # refresh token
@@ -40,33 +40,33 @@ RSpec.describe 'RingCentral' do
40
40
 
41
41
  it 'test_http_methods' do
42
42
  Dotenv.load
43
- rc = RingCentral.new(ENV['clientId'], ENV['clientSecret'], ENV['server'])
44
- rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
43
+ rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
44
+ rc.authorize(username: ENV['RINGCENTRAL_USERNAME'], extension: ENV['RINGCENTRAL_EXTENSION'], password: ENV['RINGCENTRAL_PASSWORD'])
45
45
 
46
46
  # get
47
47
  r = rc.get('/restapi/v1.0/account/~/extension/~')
48
48
  expect(r).not_to be_nil
49
- expect('101').to eq(JSON.parse(r.body)['extensionNumber'])
49
+ expect('101').to eq(r.body['extensionNumber'])
50
50
 
51
51
  # post
52
52
  r = rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
53
- to: [{phoneNumber: ENV['receiver']}],
54
- from: {phoneNumber: ENV['username']},
53
+ to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
54
+ from: {phoneNumber: ENV['RINGCENTRAL_USERNAME']},
55
55
  text: 'Hello world'
56
56
  })
57
57
  expect(r).not_to be_nil
58
- message = JSON.parse(r.body)
58
+ message = r.body
59
59
  expect('SMS').to eq(message['type'])
60
60
  messageUrl = "/restapi/v1.0/account/~/extension/~/message-store/#{message['id']}"
61
61
 
62
62
  # put
63
63
  r = rc.put(messageUrl, payload: { readStatus: 'Unread' })
64
64
  expect(r).not_to be_nil
65
- message = JSON.parse(r.body)
65
+ message = r.body
66
66
  expect('Unread').to eq(message['readStatus'])
67
67
  r = rc.put(messageUrl, payload: { readStatus: 'Read' })
68
68
  expect(r).not_to be_nil
69
- message = JSON.parse(r.body)
69
+ message = r.body
70
70
  expect('Read').to eq(message['readStatus'])
71
71
 
72
72
  # todo: test patch
@@ -76,7 +76,7 @@ RSpec.describe 'RingCentral' do
76
76
  expect(r).not_to be_nil
77
77
  r = rc.get(messageUrl)
78
78
  expect(r).not_to be_nil
79
- message = JSON.parse(r.body)
79
+ message = r.body
80
80
  expect('Deleted').to eq(message['availability'])
81
81
  end
82
82
  end
@@ -4,8 +4,8 @@ require 'dotenv'
4
4
  require 'rspec'
5
5
 
6
6
  Dotenv.load
7
- $rc = RingCentral.new(ENV['clientId'], ENV['clientSecret'], ENV['server'])
8
- $rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
7
+ $rc = RingCentral.new(ENV['RINGCENTRAL_CLIENT_ID'], ENV['RINGCENTRAL_CLIENT_SECRET'], ENV['RINGCENTRAL_SERVER_URL'])
8
+ $rc.authorize(username: ENV['RINGCENTRAL_USERNAME'], extension: ENV['RINGCENTRAL_EXTENSION'], password: ENV['RINGCENTRAL_PASSWORD'])
9
9
 
10
10
  def createSubscription(callback)
11
11
  events = [
@@ -27,8 +27,8 @@ RSpec.describe 'Subscription' do
27
27
  })
28
28
 
29
29
  $rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
30
- to: [{phoneNumber: ENV['receiver']}],
31
- from: {phoneNumber: ENV['username']},
30
+ to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
31
+ from: {phoneNumber: ENV['RINGCENTRAL_USERNAME']},
32
32
  text: 'Hello world'
33
33
  })
34
34
  sleep(20)
@@ -45,8 +45,8 @@ RSpec.describe 'Subscription' do
45
45
  subscription.refresh()
46
46
 
47
47
  $rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
48
- to: [{phoneNumber: ENV['receiver']}],
49
- from: {phoneNumber: ENV['username']},
48
+ to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
49
+ from: {phoneNumber: ENV['RINGCENTRAL_USERNAME']},
50
50
  text: 'Hello world'
51
51
  })
52
52
  sleep(20)
@@ -63,8 +63,8 @@ RSpec.describe 'Subscription' do
63
63
  subscription.revoke()
64
64
 
65
65
  $rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
66
- to: [{phoneNumber: ENV['receiver']}],
67
- from: {phoneNumber: ENV['username']},
66
+ to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
67
+ from: {phoneNumber: ENV['RINGCENTRAL_USERNAME']},
68
68
  text: 'Hello world'
69
69
  })
70
70
  sleep(20)
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.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Liu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-16 00:00:00.000000000 Z
11
+ date: 2018-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -90,6 +90,26 @@ dependencies:
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
92
  version: 0.10.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: faraday_middleware
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '0.12'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 0.12.2
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.12'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 0.12.2
93
113
  description: Ruby SDK for you to access RingCentral platform API.
94
114
  email:
95
115
  - tyler.liu@ringcentral.com
@@ -126,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
146
  version: '0'
127
147
  requirements: []
128
148
  rubyforge_project:
129
- rubygems_version: 2.5.1
149
+ rubygems_version: 2.7.6
130
150
  signing_key:
131
151
  specification_version: 4
132
152
  summary: RingCentral Ruby SDK.