ringcentral-sdk 0.9.8 → 0.9.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c148f211fd760e709cb7ecc99c2b5eec62d79095c2a9bde9e48338009709cf1a
4
- data.tar.gz: 47605bac114f39ac6b89dd9bf400fc0b7ca3c86c9712dcf25fa92349adab0f60
3
+ metadata.gz: 0c82aa5b359e0d18f0096e856d81cebb7c00990208cc210a217d49d470ee19eb
4
+ data.tar.gz: 5a4f3973076393c86fa95ea47aa7b467c0b01abd3c46fcd819a5c976ab625717
5
5
  SHA512:
6
- metadata.gz: 524b9224e4e4ebcf599fb4718eeca1bdc440842d91905edc3d306257503f06169ead91ef1f2dec0d51188a6f88053cc686546c14c152daed85baaea8c23ec19b
7
- data.tar.gz: 8a2e4a803706cf366009f8ad7aa83914cccd9bf0b79b779d5b92213b26c9cf2413a0a96285086dfdf9f2e1412a7634d9880573f59223a8a4c57dd81c3a47e4d6
6
+ metadata.gz: 1cd78622b101fbf1ef52b717af4ea587fdf98517613d9de858f432c3954e89c4c8393a16f67a43bfa29fe938d2711970200133ad9fc7362307b214d0a807f094
7
+ data.tar.gz: 9a98212a1550ee2cd269d8b935fb25115f31f9ece0609498e6a5fa2efd701107da6e3ed58a48fb266e118934e85b8ded88860529f93c13142ea2d87cb315e94b
data/README.md CHANGED
@@ -41,7 +41,7 @@ https://developer.ringcentral.com/api-docs/latest/index.html
41
41
  require 'ringcentral'
42
42
 
43
43
  rc = RingCentral.new('clientID', 'clientSecret', 'serverURL')
44
- rc.authorize(username: 'username', extension: 'extension', password: 'password')
44
+ rc.authorize(jwt: 'jwt-token')
45
45
 
46
46
  # get
47
47
  r = rc.get('/restapi/v1.0/account/~/extension/~')
@@ -98,7 +98,7 @@ rc.token = { access_token: 'the token string' }
98
98
  ```ruby
99
99
  r = rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
100
100
  to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
101
- from: {phoneNumber: ENV['RINGCENTRAL_USERNAME']},
101
+ from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
102
102
  text: 'Hello world'
103
103
  })
104
104
  ```
@@ -123,7 +123,7 @@ payload: { to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }] },
123
123
  r = rc.post('/restapi/v1.0/account/~/extension/~/sms',
124
124
  payload: {
125
125
  to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }],
126
- from: { phoneNumber: ENV['RINGCENTRAL_USERNAME'] },
126
+ from: { phoneNumber: ENV['RINGCENTRAL_SENDER'] },
127
127
  text: 'hello world'
128
128
  },
