ringcentral_sdk 0.5.0 → 0.5.1

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
2
  SHA1:
3
- metadata.gz: 1f9dcd84f1f05d75c88713e2670ef117ff10fbbc
4
- data.tar.gz: 592200667132fc64debd755707acb7b89e820926
3
+ metadata.gz: e6ac4e79b4c9626cf8b931e0cf4776ac22d08909
4
+ data.tar.gz: 95084e7e2cd40c0567b13d53ae32d56baaeb9ef8
5
5
  SHA512:
6
- metadata.gz: fdb5b49fd8ee320bf2309e976a106f4d721251e5b355b523c358394e6341ea50e6f8e5b869b40988efff9bba687a1b3a66860c132eaa782f7c5c2631a021a2f3
7
- data.tar.gz: 0d84fb441b6be1b14fd92c6a164856ec3b80a6762c822bf8dad71adc7c8e5207f463124b40997d78f9ddf0704eaee17dfdc25d2ac1ac2645489e1b917031d5df
6
+ metadata.gz: 21c8a0f4d2c62ce147805ff28a0eaaaa7e4417a0e1864a04ccf86e7dacc1b6e30bd61188c2b5909c70cdedac713180d28bcb9bdd5f7cb2caaab29cfd493f7c83
7
+ data.tar.gz: e841e5c7960967dff3c008b1fb4f31e7568f8126444bd87467e9ab36afe020eca135947f9b3a14dd174e565e8066d129390b5b55ea136b1bdde4517e9fffa763
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  CHANGELOG
2
2
  ---------
3
+ - **2015-12-08**: 0.5.1
4
+ - Add call recording transcription demo script via VoiceBase
5
+ - Fix PubNub unsubscribe bug
6
+ - Fix fax helper to support UTF-8 metadata with file attachment
7
+ - Update tests to support access token without refresh token
8
+ - Update sample scripts credentials file format to be more scalable
3
9
  - **2015-10-18**: 0.5.0
4
10
  - Add stubbed tests via `mocha`
5
11
  - Add `RingCentralSdk.new()` sugar method
@@ -48,4 +54,4 @@ CHANGELOG
48
54
  - **2015-03-08**: 0.0.2
49
55
  - Convert methods from camelCase to under_scores
50
56
  - **2015-03-07**: 0.0.1
51
- - Initial release
57
+ - Initial release
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  RingCentral SDK for Ruby
2
2
  ========================
3
3
 
