ringcentral-sdk 0.3.0 → 0.4.0

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
  SHA1:
3
- metadata.gz: 985e9f0cf6416e2288c2330b596fde160e32a381
4
- data.tar.gz: 631d59c2a2c13baa8178fadfc466c6044209b9c4
3
+ metadata.gz: 354ed40d66f2e406de2889128652ae486f7a58a6
4
+ data.tar.gz: 612d22c0d3c057d446b505b4d5a5f1ebc2d8ceae
5
5
  SHA512:
6
- metadata.gz: 2b44f5dddcbc5c65b8c1484844665ce01c2944f42f71d708992bfacbd54f0a977c98b8f87a566a456afc2bc17056328e7663e279aca1559e44059556bfecb906
7
- data.tar.gz: 1206c7a15bb653e5cb412e1b814031c4b7726f53f39875a56e2cb8688096a1abe68ae6d7aef7c552c2a0f5d2842eeea35d1e03d7002dab44c976ad556205875f
6
+ metadata.gz: fd5fb7784d5a65dc0d3a1f3c5f9d59ca2bf7c2949f6ec376e3a23343277a8be607956042fe9de803fe58ce2dca8d359a5d8b8b52f0eb6a68d28f83a0095245da
7
+ data.tar.gz: 46f4c8903ef34646614850b2c0bdb32bb50e0dd376f30cc28034768e681a139bead61c0d59d9e7cb5ec055ee5f466d4864ea4d6e49ad9c906721e775e2cd001e
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # ringcentral-ruby
2
2
 