129
129
  files: [
@@ -162,17 +162,9 @@ For more sample codes, please refer to the [test cases](/spec).
162
162
  bundle install --path vendor/bundle
163
163
  ```
164
164
 
165
- Create `.env` file with the following content:
165
+ Rename `.env.sample` to `.env`.
166
166
 
167
- ```
168
- RINGCENTRAL_SERVER_URL=https://platform.devtest.ringcentral.com
169
- RINGCENTRAL_CLIENT_ID=
170
- RINGCENTRAL_CLIENT_SECRET=
171
- RINGCENTRAL_USERNAME=
172
- RINGCENTRAL_EXTENSION=
173
- RINGCENTRAL_PASSWORD=
174
- RINGCENTRAL_RECEIVER=
175
- ```
167
+ Edit `.env` file to specify credentials.
176
168
 
177
169
  `RINGCENTRAL_RECEIVER` is a phone number to receive SMS, Fax..etc.
178
170
 
data/lib/ringcentral.rb CHANGED
@@ -16,13 +16,14 @@ class RingCentral
16
16
  end
17
17
 
18
18
  attr_reader :client_id, :client_secret, :server, :token
19
- attr_accessor :auto_refresh
19
+ attr_accessor :auto_refresh, :debug_mode
20
20
 
21
- def initialize(client_id, client_secret, server)
21
+ def initialize(client_id, client_secret, server, debug_mode = false)
22
22
  @client_id = client_id
23
23
  @client_secret = client_secret
24
24
  @server = server
25
25
  @auto_refresh = false
26
+ @debug_mode = debug_mode
26
27
  @token = nil
27
28
  @timer = nil
28
29
  @faraday = Faraday.new(url: server, request: { params_encoder: Faraday::FlatParamsEncoder }) do |faraday|
@@ -91,31 +92,36 @@ class RingCentral
91
92
  self.post('/restapi/oauth/revoke', payload: payload)
92
93
  end
93
94
 
94
- def authorize_uri(redirect_uri, state = '', challenge = nil, challenge_method = 'S256')
95
+ def authorize_uri(redirect_uri, hash = {})
96
+ hash[:response_type] = 'code'
97
+ hash[:redirect_uri] = redirect_uri
98
+ hash[:client_id] = @client_id
95
99
  uri = Addressable::URI.parse(@server) + '/restapi/oauth/authorize'
96
- uri.query_values = {
97
- response_type: 'code',
98
- state: state,
99
- redirect_uri: redirect_uri,
100
- client_id: @client_id
101
- }
102
- if challenge != nil
103
- uri.query_values["code_challenge"] = challenge
104
- uri.query_values["code_challenge_method"] = challenge_method
105
- end
100
+ uri.query_values = hash
106
101
  uri.to_s
107
102
  end
108
103
 
109
104
  def get(endpoint, params = {})
110
- @faraday.get do |req|
105
+ r = @faraday.get do |req|
111
106
  req.url endpoint
112
107
  req.params = params
113
108
  req.headers = headers
114
109
  end
110
+ if @debug_mode
111
+ puts r.status, r.body
112
+ end
113
+ if r.status >= 400
114
+ raise "HTTP status #{r.status}:
115
+
116
+ headers: #{r.headers}
117
+
118
+ body: #{r.body}"
119
+ end
120
+ return r
115
121
  end
116
122
 
117
123
  def post(endpoint, payload: nil, params: {}, files: nil)
118
- @faraday.post do |req|
124
+ r = @faraday.post do |req|
119
125
  req.url endpoint
120
126
  req.params = params
121
127
  if files != nil && files.size > 0 # send fax or MMS
@@ -133,32 +139,76 @@ class RingCentral
133
139
  req.body = payload
134
140
  end
135
141
  end
142
+ if @debug_mode
143
+ puts r.status, r.body
144
+ end
145
+ if r.status >= 400
146
+ raise "HTTP status #{r.status}:
147
+
148
+ headers: #{r.headers}
149
+
150
+ body: #{r.body}"
151
+ end
152
+ return r
136
153
  end
137
154
 
138
155
  def put(endpoint, payload: nil, params: {}, files: nil)
139
- @faraday.put do |req|
156
+ r = @faraday.put do |req|
140
157
  req.url endpoint
141
158
  req.params = params
142
159
  req.headers = headers.merge({ 'Content-Type': 'application/json' })
143
160
  req.body = payload.to_json
144
161
  end
162
+ if @debug_mode
163
+ puts r.status, r.body
164
+ end
165
+ if r.status >= 400
166
+ raise "HTTP status #{r.status}:
167
+
168
+ headers: #{r.headers}
169
+
170
+ body: #{r.body}"
171
+ end
172
+ return r
145
173
  end
146
174
 
147
175
  def patch(endpoint, payload: nil, params: {}, files: nil)
148
- @faraday.patch do |req|
176
+ r = @faraday.patch do |req|
149
177
  req.url endpoint
150
178
  req.params = params
151
179
  req.headers = headers.merge({ 'Content-Type': 'application/json' })
152
180
  req.body = payload.to_json
153
181
  end
182
+ if @debug_mode
183
+ puts r.status, r.body
184
+ end
185
+ if r.status >= 400
186
+ raise "HTTP status #{r.status}:
187
+
188
+ headers: #{r.headers}
189
+
190
+ body: #{r.body}"
191
+ end
192
+ return r
154
193
  end
155
194
 
156
195
  def delete(endpoint, params = {})
157
- @faraday.delete do |req|
196
+ r = @faraday.delete do |req|
158
197
  req.url endpoint
159
198
  req.params = params
160
199
  req.headers = headers
161
200
  end
201
+ if @debug_mode
202
+ puts r.status, r.body
203
+ end
204
+ if r.status >= 400
205
+ raise "HTTP status #{r.status}:
206
+
207
+ headers: #{r.headers}
208
+
209
+ body: #{r.body}"
210
+ end
211
+ return r
162
212
  end
163
213
 
164
214
  private
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'ringcentral-sdk'
3
- gem.version = '0.9.8'
3
+ gem.version = '0.9.9'
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.'
data/spec/fax_spec.rb CHANGED
@@ -6,7 +6,7 @@ RSpec.describe 'Fax' do
6
6
  it 'should send a fax' do
7
7
  Dotenv.load
8
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'])
9
+ rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
10
10
  r = rc.post('/restapi/v1.0/account/~/extension/~/fax',
11
11
  payload: { to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }] },
12
12
  files: [
data/spec/mms_spec.rb CHANGED
@@ -6,12 +6,12 @@ RSpec.describe 'MMS' do
6
6
  it 'should send an MMS' do
7
7
  Dotenv.load
8
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'])
9
+ rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
10
10
 
11
11
  r = rc.post('/restapi/v1.0/account/~/extension/~/sms',
12
12
  payload: {
13
13
  to: [{ phoneNumber: ENV['RINGCENTRAL_RECEIVER'] }],
14
- from: { phoneNumber: ENV['RINGCENTRAL_USERNAME'] },
14
+ from: { phoneNumber: ENV['RINGCENTRAL_SENDER'] },
15
15
  text: 'hello world'
16
16
  },
17
17
  files: [
@@ -6,7 +6,7 @@ RSpec.describe 'query params' do
6
6
  it 'contain single query param' do
7
7
  Dotenv.load
8
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'])
9
+ rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
10
10
  r = rc.get('/restapi/v1.0/account/~/extension/~/address-book/contact', { phoneNumber: '666' })
11
11
  expect(r).not_to be_nil
12
12
  message = r.body
@@ -17,16 +17,16 @@ RSpec.describe 'RingCentral' do
17
17
 
18
18
  it 'test_authorize_uri' do
19
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'))
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', {state: 'mystate'}))
21
21
  end
22
22
 
23
- it 'test_password_flow' do
23
+ it 'test_jwt_flow' do
24
24
  Dotenv.load
25
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['RINGCENTRAL_USERNAME'], extension: ENV['RINGCENTRAL_EXTENSION'], password: ENV['RINGCENTRAL_PASSWORD'])
29
+ rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
30
30
  expect(rc.token).not_to be_nil
31
31
 
32
32
  # refresh token
@@ -41,7 +41,7 @@ RSpec.describe 'RingCentral' do
41
41
  it 'test_http_methods' do
42
42
  Dotenv.load
43
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'])
44
+ rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
45
45
 
46
46
  # get
47
47
  r = rc.get('/restapi/v1.0/account/~/extension/~')
@@ -51,7 +51,7 @@ RSpec.describe 'RingCentral' do
51
51
  # post
52
52
  r = rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
53
53
  to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
54
- from: {phoneNumber: ENV['RINGCENTRAL_USERNAME']},
54
+ from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
55
55
  text: 'Hello world'
56
56
  })
57
57
  expect(r).not_to be_nil
@@ -5,7 +5,7 @@ require 'rspec'
5
5
 
6
6
  Dotenv.load
7
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'])
8
+
9
9
 
10
10
  def createSubscription(callback)
11
11
  events = [
@@ -21,6 +21,7 @@ end
21
21
  RSpec.describe 'Subscription' do
22
22
  describe 'subscription' do
23
23
  it 'receives message notification' do
24
+ $rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
24
25
  count = 0
25
26
  createSubscription(lambda { |message|
26
27
  count += 1
@@ -28,15 +29,17 @@ RSpec.describe 'Subscription' do
28
29
 
29
30
  $rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
30
31
  to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
31
- from: {phoneNumber: ENV['RINGCENTRAL_USERNAME']},
32
+ from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
32
33
  text: 'Hello world'
33
34
  })
34
35
  sleep(20)
35
36
 
36
37
  expect(count).to be > 0
38
+ $rc.revoke()
37
39
  end
38
40
 
39
41
  it 'refresh' do
42
+ $rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
40
43
  count = 0
41
44
  subscription = createSubscription(lambda { |message|
42
45
  count += 1
@@ -46,15 +49,17 @@ RSpec.describe 'Subscription' do
46
49
 
47
50
  $rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
48
51
  to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
49
- from: {phoneNumber: ENV['RINGCENTRAL_USERNAME']},
52
+ from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
50
53
  text: 'Hello world'
51
54
  })
52
55
  sleep(20)
53
56
 
54
57
  expect(count).to be > 0
58
+ $rc.revoke()
55
59
  end
56
60
 
57
61
  it 'revoke' do
62
+ $rc.authorize(jwt: ENV['RINGCENTRAL_JWT_TOKEN'])
58
63
  count = 0
59
64
  subscription = createSubscription(lambda { |message|
60
65
  count += 1
@@ -64,12 +69,13 @@ RSpec.describe 'Subscription' do
64
69
 
65
70
  $rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
66
71
  to: [{phoneNumber: ENV['RINGCENTRAL_RECEIVER']}],
67
- from: {phoneNumber: ENV['RINGCENTRAL_USERNAME']},
72
+ from: {phoneNumber: ENV['RINGCENTRAL_SENDER']},
68
73
  text: 'Hello world'
69
74
  })
70
75
  sleep(20)
71
76
 
72
77
  expect(count).to eq(0)
78
+ $rc.revoke()
73
79
  end
74
80
  end
75
81
  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.9.8
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Liu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-03 00:00:00.000000000 Z
11
+ date: 2023-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.2.3
148
+ rubygems_version: 3.4.10
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: RingCentral Ruby SDK.