ringcentral_sdk 0.2.0 → 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/CHANGELOG.md +4 -0
- data/LICENSE.txt +2 -0
- data/README.md +36 -15
- data/VERSION.txt +1 -1
- data/lib/ringcentral_sdk.rb +2 -0
- data/lib/ringcentral_sdk/platform.rb +1 -1
- data/lib/ringcentral_sdk/platform/platform.rb +26 -6
- data/lib/ringcentral_sdk/pubnub_factory.rb +33 -0
- data/lib/ringcentral_sdk/sdk.rb +9 -3
- data/lib/ringcentral_sdk/subscription.rb +281 -0
- data/lib/ringcentral_sdk/version.rb +1 -1
- metadata +36 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 239dea9ba4e4c8e62d7766757e538136ecda1576
|
4
|
+
data.tar.gz: b4f83504a9a0e48110174b4233da10b0619b7868
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fa0276afb85635e2865c00a63c7a14ca2dd2213cb0b894223cfd0ad6863509a234b158e85c9bb8c5c318512a3eb75fa566f952c96c7cd5911f65b65b4234ce9
|
7
|
+
data.tar.gz: 3114700d02cc0e3c31c86864c60240a55ff884d69e707235888a7cae7f6390fc01a831e4573b4ab9e5411ba001692fa43940737cfc105610cb5607ac6d531a93
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
---------
|
3
|
+
- **2015-10-07**: 0.3.0
|
4
|
+
- Add subscription support via PubNub
|
5
|
+
- Add `ruby-head`, `jruby`, `jruby-head`, and `rbx-2` to Travis CI
|
6
|
+
- Remove Ruby 1.8.7 support due to `hitimes` requirement in `pubnub` and `eventmachine`
|
3
7
|
- **2015-09-14**: 0.2.0
|
4
8
|
- Refactor platform class to remove `authorized` method in favor of `set_token`
|
5
9
|
- Add `User-Agent` header support
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,7 @@ RingCentral SDK
|
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/ringcentral_sdk.svg)](http://badge.fury.io/rb/ringcentral_sdk)
|
5
5
|
[![Build Status](https://img.shields.io/travis/grokify/ringcentral-sdk-ruby/master.svg)](https://travis-ci.org/grokify/ringcentral-sdk-ruby)
|
6
|
+
[![Dependency Status](https://gemnasium.com/bogdanRada/ruby-gem-downloads-badge.svg)](https://gemnasium.com/bogdanRada/ruby-gem-downloads-badge)
|
6
7
|
[![Code Climate](https://codeclimate.com/github/grokify/ringcentral-sdk-ruby/badges/gpa.svg)](https://codeclimate.com/github/grokify/ringcentral-sdk-ruby)
|
7
8
|
[![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)
|
8
9
|
[![Coverage Status](https://coveralls.io/repos/grokify/ringcentral-sdk-ruby/badge.svg?branch=master)](https://coveralls.io/r/grokify/ringcentral-sdk-ruby?branch=master)
|
@@ -23,6 +24,7 @@ RingCentral SDK
|
|
23
24
|
1. [API Requests](#api-requests)
|
24
25
|
1. [SMS Example](#sms-example)
|
25
26
|
2. [Fax Example](#fax-example)
|
27
|
+
1. [Subscriptions](#subscriptions)
|
26
28
|
5. [Change Log](#change-log)
|
27
29
|
6. [Links](#links)
|
28
30
|
7. [Contributions](#contributions)
|
@@ -113,13 +115,12 @@ platform = rcsdk.platform
|
|
113
115
|
### Authorization
|
114
116
|
|
115
117
|
```ruby
|
116
|
-
# Initialize using user phone number without extension number
|
117
|
-
|
118
|
-
platform.authorize("myUsername", nil, "myPassword")
|
119
|
-
|
120
118
|
# Initialize using main phone number and extension number
|
121
|
-
|
122
119
|
platform.authorize("myUsername", "myExtension", "myPassword")
|
120
|
+
|
121
|
+
# Initialize using user phone number without extension number
|
122
|
+
# Extension defaults to company admin extension
|
123
|
+
platform.authorize("myUsername", nil, "myPassword")
|
123
124
|
```
|
124
125
|
|
125
126
|
#### Authentication Lifecycle
|
@@ -127,21 +128,22 @@ platform.authorize("myUsername", "myExtension", "myPassword")
|
|
127
128
|
The platform class performs token refresh procedure automatically if needed. To save the access and refresh tokens between instances of the SDK, you can save and reuse the token as follows:
|
128
129
|
|
129
130
|
```ruby
|
130
|
-
# Retrieve and save access token when program is to be stopped
|
131
|
-
|
132
|
-
token_hash =
|
131
|
+
# Retrieve and save access token when program is to be stopped
|
132
|
+
# `token` is an `OAuth2::AccessToken` object
|
133
|
+
token_hash = rcsdk.platform.token.to_hash
|
133
134
|
```
|
134
135
|
|
135
136
|
After you have saved the token hash, e.g. as JSON, you can reload it in another instance of the SDK as follows:
|
136
137
|
|
137
138
|
```ruby
|
138
|
-
# Reuse token_hash in
|
139
|
-
|
139
|
+
# Reuse token_hash in another SDK instance
|
140
|
+
rcsdk2 = RingCentralSdk::Sdk.new(
|
140
141
|
"myAppKey",
|
141
142
|
"myAppSecret",
|
142
143
|
RingCentralSdk::Sdk::RC_SERVER_SANDBOX
|
143
144
|
)
|
144
|
-
|
145
|
+
# set_token() accepts a hash or OAuth2::AccessToken object
|
146
|
+
rcsdk2.platform.set_token(token_hash)
|
145
147
|
```
|
146
148
|
|
147
149
|
Important! You have to manually maintain synchronization of SDK's between requests if you share authentication. When two simultaneous requests will perform refresh, only one will succeed. One of the solutions would be to have semaphor and pause other pending requests while one of them is performing refresh.
|
@@ -163,7 +165,6 @@ SMS and other requests can be easily sent directly without helpers.
|
|
163
165
|
|
164
166
|
```ruby
|
165
167
|
# SMS Example
|
166
|
-
|
167
168
|
response = client.post do |req|
|
168
169
|
req.url 'account/~/extension/~/sms'
|
169
170
|
req.headers['Content-Type'] = 'application/json'
|
@@ -190,7 +191,6 @@ helper object in its entirety.
|
|
190
191
|
|
191
192
|
```ruby
|
192
193
|
# Fax example using request helper
|
193
|
-
|
194
194
|
fax = RingCentralSdk::Helpers::CreateFaxRequest.new(
|
195
195
|
nil, # auto-inflates to [{:account_id => '~', :extension_id => '~'}]
|
196
196
|
{
|
@@ -213,11 +213,32 @@ response = client.post do |req|
|
|
213
213
|
end
|
214
214
|
```
|
215
215
|
|
216
|
+
### Subscriptions
|
217
|
+
|
218
|
+
To make subscriptions with RingCentral, use the SDK object to create subscription Observer object and then add observers to it.
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
sub = rcsdk.create_subscription()
|
222
|
+
|
223
|
+
sub.subscribe(['/restapi/v1.0/account/~/extension/~/presence'])
|
224
|
+
|
225
|
+
class MyObserver
|
226
|
+
def update(message)
|
227
|
+
puts "Subscription Message Received"
|
228
|
+
puts JSON.dump(message)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
sub.add_observer(MyObserver.new())
|
233
|
+
|
234
|
+
sub.destroy() # end the subscription
|
235
|
+
```
|
236
|
+
|
216
237
|
## Versioning
|
217
238
|
|
218
|
-
This project is currently in development and the API can change. During development (Version 0.x.x),
|
239
|
+
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.
|
219
240
|
|
220
|
-
Once the project is version 1.0.0 or above, it will use [semantic versioning](http://semver.org/).
|
241
|
+
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.
|
221
242
|
|
222
243
|
## Change Log
|
223
244
|
|
data/VERSION.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/ringcentral_sdk.rb
CHANGED
@@ -3,5 +3,7 @@ require 'ringcentral_sdk/version.rb'
|
|
3
3
|
module RingCentralSdk
|
4
4
|
autoload :Helpers, 'ringcentral_sdk/helpers'
|
5
5
|
autoload :Platform, 'ringcentral_sdk/platform'
|
6
|
+
autoload :PubnubFactory, 'ringcentral_sdk/pubnub_factory'
|
6
7
|
autoload :Sdk, 'ringcentral_sdk/sdk'
|
8
|
+
autoload :Subscription, 'ringcentral_sdk/subscription'
|
7
9
|
end
|
@@ -21,7 +21,7 @@ module RingCentralSdk::Platform
|
|
21
21
|
|
22
22
|
attr_reader :client
|
23
23
|
attr_reader :token
|
24
|
-
attr_reader :
|
24
|
+
attr_reader :user_agent
|
25
25
|
|
26
26
|
def initialize(app_key='', app_secret='', server_url=RingCentralSdk::Sdk::RC_SERVER_SANDBOX)
|
27
27
|
@app_key = app_key
|
@@ -36,8 +36,29 @@ module RingCentralSdk::Platform
|
|
36
36
|
return @server_url + URL_PREFIX + '/' + API_VERSION
|
37
37
|
end
|
38
38
|
|
39
|
+
def create_url(url, add_server=false, add_method=nil, add_token=false)
|
40
|
+
built_url = ''
|
41
|
+
has_http = !url.index('http://').nil? && !url.index('https://').nil?
|
42
|
+
|
43
|
+
if add_server && ! has_http
|
44
|
+
built_url += @server_url
|
45
|
+
end
|
46
|
+
|
47
|
+
if url.index(URL_PREFIX).nil? && ! has_http
|
48
|
+
built_url += URL_PREFIX + '/' + API_VERSION
|
49
|
+
end
|
50
|
+
|
51
|
+
built_url += url
|
52
|
+
|
53
|
+
return built_url
|
54
|
+
end
|
55
|
+
|
56
|
+
def login(username, extension, password)
|
57
|
+
return authorize(username, extension, password)
|
58
|
+
end
|
59
|
+
|
39
60
|
def authorize(username='', extension='', password='', remember=false)
|
40
|
-
oauth2client =
|
61
|
+
oauth2client = new_oauth2_client()
|
41
62
|
|
42
63
|
token = oauth2client.password.get_token(username, password, {
|
43
64
|
:extension => extension,
|
@@ -48,12 +69,11 @@ module RingCentralSdk::Platform
|
|
48
69
|
|
49
70
|
def set_token(token)
|
50
71
|
if token.is_a?(Hash)
|
51
|
-
|
52
|
-
token = OAuth2::AccessToken::from_hash(oauth2client, token)
|
72
|
+
token = OAuth2::AccessToken::from_hash(new_oauth2_client(), token)
|
53
73
|
end
|
54
74
|
|
55
75
|
unless token.is_a?(OAuth2::AccessToken)
|
56
|
-
raise "Token is a OAuth2::AccessToken"
|
76
|
+
raise "Token is not a OAuth2::AccessToken"
|
57
77
|
end
|
58
78
|
|
59
79
|
@token = token
|
@@ -69,7 +89,7 @@ module RingCentralSdk::Platform
|
|
69
89
|
end
|
70
90
|
end
|
71
91
|
|
72
|
-
def
|
92
|
+
def new_oauth2_client()
|
73
93
|
return OAuth2::Client.new(@app_key, @app_secret,
|
74
94
|
:site => @server_url,
|
75
95
|
:token_url => TOKEN_ENDPOINT)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'pubnub'
|
3
|
+
|
4
|
+
module RingCentralSdk
|
5
|
+
class PubnubFactory
|
6
|
+
|
7
|
+
def initialize(use_mock=false)
|
8
|
+
@_use_mock = use_mock
|
9
|
+
end
|
10
|
+
|
11
|
+
def pubnub(subscribe_key='', ssl_on=false, publish_key='', my_logger=nil)
|
12
|
+
if @_use_mock
|
13
|
+
raise 'PubNub Mock is not implemented'
|
14
|
+
end
|
15
|
+
|
16
|
+
my_logger = Logger.new(STDOUT) if my_logger.nil?
|
17
|
+
|
18
|
+
pubnub = Pubnub.new(
|
19
|
+
:subscribe_key => subscribe_key.to_s,
|
20
|
+
:publish_key => publish_key.to_s,
|
21
|
+
:error_callback => lambda { |msg|
|
22
|
+
puts "Error callback says: #{msg.inspect}"
|
23
|
+
},
|
24
|
+
:connect_callback => lambda { |msg|
|
25
|
+
puts "CONNECTED: #{msg.inspect}"
|
26
|
+
},
|
27
|
+
:logger => my_logger
|
28
|
+
)
|
29
|
+
|
30
|
+
return pubnub
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/ringcentral_sdk/sdk.rb
CHANGED
@@ -4,19 +4,25 @@ module RingCentralSdk
|
|
4
4
|
RC_SERVER_PRODUCTION = 'https://platform.ringcentral.com'
|
5
5
|
RC_SERVER_SANDBOX = 'https://platform.devtest.ringcentral.com'
|
6
6
|
|
7
|
-
#attr_reader :parser
|
8
7
|
attr_reader :platform
|
9
8
|
|
10
9
|
def initialize(app_key=nil,app_secret=nil,server_url=nil,username=nil,extension=nil,password=nil)
|
11
|
-
|
10
|
+
use_pubnub_mock = false
|
11
|
+
|
12
12
|
@platform = RingCentralSdk::Platform::Platform.new(app_key, app_secret, server_url)
|
13
13
|
if not username.nil? and not password.nil?
|
14
14
|
@platform.authorize(username, extension, password)
|
15
15
|
end
|
16
|
+
|
17
|
+
@_pubnub_factory = RingCentralSdk::PubnubFactory.new(use_pubnub_mock)
|
16
18
|
end
|
17
19
|
|
18
20
|
def request(helper=nil)
|
19
21
|
return @platform.request(helper)
|
20
22
|
end
|
23
|
+
|
24
|
+
def create_subscription()
|
25
|
+
return RingCentralSdk::Subscription.new(@platform, @_pubnub_factory)
|
26
|
+
end
|
21
27
|
end
|
22
|
-
end
|
28
|
+
end
|
@@ -0,0 +1,281 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'multi_json'
|
3
|
+
require 'observer'
|
4
|
+
require 'timers' # Also see http://ruby-doc.org/stdlib-2.2.3/libdoc/timeout/rdoc/Timeout.html
|
5
|
+
|
6
|
+
module RingCentralSdk
|
7
|
+
class Subscription
|
8
|
+
include Observable
|
9
|
+
|
10
|
+
RENEW_HANDICAP = 60
|
11
|
+
|
12
|
+
def initialize(platform, pubnub_factory)
|
13
|
+
@_platform = platform
|
14
|
+
@_pubnub_factory = pubnub_factory
|
15
|
+
@_event_filters = []
|
16
|
+
@_timeout = nil
|
17
|
+
@_subscription = nil_subscription()
|
18
|
+
@_pubnub = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def nil_subscription()
|
22
|
+
subscription = {
|
23
|
+
'eventFilters' => [],
|
24
|
+
'expirationTime' => '', # 2014-03-12T19:54:35.613Z
|
25
|
+
'expiresIn' => 0,
|
26
|
+
'deliveryMode' => {
|
27
|
+
'transportType' => 'PubNub',
|
28
|
+
'encryption' => false,
|
29
|
+
'address' => '',
|
30
|
+
'subscriberKey' => '',
|
31
|
+
'secretKey' => ''
|
32
|
+
},
|
33
|
+
'id' => '',
|
34
|
+
'creationTime' => '', # 2014-03-12T19:54:35.613Z
|
35
|
+
'status' => '', # Active
|
36
|
+
'uri' => ''
|
37
|
+
}
|
38
|
+
return subscription
|
39
|
+
end
|
40
|
+
|
41
|
+
def pubnub()
|
42
|
+
return @_pubnub
|
43
|
+
end
|
44
|
+
|
45
|
+
def register(events=nil)
|
46
|
+
return alive() ? renew(events) : subscribe(events)
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_events(events)
|
50
|
+
unless events.is_a?(Array)
|
51
|
+
raise 'Events is not an array.'
|
52
|
+
end
|
53
|
+
@_event_filters.push(events) if events.length>0
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_events(events)
|
57
|
+
unless events.is_a?(Array)
|
58
|
+
raise 'Events is not an array.'
|
59
|
+
end
|
60
|
+
@_event_filters.push(*events) if events.length>0
|
61
|
+
end
|
62
|
+
|
63
|
+
def subscribe(events=nil)
|
64
|
+
set_events(events) if events.is_a?(Array)
|
65
|
+
|
66
|
+
if !@_event_filters.is_a?(Array) || @_event_filters.length ==0
|
67
|
+
raise 'Events are undefined'
|
68
|
+
end
|
69
|
+
|
70
|
+
begin
|
71
|
+
response = @_platform.client.post do |req|
|
72
|
+
req.url 'subscription'
|
73
|
+
req.body = {
|
74
|
+
:eventFilters => _get_full_events_filter(),
|
75
|
+
:deliveryMode => {
|
76
|
+
:transportType => 'PubNub'
|
77
|
+
}
|
78
|
+
}
|
79
|
+
end
|
80
|
+
set_subscription(response.body)
|
81
|
+
_subscribe_at_pubnub()
|
82
|
+
changed
|
83
|
+
notify_observers(response)
|
84
|
+
return response
|
85
|
+
rescue StandardError => e
|
86
|
+
reset()
|
87
|
+
changed
|
88
|
+
notify_observers(e)
|
89
|
+
raise 'Subscribe HTTP Request Error'
|
90
|
+
end
|
91
|
+
|
92
|
+
return nil
|
93
|
+
end
|
94
|
+
|
95
|
+
def renew(events=nil)
|
96
|
+
set_events(events) if events.is_a?(Array)
|
97
|
+
|
98
|
+
unless alive()
|
99
|
+
raise 'Subscription is not alive'
|
100
|
+
end
|
101
|
+
|
102
|
+
if !@_event_filters.is_a?(Array) || @_event_filters.length ==0
|
103
|
+
raise 'Events are undefined'
|
104
|
+
end
|
105
|
+
|
106
|
+
_clear_timeout()
|
107
|
+
|
108
|
+
begin
|
109
|
+
response = @_platform.client.put do |req|
|
110
|
+
req.url 'subscription' + @_subscription['id']
|
111
|
+
req.body = {
|
112
|
+
:eventFilters => _get_full_events_filter()
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
set_subscription(response.body)
|
117
|
+
changed
|
118
|
+
notify_observers(response)
|
119
|
+
return response
|
120
|
+
rescue StandardError => e
|
121
|
+
reset()
|
122
|
+
changed
|
123
|
+
notify_observers(e)
|
124
|
+
raise 'Renew HTTP Request Error'
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def remove()
|
129
|
+
unless alive()
|
130
|
+
raise 'Subscription is not alive'
|
131
|
+
end
|
132
|
+
|
133
|
+
begin
|
134
|
+
response = @_platform.client.delete do |req|
|
135
|
+
req.url = 'subscription' + @_subscription['id']
|
136
|
+
end
|
137
|
+
reset()
|
138
|
+
changed
|
139
|
+
notify_observers(response.body)
|
140
|
+
return response
|
141
|
+
rescue StandardError => e
|
142
|
+
reset()
|
143
|
+
changed
|
144
|
+
notify_observers(e)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def alive()
|
149
|
+
s = @_subscription
|
150
|
+
return (s.has_key?('deliveryMode') && s['deliveryMode']) && \
|
151
|
+
(s['deliveryMode'].has_key?('subscriberKey') && s['deliveryMode']['subscriberKey']) && \
|
152
|
+
(s['deliveryMode'].has_key?('address') && s['deliveryMode']['address'])
|
153
|
+
end
|
154
|
+
|
155
|
+
def subscription()
|
156
|
+
return @_subscription
|
157
|
+
end
|
158
|
+
|
159
|
+
def set_subscription(data)
|
160
|
+
_clear_timeout()
|
161
|
+
@_subscription = data
|
162
|
+
_set_timeout()
|
163
|
+
end
|
164
|
+
|
165
|
+
def reset()
|
166
|
+
_clear_timeout()
|
167
|
+
_unsubscribe_at_pubnub()
|
168
|
+
_subscription = nil
|
169
|
+
end
|
170
|
+
|
171
|
+
def destroy()
|
172
|
+
reset()
|
173
|
+
off()
|
174
|
+
end
|
175
|
+
|
176
|
+
def _subscribe_at_pubnub()
|
177
|
+
unless alive()
|
178
|
+
raise 'Subscription is not alive'
|
179
|
+
end
|
180
|
+
|
181
|
+
s_key = @_subscription['deliveryMode']['subscriberKey']
|
182
|
+
@_pubnub = @_pubnub_factory.pubnub(s_key, false, '')
|
183
|
+
|
184
|
+
callback = lambda { |envelope|
|
185
|
+
_notify(envelope.msg)
|
186
|
+
changed
|
187
|
+
notify_observers('GOT_PUBNUB_MESSAGE_NOTIFY')
|
188
|
+
}
|
189
|
+
|
190
|
+
error = lambda { |envelope|
|
191
|
+
puts('ERROR : ' + envelope.msg.to_s) # FIXME Handle this
|
192
|
+
}
|
193
|
+
|
194
|
+
connect = lambda { |envelope|
|
195
|
+
puts('CONNECTED')
|
196
|
+
}
|
197
|
+
|
198
|
+
reconnect = lambda { |envelope|
|
199
|
+
puts('RECONNECTED')
|
200
|
+
}
|
201
|
+
|
202
|
+
disconnect = lambda { |envelope|
|
203
|
+
puts('DISCONNECTED')
|
204
|
+
}
|
205
|
+
|
206
|
+
@_pubnub.subscribe(
|
207
|
+
:channel => @_subscription['deliveryMode']['address'],
|
208
|
+
:callback => callback,
|
209
|
+
:error => error,
|
210
|
+
:connect => connect,
|
211
|
+
:reconnect => reconnect,
|
212
|
+
:disconnect => disconnect
|
213
|
+
)
|
214
|
+
end
|
215
|
+
|
216
|
+
def _notify(message)
|
217
|
+
message = _decrypt(message)
|
218
|
+
changed
|
219
|
+
notify_observers(message)
|
220
|
+
end
|
221
|
+
|
222
|
+
def _decrypt(message)
|
223
|
+
unless alive()
|
224
|
+
raise 'Subscription is not alive'
|
225
|
+
end
|
226
|
+
|
227
|
+
delivery_mode = @_subscription['deliveryMode']
|
228
|
+
|
229
|
+
is_encrypted = delivery_mode.has_key?('encryption') && \
|
230
|
+
delivery_mode['encryption'] && \
|
231
|
+
delivery_mode.has_key?('encryptionKey') && \
|
232
|
+
delivery_mode['encryptionKey']
|
233
|
+
|
234
|
+
if is_encrypted
|
235
|
+
key = Base64.decode64(delivery_mode['encryptionKey'])
|
236
|
+
ciphertext = Base64.decode64(message)
|
237
|
+
|
238
|
+
decipher = OpenSSL::Cipher::AES.new(128, :ECB)
|
239
|
+
decipher.decrypt
|
240
|
+
decipher.key = key
|
241
|
+
|
242
|
+
plaintext = decipher.update(ciphertext) + decipher.final
|
243
|
+
|
244
|
+
message = MultiJson.decode(plaintext)
|
245
|
+
end
|
246
|
+
|
247
|
+
return message
|
248
|
+
end
|
249
|
+
|
250
|
+
def _unsubscribe_at_pubnub()
|
251
|
+
if @_pubnub && alive()
|
252
|
+
@_pubnub.unsubscribe(@_subscription['deliveryMode']['address'])
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def _get_full_events_filter()
|
257
|
+
full_events_filter = []
|
258
|
+
@_event_filters.each do |filter|
|
259
|
+
if filter.to_s
|
260
|
+
full_events_filter.push(@_platform.create_url(filter.to_s))
|
261
|
+
end
|
262
|
+
end
|
263
|
+
return full_events_filter
|
264
|
+
end
|
265
|
+
|
266
|
+
def _set_timeout()
|
267
|
+
time_to_expiration = @_subscription['expiresIn'] - RENEW_HANDICAP
|
268
|
+
@_timeout = Timers::Group.new
|
269
|
+
@_timeout.after(time_to_expiration) do
|
270
|
+
renew()
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
def _clear_timeout()
|
275
|
+
if @_timeout.is_a?(Timers::Group)
|
276
|
+
@_timeout.cancel()
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
281
|
+
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.
|
4
|
+
version: 0.3.0
|
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-
|
11
|
+
date: 2015-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -120,6 +120,20 @@ dependencies:
|
|
120
120
|
- - '>='
|
121
121
|
- !ruby/object:Gem::Version
|
122
122
|
version: '0'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: pubnub
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ~>
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: 3.7.3
|
130
|
+
type: :runtime
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ~>
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 3.7.3
|
123
137
|
- !ruby/object:Gem::Dependency
|
124
138
|
name: test-unit
|
125
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,7 +148,21 @@ dependencies:
|
|
134
148
|
- - '>='
|
135
149
|
- !ruby/object:Gem::Version
|
136
150
|
version: '0'
|
137
|
-
|
151
|
+
- !ruby/object:Gem::Dependency
|
152
|
+
name: timers
|
153
|
+
requirement: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
type: :runtime
|
159
|
+
prerelease: false
|
160
|
+
version_requirements: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
description: A Ruby SDK for the RingCentral Connect Platform API
|
138
166
|
email: johncwang@gmail.com
|
139
167
|
executables: []
|
140
168
|
extensions: []
|
@@ -153,11 +181,14 @@ files:
|
|
153
181
|
- lib/ringcentral_sdk/helpers/request.rb
|
154
182
|
- lib/ringcentral_sdk/platform.rb
|
155
183
|
- lib/ringcentral_sdk/platform/platform.rb
|
184
|
+
- lib/ringcentral_sdk/pubnub_factory.rb
|
156
185
|
- lib/ringcentral_sdk/sdk.rb
|
186
|
+
- lib/ringcentral_sdk/subscription.rb
|
157
187
|
- lib/ringcentral_sdk/version.rb
|
158
188
|
- test/test_setup.rb
|
159
189
|
homepage: https://github.com/grokify/
|
160
|
-
licenses:
|
190
|
+
licenses:
|
191
|
+
- MIT
|
161
192
|
metadata: {}
|
162
193
|
post_install_message:
|
163
194
|
rdoc_options: []
|
@@ -178,6 +209,5 @@ rubyforge_project:
|
|
178
209
|
rubygems_version: 2.1.5
|
179
210
|
signing_key:
|
180
211
|
specification_version: 4
|
181
|
-
summary: RingCentral SDK -
|
182
|
-
API
|
212
|
+
summary: RingCentral SDK - Ruby SDK for the RingCentral Connect Platform API
|
183
213
|
test_files: []
|