4
- [![Gem Version](https://badge.fury.io/rb/ringcentral_sdk.svg)](http://badge.fury.io/rb/ringcentral_sdk)
5
- [![Build Status](https://img.shields.io/travis/grokify/ringcentral-sdk-ruby/master.svg)](https://travis-ci.org/grokify/ringcentral-sdk-ruby)
6
- [![Coverage Status](https://coveralls.io/repos/grokify/ringcentral-sdk-ruby/badge.svg?branch=master)](https://coveralls.io/r/grokify/ringcentral-sdk-ruby?branch=master)
7
- [![Dependency Status](https://gemnasium.com/grokify/ringcentral-sdk-ruby.svg)](https://gemnasium.com/grokify/ringcentral-sdk-ruby)
8
- [![Code Climate](https://codeclimate.com/github/grokify/ringcentral-sdk-ruby/badges/gpa.svg)](https://codeclimate.com/github/grokify/ringcentral-sdk-ruby)
9
- [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/grokify/ringcentral-sdk-ruby/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/grokify/ringcentral-sdk-ruby/?branch=master)
10
- [![Docs](https://img.shields.io/badge/docs-readthedocs-blue.svg)](http://ringcentral-sdk-ruby.readthedocs.org/)
11
- [![Docs](https://img.shields.io/badge/docs-rubydoc-blue.svg)](http://www.rubydoc.info/gems/ringcentral_sdk/)
12
- [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/grokify/ringcentral-sdk-ruby/master/LICENSE.txt)
4
+ [![Gem Version][gem-version-svg]][gem-version-link]
5
+ [![Build Status][build-status-svg]][build-status-link]
6
+ [![Coverage Status][coverage-status-svg]][coverage-status-link]
7
+ [![Dependency Status][dependency-status-svg]][dependency-status-link]
8
+ [![Code Climate][codeclimate-status-svg]][codeclimate-status-link]
9
+ [![Scrutinizer Code Quality][scrutinizer-status-svg]][scrutinizer-status-link]
10
+ [![Docs][docs-readthedocs-svg]][docs-readthedocs-link]
11
+ [![Docs][docs-rubydoc-svg]][docs-rubydoc-link]
12
+ [![License][license-svg]][license-link]
13
13
 
14
14
  ## Table of contents
15
15
 
@@ -29,8 +29,9 @@ RingCentral SDK for Ruby
29
29
  3. [Fax Example](#fax-example)
30
30
  1. [Subscriptions](#subscriptions)
31
31
  5. [Supported Ruby Versions](#supported-ruby-versions)
32
- 6. [Versioning](#versioning)
33
- 7. [Change Log](#change-log)
32
+ 6. [Releases](#releases)
33
+ 1. [Versioning](#versioning)
34
+ 1. [Change Log](#change-log)
34
35
  8. [Links](#links)
35
36
  9. [Contributions](#contributions)
36
37
  10. [License](#license)
@@ -284,10 +285,7 @@ end
284
285
  To make subscriptions with RingCentral, use the SDK object to create subscription Observer object and then add observers to it.
285
286
 
286
287
  ```ruby
287
- sub = rcsdk.create_subscription()
288
-
289
- sub.subscribe(['/restapi/v1.0/account/~/extension/~/presence'])
290
-
288
+ # Create an observer object
291
289
  class MyObserver
292
290
  def update(message)
293
291
  puts "Subscription Message Received"
@@ -295,9 +293,13 @@ class MyObserver
295
293
  end
296
294
  end
297
295
 
296
+ # Create an observable subscription and add your observer
297
+ sub = rcsdk.create_subscription()
298
+ sub.subscribe(['/restapi/v1.0/account/~/extension/~/presence'])
298
299
  sub.add_observer(MyObserver.new())
299
300
 
300
- sub.destroy() # end the subscription
301
+ # End the subscription
302
+ sub.destroy()
301
303
  ```
302
304
 
303
305
  ## Supported Ruby Versions
@@ -313,13 +315,17 @@ This library supports and is [tested against](https://travis-ci.org/grokify/ring
313
315
 
314
316
  Note: Ruby 1.8.7 works except for subscription support which relies on the `pubnub` gem. If there is a need for 1.8.7 support, consider creating a GitHub issue so we can evalute creating a separate library for subscription handling.
315
317
 
316
- ## Versioning
318
+ ## Releases
319
+
320
+ Releases with release notes are availabe on [GitHub releases](https://github.com/grokify/ringcentral-sdk-ruby/releases). Release notes include a high level description of the release as well as lists of non-breaking and breaking changes.
321
+
322
+ ### Versioning
317
323
 
318
324
  This project is currently in development and the API can change. During initial development (Version 0.x.x), minor version changes will indicate either substantial feature inclusion or breaking changes.
319
325
 
320
326
  Once the project is version 1.0.0 or above, it will use [semantic versioning](http://semver.org/). At this time, breaking changes will be indicated by a change in major version.
321
327
 
322
- ## Change Log
328
+ ### Change Log
323
329
 
324
330
  See [CHANGELOG.md](CHANGELOG.md)
325
331
 
@@ -352,3 +358,22 @@ Please report these on [Github](https://github.com/grokify/ringcentral-sdk-ruby)
352
358
  RingCentral SDK is available under an MIT-style license. See [LICENSE.txt](LICENSE.txt) for details.
353
359
 
354
360
  RingCentral SDK © 2015 by John Wang
361
+
362
+ [gem-version-svg]: https://badge.fury.io/rb/ringcentral_sdk.svg
363
+ [gem-version-link]: http://badge.fury.io/rb/ringcentral_sdk
364
+ [build-status-svg]: https://api.travis-ci.org/grokify/ringcentral-sdk-ruby.svg?branch=master
365
+ [build-status-link]: https://travis-ci.org/grokify/ringcentral-sdk-ruby
366
+ [coverage-status-svg]: https://coveralls.io/repos/grokify/ringcentral-sdk-ruby/badge.svg?branch=master
367
+ [coverage-status-link]: https://coveralls.io/r/grokify/ringcentral-sdk-ruby?branch=master
368
+ [dependency-status-svg]: https://gemnasium.com/grokify/ringcentral-sdk-ruby.svg
369
+ [dependency-status-link]: https://gemnasium.com/grokify/ringcentral-sdk-ruby
370
+ [codeclimate-status-svg]: https://codeclimate.com/github/grokify/ringcentral-sdk-ruby/badges/gpa.svg
371
+ [codeclimate-status-link]: https://codeclimate.com/github/grokify/ringcentral-sdk-ruby
372
+ [scrutinizer-status-svg]: https://scrutinizer-ci.com/g/grokify/ringcentral-sdk-ruby/badges/quality-score.png?b=master
373
+ [scrutinizer-status-link]: https://scrutinizer-ci.com/g/grokify/ringcentral-sdk-ruby/?branch=master
374
+ [docs-readthedocs-svg]: https://img.shields.io/badge/docs-readthedocs-blue.svg
375
+ [docs-readthedocs-link]: http://ringcentral-sdk-ruby.readthedocs.org/
376
+ [docs-rubydoc-svg]: https://img.shields.io/badge/docs-rubydoc-blue.svg
377
+ [docs-rubydoc-link]: http://www.rubydoc.info/gems/ringcentral_sdk/
378
+ [license-svg]: https://img.shields.io/badge/license-MIT-blue.svg
379
+ [license-link]: https://github.com/grokify/ringcentral-sdk-ruby/blob/master/LICENSE.txt
@@ -1,16 +1,17 @@
1
1
  module RingCentralSdk
2
2
 
3
- VERSION = '0.5.0'
3
+ VERSION = '0.5.1'
4
4
 
5
5
  RC_SERVER_PRODUCTION = 'https://platform.ringcentral.com'
6
6
  RC_SERVER_SANDBOX = 'https://platform.devtest.ringcentral.com'
7
7
 
8
8
  autoload :Helpers, 'ringcentral_sdk/helpers'
9
9
  autoload :Platform, 'ringcentral_sdk/platform'
10
+ autoload :Simple, 'ringcentral_sdk/simple'
10
11
  autoload :Subscription, 'ringcentral_sdk/subscription'
11
12
 
12
13
  class << self
13
- def new(app_key, app_secret, server_url=nil, opts={})
14
+ def new(app_key, app_secret, server_url=RC_SERVER_SANDBOX, opts={})
14
15
  RingCentralSdk::Platform.new(app_key, app_secret, server_url, opts)
15
16
  end
16
17
  end
@@ -28,11 +28,14 @@ module RingCentralSdk::Helpers
28
28
  end
29
29
 
30
30
  def add_metadata(meta=nil)
31
+ base64_encode = true
31
32
  meta = inflate_metadata(meta)
32
33
  json = MultiJson.encode(meta)
34
+ json = Base64.encode64(json) if base64_encode
33
35
  json_part = MIME::Text.new(json)
34
36
  json_part.headers.delete('Content-Id')
35
- json_part.headers.set('Content-Type','application/json')
37
+ json_part.headers.set('Content-Type', 'application/json')
38
+ json_part.headers.set('Content-Transfer-Encoding', 'base64') if base64_encode
36
39
  @msg.add(json_part)
37
40
  return true
38
41
  end
@@ -157,7 +157,7 @@ module RingCentralSdk
157
157
  return api_key
158
158
  end
159
159
 
160
- def request(helper=nil)
160
+ def send_request(helper=nil)
161
161
  unless helper.is_a?(RingCentralSdk::Helpers::Request)
162
162
  raise 'Request is not a RingCentralSdk::Helpers::Request'
163
163
  end
@@ -187,6 +187,7 @@ module RingCentralSdk
187
187
 
188
188
  alias_method :authorize, :authorize_password
189
189
  alias_method :login, :authorize_password
190
+ alias_method :request, :send_request
190
191
  private :get_api_version_url
191
192
  end
192
193
  end
@@ -0,0 +1,88 @@
1
+ module RingCentralSdk
2
+ class Simple
3
+ attr_accessor :rcsdk
4
+
5
+ def initialize(rcsdk)
6
+ @rcsdk = rcsdk
7
+ end
8
+
9
+ def send(request)
10
+ if request.is_a?(RingCentralSdk::Helpers::Request)
11
+ return @rcsdk.request(request)
12
+ elsif ! request.is_a?(Hash)
13
+ raise "Request is not a RingCentralSdk::Helpers::Request or Hash"
14
+ end
15
+
16
+ verb = request.has_key?(:verb) ? request[:verb].to_s.downcase : 'get'
17
+
18
+ if verb == 'get'
19
+ return get(request)
20
+ elsif verb == 'post'
21
+ return post(request)
22
+ elsif verb == 'put'
23
+ return put(request)
24
+ elsif verb == 'delete'
25
+ return delete(request)
26
+ else
27
+ raise 'Method not supported'
28
+ end
29
+ end
30
+
31
+ def delete(opts={})
32
+ return @rcsdk.client.delete do |req|
33
+ req.url build_url(opts[:path])
34
+ end
35
+ end
36
+
37
+ def get(opts={})
38
+ return @rcsdk.client.get do |req|
39
+ req.url build_url(opts[:path])
40
+ end
41
+ end
42
+
43
+ def post(opts={})
44
+ return @rcsdk.client.post do |req|
45
+ req.url build_url(opts[:path])
46
+ if opts.has_key?(:body)
47
+ req.body = opts[:body]
48
+ if opts[:body].is_a?(Hash)
49
+ req.headers['Content-Type'] = 'application/json'
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def put(opts={})
56
+ return @rcsdk.client.put do |req|
57
+ req.url build_url(opts[:path])
58
+ if opts.has_key?(:body)
59
+ req.body = opts[:body]
60
+ if opts[:body].is_a?(Hash)
61
+ req.headers['Content-Type'] = 'application/json'
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ def build_url(path)
68
+ url = ''
69
+ if !path.is_a?(Array)
70
+ path = [path]
71
+ end
72
+ if path.length>0
73
+ path0 = path[0].to_s
74
+ if path0 !~ /\//
75
+ if path0.index('account') != 0
76
+ if path0.index('extension') != 0
77
+ path.unshift('extension/~')
78
+ end
79
+ path.unshift('account/~')
80
+ end
81
+ end
82
+ end
83
+ url = path.join('/')
84
+ return url
85
+ end
86
+
87
+ end
88
+ end
@@ -242,7 +242,9 @@ module RingCentralSdk
242
242
 
243
243
  def _unsubscribe_at_pubnub()
244
244
  if @_pubnub && alive?()
245
- @_pubnub.unsubscribe(@_subscription['deliveryMode']['address'])
245
+ @_pubnub.unsubscribe(channel: @_subscription['deliveryMode']['address']) do |envelope|
246
+ # puts envelope.message
247
+ end
246
248
  end
247
249
  end
248
250
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require './test/test_helper.rb'
2
4
 
3
5
  class RingCentralSdkHelperFaxTest < Test::Unit::TestCase
@@ -23,7 +25,7 @@ class RingCentralSdkHelperFaxTest < Test::Unit::TestCase
23
25
  # phone numbers are in E.164 format with or without leading '+'
24
26
  "to" => { :phoneNumber => '+16505551212' },
25
27
  :faxResolution => 'High',
26
- :coverPageText => 'RingCentral fax demo using Ruby SDK!'
28
+ :coverPageText => 'RingCentral fax demo using Ruby SDK Résolution!'
27
29
  },
28
30
  :file_name => './scripts/test_file.pdf'
29
31
  )
@@ -34,6 +36,9 @@ class RingCentralSdkHelperFaxTest < Test::Unit::TestCase
34
36
  fax2.add_file('non-existent_file_path')
35
37
  end
36
38
 
39
+ # Test UTF-8 metadata and file MIME concatenation
40
+ body = fax2.body
41
+
37
42
  fax3 = RingCentralSdk::Helpers::CreateFaxRequest.new(
38
43
  { :account_id => 111111111, :extension_id => 222222222 }, # Can be nil or {} for defaults '~'
39
44
  {
@@ -92,7 +92,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
92
92
  rcsdk = new_rcsdk()
93
93
  rcsdk.set_oauth2_client()
94
94
 
95
- stub_token_hash = data_auth_token
95
+ stub_token_hash = data_auth_token_with_refresh
96
96
  stub_token = OAuth2::AccessToken::from_hash(rcsdk.oauth2client, stub_token_hash)
97
97
 
98
98
  rcsdk.oauth2client.auth_code.stubs(:get_token).returns(stub_token)
@@ -104,7 +104,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
104
104
  rcsdk = new_rcsdk({:redirect_uri => 'http://localhost:4567/oauth'})
105
105
  rcsdk.set_oauth2_client()
106
106
 
107
- stub_token_hash = data_auth_token
107
+ stub_token_hash = data_auth_token_with_refresh
108
108
  stub_token = OAuth2::AccessToken::from_hash(rcsdk.oauth2client, stub_token_hash)
109
109
 
110
110
  rcsdk.oauth2client.auth_code.stubs(:get_token).returns(stub_token)
@@ -138,11 +138,11 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
138
138
  assert_equal 'OAuth2::AccessToken', rcsdk.token.class.name
139
139
  end
140
140
 
141
- def test_authorize_password
141
+ def test_authorize_password_with_refresh
142
142
  rcsdk = new_rcsdk()
143
143
  rcsdk.set_oauth2_client()
144
144
 
145
- stub_token_hash = data_auth_token
145
+ stub_token_hash = data_auth_token_with_refresh
146
146
  stub_token = OAuth2::AccessToken::from_hash(rcsdk.oauth2client, stub_token_hash)
147
147
 
148
148
  rcsdk.oauth2client.password.stubs(:get_token).returns(stub_token)
@@ -150,6 +150,22 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
150
150
  token = rcsdk.authorize('my_test_username', 'my_test_extension', 'my_test_password')
151
151
  assert_equal 'OAuth2::AccessToken', token.class.name
152
152
  assert_equal 'OAuth2::AccessToken', rcsdk.token.class.name
153
+ assert_equal 'my_test_access_token_with_refresh', rcsdk.token.token
154
+ end
155
+
156
+ def test_authorize_password_without_refresh
157
+ rcsdk = new_rcsdk()
158
+ rcsdk.set_oauth2_client()
159
+
160
+ stub_token_hash = data_auth_token_without_refresh
161
+ stub_token = OAuth2::AccessToken::from_hash(rcsdk.oauth2client, stub_token_hash)
162
+
163
+ rcsdk.oauth2client.password.stubs(:get_token).returns(stub_token)
164
+
165
+ token = rcsdk.authorize('my_test_username', 'my_test_extension', 'my_test_password')
166
+ assert_equal 'OAuth2::AccessToken', token.class.name
167
+ assert_equal 'OAuth2::AccessToken', rcsdk.token.class.name
168
+ assert_equal 'my_test_access_token_without_refresh', rcsdk.token.token
153
169
  end
154
170
 
155
171
  def test_request
@@ -160,7 +176,7 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
160
176
  rcsdk = new_rcsdk()
161
177
  rcsdk.set_oauth2_client()
162
178
 
163
- stub_token_hash = data_auth_token
179
+ stub_token_hash = data_auth_token_with_refresh
164
180
  stub_token = OAuth2::AccessToken::from_hash(rcsdk.oauth2client, stub_token_hash)
165
181
 
166
182
  rcsdk.oauth2client.password.stubs(:get_token).returns(stub_token)
@@ -193,9 +209,9 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
193
209
  )
194
210
  end
195
211
 
196
- def data_auth_token
212
+ def data_auth_token_with_refresh
197
213
  json = '{
198
- "access_token": "my_test_access_token",
214
+ "access_token": "my_test_access_token_with_refresh",
199
215
  "token_type": "bearer",
200
216
  "expires_in": 3599,
201
217
  "refresh_token": "my_test_refresh_token",
@@ -206,4 +222,18 @@ class RingCentralSdkPlatformTest < Test::Unit::TestCase
206
222
  data = JSON.parse(json, :symbolize_names=>true)
207
223
  return data
208
224
  end
225
+
226
+ def data_auth_token_without_refresh
227
+ json = '{
228
+ "access_token": "my_test_access_token_without_refresh",
229
+ "token_type": "bearer",
230
+ "expires_in": 3599,
231
+ "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",
232
+ "owner_id": "1234567890"
233
+ }'
234
+ data = JSON.parse(json, :symbolize_names=>true)
235
+ return data
236
+ end
237
+
238
+ alias_method :data_auth_token, :data_auth_token_with_refresh
209
239
  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.5.0
4
+ version: 0.5.1
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-18 00:00:00.000000000 Z
11
+ date: 2015-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -134,20 +134,6 @@ dependencies:
134
134
  - - ~>
135
135
  - !ruby/object:Gem::Version
136
136
  version: 3.7.3
137
- - !ruby/object:Gem::Dependency
138
- name: test-unit
139
- requirement: !ruby/object:Gem::Requirement
140
- requirements:
141
- - - '>='
142
- - !ruby/object:Gem::Version
143
- version: '0'
144
- type: :runtime
145
- prerelease: false
146
- version_requirements: !ruby/object:Gem::Requirement
147
- requirements:
148
- - - '>='
149
- - !ruby/object:Gem::Version
150
- version: '0'
151
137
  - !ruby/object:Gem::Dependency
152
138
  name: timers
153
139
  requirement: !ruby/object:Gem::Requirement
@@ -174,6 +160,7 @@ files:
174
160
  - lib/ringcentral_sdk/helpers/request.rb
175
161
  - lib/ringcentral_sdk/helpers.rb
176
162
  - lib/ringcentral_sdk/platform.rb
163
+ - lib/ringcentral_sdk/simple.rb
177
164
  - lib/ringcentral_sdk/subscription.rb
178
165
  - lib/ringcentral_sdk.rb
179
166
  - CHANGELOG.md