3
+ [![Build Status](https://travis-ci.org/ringcentral/ringcentral-ruby.svg?branch=master)](https://travis-ci.org/ringcentral/ringcentral-ruby)
4
+ [![Coverage Status](https://coveralls.io/repos/github/ringcentral/ringcentral-ruby/badge.svg?branch=master)](https://coveralls.io/github/ringcentral/ringcentral-ruby?branch=master)
5
+
6
+
3
7
  Ruby SDK for RingCentral.
4
8
 
5
9
 
@@ -58,7 +62,5 @@ MIT
58
62
 
59
63
  ## Todo
60
64
 
61
- - Travis CI
62
- - Code coverage
63
65
  - Batch requests
64
- - Fax & SMS
66
+ - Samples for Fax & MMS
data/lib/ringcentral.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'base64'
2
2
  require 'addressable/uri'
3
3
  require 'subscription'
4
- require 'rest-client'
5
4
  require 'json'
6
5
  require 'concurrent'
6
+ require 'faraday'
7
7
 
8
8
  class RingCentral
9
9
  def self.SANDBOX_SERVER
@@ -24,6 +24,11 @@ class RingCentral
24
24
  @auto_refresh = true
25
25
  @token = nil
26
26
  @timer = nil
27
+ @faraday = Faraday.new(url: server) do |faraday|
28
+ faraday.request :multipart
29
+ faraday.request :url_encoded
30
+ faraday.adapter Faraday.default_adapter
31
+ end
27
32
  end
28
33
 
29
34
  def token=(value)
@@ -87,20 +92,48 @@ class RingCentral
87
92
  uri.to_s
88
93
  end
89
94
 
90
- def get(endpoint, params = nil)
91
- request(:get, endpoint, params: params)
95
+ def get(endpoint, params = {})
96
+ @faraday.get do |req|
97
+ req.url endpoint
98
+ req.params = params
99
+ req.headers = headers
100
+ end
92
101
  end
93
102
 
94
- def post(endpoint, payload: nil, params: nil, files: nil)
95
- request(:post, endpoint, payload: payload, params: params, files: files)
103
+ def post(endpoint, payload: nil, params: {}, files: nil)
104
+ @faraday.post do |req|
105
+ req.url endpoint
106
+ req.params = params
107
+ if files != nil && files.size > 0
108
+ req.headers = headers
109
+ req.body = (payload || {}).merge({
110
+ attachment: Faraday::UploadIO.new(files[0][:path], files[0][:content_type])
111
+ })
112
+ elsif payload != nil && @token != nil
113
+ req.headers = headers.merge({ 'Content-Type': 'application/json' })
114
+ req.body = payload.to_json
115
+ else
116
+ req.headers = headers
117
+ req.body = payload
118
+ end
119
+ end
96
120
  end
97
121
 
98
- def put(endpoint, payload: nil, params: nil, files: nil)
99
- request(:put, endpoint, payload: payload, params: params, files: files)
122
+ def put(endpoint, payload: nil, params: {}, files: nil)
123
+ @faraday.put do |req|
124
+ req.url endpoint
125
+ req.params = params
126
+ req.headers = headers.merge({ 'Content-Type': 'application/json' })
127
+ req.body = payload.to_json
128
+ end
100
129
  end
101
130
 
102
- def delete(endpoint, params = nil)
103
- request(:delete, endpoint, params: params)
131
+ def delete(endpoint, params = {})
132
+ @faraday.delete do |req|
133
+ req.url endpoint
134
+ req.params = params
135
+ req.headers = headers
136
+ end
104
137
  end
105
138
 
106
139
  def subscription(events, callback)
@@ -117,17 +150,12 @@ class RingCentral
117
150
  @token != nil ? "Bearer #{@token['access_token']}" : "Basic #{basic_key}"
118
151
  end
119
152
 
120
- def request(method, endpoint, params: nil, payload: nil, files: nil)
121
- url = (Addressable::URI.parse(@server) + endpoint).to_s
153
+ def headers
122
154
  user_agent_header = "ringcentral/ringcentral-ruby Ruby #{RUBY_VERSION} #{RUBY_PLATFORM}"
123
- headers = {
155
+ {
124
156
  'Authorization': autorization_header,
125
- 'RC-User-Agent': user_agent_header
157
+ 'RC-User-Agent': user_agent_header,
158
+ 'User-Agent': user_agent_header,
126
159
  }
127
- if payload != nil && @token != nil
128
- headers['Content-Type'] = 'application/json'
129
- payload = payload.to_json
130
- end
131
- RestClient::Request.execute(method: method.to_sym, url: url, params: params, payload: payload, headers: headers, files: files)
132
160
  end
133
161
  end
data/lib/subscription.rb CHANGED
@@ -49,7 +49,7 @@ class Subscription
49
49
  r = @rc.post('/restapi/v1.0/subscription', payload: request_body)
50
50
  self.subscription = JSON.parse(r.body)
51
51
  @pubnub = Pubnub.new(subscribe_key: @subscription['deliveryMode']['subscriberKey'])
52
- @pubnub.add_listener(callback: @callback)
52
+ @pubnub.add_listener(name: 'default', callback: @callback)
53
53
  @pubnub.subscribe(channels: @subscription['deliveryMode']['address'])
54
54
  end
55
55
 
@@ -62,9 +62,9 @@ class Subscription
62
62
  def revoke
63
63
  return if @subscription == nil
64
64
  @pubnub.unsubscribe(channel: @subscription['deliveryMode']['address'])
65
- @pubnub.remove_listener(@callback)
65
+ @pubnub.remove_listener(name: 'default')
66
66
  @pubnub = nil
67
- rc.delete("/restapi/v1.0/subscription/#{@subscription['id']}")
67
+ @rc.delete("/restapi/v1.0/subscription/#{@subscription['id']}")
68
68
  self.subscription = nil
69
69
  end
70
70
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'ringcentral-sdk'
3
- gem.version = '0.3.0'
3
+ gem.version = '0.4.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.'
@@ -13,8 +13,8 @@ Gem::Specification.new do |gem|
13
13
  gem.files += Dir['lib/**/*.rb']
14
14
  gem.test_files = Dir['spec/**/*.rb']
15
15
 
16
- gem.add_dependency('rest-client', '~> 2.0', '>= 2.0.2')
17
16
  gem.add_dependency('addressable', '~> 2.5', '>= 2.5.2')
18
17
  gem.add_dependency('concurrent-ruby', '~> 1.0', '>= 1.0.2')
19
18
  gem.add_dependency('pubnub', '~> 4.0', '>= 4.0.27')
19
+ gem.add_dependency('faraday', '~> 0.13', '>= 0.13.1')
20
20
  end
data/spec/fax_spec.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'dotenv'
2
+ require 'ringcentral'
3
+
4
+ RSpec.describe 'Fax' do
5
+ describe 'send fax' do
6
+ it 'should send a fax' do
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
+
11
+ r = rc.post('/restapi/v1.0/account/~/extension/~/fax',
12
+ payload: { to: ENV['receiver'] },
13
+ files:[{ path: './spec/test.png', content_type: 'image/png' }]
14
+ )
15
+ expect(r).not_to be_nil
16
+ message = JSON.parse(r.body)
17
+ expect('Fax').to eq(message['type'])
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.configure do |config|
2
+ require 'simplecov'
3
+ SimpleCov.start
4
+
5
+ require 'coveralls'
6
+ Coveralls.wear!
7
+ end
@@ -2,23 +2,48 @@ require 'ringcentral'
2
2
  require 'dotenv'
3
3
  require 'rspec'
4
4
 
5
+ Dotenv.load
6
+ $rc = RingCentral.new(ENV['appKey'], ENV['appSecret'], ENV['server'])
7
+ $rc.authorize(username: ENV['username'], extension: ENV['extension'], password: ENV['password'])
8
+
9
+ def createSubscription(callback)
10
+ events = [
11
+ '/restapi/v1.0/account/~/extension/~/message-store',
12
+ ]
13
+ subscription = $rc.subscription(events, lambda { |message|
14
+ callback.call(message)
15
+ })
16
+ subscription.subscribe()
17
+ return subscription
18
+ end
19
+
5
20
  RSpec.describe 'Subscription' do
6
21
  describe 'subscription' do
7
22
  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'])
23
+ count = 0
24
+ createSubscription(lambda { |message|
25
+ count += 1
26
+ })
27
+
28
+ $rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
29
+ to: [{phoneNumber: ENV['receiver']}],
30
+ from: {phoneNumber: ENV['username']},
31
+ text: 'Hello world'
32
+ })
33
+ sleep(20)
34
+
35
+ expect(count).to be > 0
36
+ end
11
37
 
12
- events = [
13
- '/restapi/v1.0/account/~/extension/~/message-store',
14
- ]
38
+ it 'refresh' do
15
39
  count = 0
16
- subscription = rc.subscription(events, lambda { |message|
40
+ subscription = createSubscription(lambda { |message|
17
41
  count += 1
18
42
  })
19
- subscription.subscribe()
20
43
 
21
- rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
44
+ subscription.refresh()
45
+
46
+ $rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
22
47
  to: [{phoneNumber: ENV['receiver']}],
23
48
  from: {phoneNumber: ENV['username']},
24
49
  text: 'Hello world'
@@ -27,5 +52,23 @@ RSpec.describe 'Subscription' do
27
52
 
28
53
  expect(count).to be > 0
29
54
  end
55
+
56
+ it 'revoke' do
57
+ count = 0
58
+ subscription = createSubscription(lambda { |message|
59
+ count += 1
60
+ })
61
+
62
+ subscription.revoke()
63
+
64
+ $rc.post('/restapi/v1.0/account/~/extension/~/sms', payload: {
65
+ to: [{phoneNumber: ENV['receiver']}],
66
+ from: {phoneNumber: ENV['username']},
67
+ text: 'Hello world'
68
+ })
69
+ sleep(20)
70
+
71
+ expect(count).to eq(0)
72
+ end
30
73
  end
31
74
  end
metadata CHANGED
@@ -1,35 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ringcentral-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.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: 2017-12-21 00:00:00.000000000 Z
11
+ date: 2017-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rest-client
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.0'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.0.2
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '2.0'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 2.0.2
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: addressable
35
15
  requirement: !ruby/object:Gem::Requirement
@@ -90,6 +70,26 @@ dependencies:
90
70
  - - ">="
91
71
  - !ruby/object:Gem::Version
92
72
  version: 4.0.27
73
+ - !ruby/object:Gem::Dependency
74
+ name: faraday
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '0.13'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.13.1
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.13'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 0.13.1
93
93
  description: Ruby SDK for you to access RingCentral platform API.
94
94
  email:
95
95
  - tyler.liu@ringcentral.com
@@ -101,7 +101,9 @@ files:
101
101
  - lib/ringcentral.rb
102
102
  - lib/subscription.rb
103
103
  - ringcentral-sdk.gemspec
104
+ - spec/fax_spec.rb
104
105
  - spec/ringcentral_spec.rb
106
+ - spec/spec_helper.rb
105
107
  - spec/subscription_spec.rb
106
108
  homepage: https://github.com/ringcentral/ringcentral-ruby
107
109
  licenses:
@@ -128,5 +130,7 @@ signing_key:
128
130
  specification_version: 4
129
131
  summary: RingCentral Ruby SDK.
130
132
  test_files:
133
+ - spec/fax_spec.rb
131
134
  - spec/ringcentral_spec.rb
135
+ - spec/spec_helper.rb
132
136
  - spec/subscription_spec.rb