ringcentral_sdk 1.3.1 → 1.3.2

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: 877b510cfc9ecc5864c9b07a4597addcd39d2adc
4
- data.tar.gz: d4f64600c0d5097a9a33ff29b691625d9c4c3917
3
+ metadata.gz: f3cbfb92bc00009e9575a0f41d2115bbf1d6964e
4
+ data.tar.gz: 38a3ec34ad844bbc18d6f42c48ac0d46348630c0
5
5
  SHA512:
6
- metadata.gz: 84d0277bd3762c77b9ba31955488ec9eed1f3916d7727a0ecb1711abb56221d6d6cd03ff3c07b066b482181055a0403b7cc2a33fdf34672dbab3d6dbc062773a
7
- data.tar.gz: 3655cc0b68e7ba2af7d453e492bd7042752900d2490106f064a57e2597851b674c17f8c78c71eb9fdcc53632472fd2dffc8f936cada92228ecacc39d35ee79f7
6
+ metadata.gz: 8f832f2188822a1a38e28a981a4eb1ee196e8e7a92be7fbd2f1026ce12e7c8a3377c48dc621a9a62a8df6286010fc86fb9876a0c6582fb2bdf70c79f82c53518
7
+ data.tar.gz: 76b5ad230db8d102ea314054339209f38f6c617b77038785d73aa6bc8bdfd65a5ee9356dc8f13234aa06a611548de42a22afb4f14cdca409b8981e9f1b680791
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  CHANGELOG
2
2
  ---------
3
+ - **2016-09-04**: 1.3.2
4
+ - Bugfixes
5
+ - Fix `RingCentralSdk::REST::Subscription` renewal bug
3
6
  - **2016-08-24**: 1.3.1
4
7
  - Updates
5
8
  - Lock PubNub dependency to 3.x due to back compat issue with 4.x
@@ -1,5 +1,5 @@
1
1
  module RingCentralSdk
2
- VERSION = '1.3.1'
2
+ VERSION = '1.3.2'
3
3
 
4
4
  RC_SERVER_PRODUCTION = 'https://platform.ringcentral.com'
5
5
  RC_SERVER_SANDBOX = 'https://platform.devtest.ringcentral.com'
@@ -4,9 +4,6 @@ require 'multi_json'
4
4
  require 'observer'
5
5
  require 'openssl'
6
6
  require 'pubnub'
7
- require 'timers'
8
-
9
- require 'pp'
10
7
 
11
8
  module RingCentralSdk::REST
12
9
  class Subscription
@@ -25,7 +22,7 @@ module RingCentralSdk::REST
25
22
  end
26
23
 
27
24
  def nil_subscription()
28
- subscription = {
25
+ return {
29
26
  'eventFilters' => [],
30
27
  'expirationTime' => '', # 2014-03-12T19:54:35.613Z
31
28
  'expiresIn' => 0,
@@ -41,7 +38,6 @@ module RingCentralSdk::REST
41
38
  'status' => '', # Active
42
39
  'uri' => ''
43
40
  }
44
- return subscription
45
41
  end
46
42
 
47
43
  def pubnub()
@@ -49,25 +45,25 @@ module RingCentralSdk::REST
49
45
  end
50
46
 
51
47
  def register(events = nil)
52
- return alive?() ? renew(events) : subscribe(events)
48
+ return alive? ? renew(events) : subscribe(events)
53
49
  end
54
50
 
55
51
  def add_events(events)
56
- unless events.is_a?(Array)
52
+ unless events.is_a? Array
57
53
  raise 'Events is not an array.'
58
54
  end
59
55
  @event_filters.push(events) if events.length > 0
60
56
  end
61
57
 
62
58
  def set_events(events)
63
- unless events.is_a?(Array)
59
+ unless events.is_a? Array
64
60
  raise 'Events is not an array.'
65
61
  end
66
62
  @event_filters = events
67
63
  end
68
64
 
69
65
  def subscribe(events=nil)
70
- set_events(events) if events.is_a?(Array)
66
+ set_events(events) if events.is_a? Array
71
67
 
72
68
  if !@event_filters.is_a?(Array) || @event_filters.length == 0
73
69
  raise 'Events are undefined'
@@ -84,10 +80,10 @@ module RingCentralSdk::REST
84
80
  }
85
81
  }
86
82
  end
87
- set_subscription(response.body)
83
+ set_subscription response.body
88
84
  _subscribe_at_pubnub()
89
85
  changed
90
- notify_observers(response)
86
+ notify_observers response
91
87
  return response
92
88
  rescue StandardError => e
93
89
  reset()
@@ -98,9 +94,9 @@ module RingCentralSdk::REST
98
94
  end
99
95
 
100
96
  def renew(events = nil)
101
- set_events(events) if events.is_a?(Array)
97
+ set_events(events) if events.is_a? Array
102
98
 
103
- unless alive?()
99
+ unless alive?
104
100
  raise 'Subscription is not alive'
105
101
  end
106
102
 
@@ -113,25 +109,26 @@ module RingCentralSdk::REST
113
109
  begin
114
110
  response = @_client.http.put do |req|
115
111
  req.url 'subscription/' + @_subscription['id'].to_s
112
+ req.headers['Content-Type'] = 'application/json'
116
113
  req.body = {
117
114
  eventFilters: @_client.create_urls(@event_filters)
118
115
  }
119
116
  end
120
117
 
121
- set_subscription(response.body)
118
+ set_subscription response.body
122
119
  changed
123
- notify_observers(response)
120
+ notify_observers response
124
121
  return response
125
122
  rescue StandardError => e
126
123
  reset()
127
124
  changed
128
- notify_observers(e)
125
+ notify_observers e
129
126
  raise 'Renew HTTP Request Error'
130
127
  end
131
128
  end
132
129
 
133
130
  def remove()
134
- unless alive?()
131
+ unless alive?
135
132
  raise 'Subscription is not alive'
136
133
  end
137
134
 
@@ -141,16 +138,16 @@ module RingCentralSdk::REST
141
138
  end
142
139
  reset()
143
140
  changed
144
- notify_observers(response.body)
141
+ notify_observers response.body
145
142
  return response
146
143
  rescue StandardError => e
147
144
  reset()
148
145
  changed
149
- notify_observers(e)
146
+ notify_observers e
150
147
  end
151
148
  end
152
149
 
153
- def alive?()
150
+ def alive?
154
151
  s = @_subscription
155
152
  return (s.has_key?('deliveryMode') && s['deliveryMode']) && \
156
153
  (s['deliveryMode'].has_key?('subscriberKey') && s['deliveryMode']['subscriberKey']) && \
@@ -160,7 +157,7 @@ module RingCentralSdk::REST
160
157
  ? true : false
161
158
  end
162
159
 
163
- def subscription()
160
+ def subscription
164
161
  return @_subscription
165
162
  end
166
163
 
@@ -170,18 +167,18 @@ module RingCentralSdk::REST
170
167
  _set_timeout()
171
168
  end
172
169
 
173
- def reset()
170
+ def reset
174
171
  _clear_timeout()
175
172
  _unsubscribe_at_pubnub()
176
173
  @_subscription = nil_subscription()
177
174
  end
178
175
 
179
- def destroy()
176
+ def destroy
180
177
  reset()
181
178
  end
182
179
 
183
- def _subscribe_at_pubnub()
184
- if ! alive?()
180
+ def _subscribe_at_pubnub
181
+ unless alive?
185
182
  raise 'Subscription is not alive'
186
183
  end
187
184
 
@@ -192,8 +189,6 @@ module RingCentralSdk::REST
192
189
  callback = lambda { |envelope|
193
190
  _notify(envelope.msg)
194
191
  changed
195
- #notify_observers {}
196
- #notify_observers('GOT_PUBNUB_MESSAGE_NOTIFY')
197
192
  }
198
193
 
199
194
  @_pubnub.subscribe(
@@ -207,13 +202,13 @@ module RingCentralSdk::REST
207
202
  end
208
203
 
209
204
  def _notify(message)
210
- message = _decrypt(message)
205
+ message = _decrypt message
211
206
  changed
212
- notify_observers(message)
207
+ notify_observers message
213
208
  end
214
209
 
215
210
  def _decrypt(message)
216
- unless alive?()
211
+ unless alive?
217
212
  raise 'Subscription is not alive'
218
213
  end
219
214
 
@@ -233,7 +228,7 @@ module RingCentralSdk::REST
233
228
  return message
234
229
  end
235
230
 
236
- def _encrypted?()
231
+ def _encrypted?
237
232
  delivery_mode = @_subscription['deliveryMode']
238
233
  is_encrypted = delivery_mode.has_key?('encryption') && \
239
234
  delivery_mode['encryption'] && \
@@ -242,7 +237,7 @@ module RingCentralSdk::REST
242
237
  return is_encrypted
243
238
  end
244
239
 
245
- def _unsubscribe_at_pubnub()
240
+ def _unsubscribe_at_pubnub
246
241
  if @_pubnub && alive?()
247
242
  @_pubnub.unsubscribe(channel: @_subscription['deliveryMode']['address']) do |envelope|
248
243
  # puts envelope.message
@@ -250,18 +245,18 @@ module RingCentralSdk::REST
250
245
  end
251
246
  end
252
247
 
253
- def _set_timeout()
248
+ def _set_timeout
254
249
  time_to_expiration = @_subscription['expiresIn'] - RENEW_HANDICAP
255
- @_timeout = Timers::Group.new
256
- @_timeout.after(time_to_expiration) do
257
- renew()
250
+ time_to_expiration = 5
251
+
252
+ @_timeout = Thread.new do
253
+ sleep time_to_expiration
254
+ renew
258
255
  end
259
256
  end
260
257
 
261
- def _clear_timeout()
262
- if @_timeout.is_a? Timers::Group
263
- @_timeout.cancel()
264
- end
258
+ def _clear_timeout
259
+ @_timeout = nil
265
260
  end
266
261
 
267
262
  def new_pubnub(subscribe_key='', ssl_on=false, publish_key='', my_logger=nil)
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: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Wang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-24 00:00:00.000000000 Z
11
+ date: 2016-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -306,7 +306,6 @@ extra_rdoc_files: []
306
306
  files:
307
307
  - CHANGELOG.md
308
308
  - Gemfile
309
- - Gemfile.lock
310
309
  - LICENSE.txt
311
310
  - README.md
312
311
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,112 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ringcentral_sdk (1.3.1)
5
- dotenv (~> 2.1, >= 2.1.0)
6
- faraday (~> 0.9, >= 0.9)
7
- faraday_middleware (~> 0, >= 0)
8
- faraday_middleware-oauth2_refresh (~> 0)
9
- jsondoc (~> 0.1, >= 0.1.0)
10
- logger
11
- mime (~> 0.4, >= 0.4.3)
12
- mime-types (~> 3.1)
13
- mime_builder (~> 0)
14
- multi_json (~> 1.3)
15
- oauth2 (~> 1.0, >= 1.0.0)
16
- pubnub (~> 3.8)
17
- timers (~> 4.1)
18
-
19
- GEM
20
- remote: https://rubygems.org/
21
- specs:
22
- celluloid (0.17.3)
23
- celluloid-essentials
24
- celluloid-extras
25
- celluloid-fsm
26
- celluloid-pool
27
- celluloid-supervision
28
- timers (>= 4.1.1)
29
- celluloid-essentials (0.20.5)
30
- timers (>= 4.1.1)
31
- celluloid-extras (0.20.5)
32
- timers (>= 4.1.1)
33
- celluloid-fsm (0.20.5)
34
- timers (>= 4.1.1)
35
- celluloid-pool (0.20.5)
36
- timers (>= 4.1.1)
37
- celluloid-supervision (0.20.6)
38
- timers (>= 4.1.1)
39
- coveralls (0.8.15)
40
- json (>= 1.8, < 3)
41
- simplecov (~> 0.12.0)
42
- term-ansicolor (~> 1.3)
43
- thor (~> 0.19.1)
44
- tins (>= 1.6.0, < 2)
45
- docile (1.1.5)
46
- dotenv (2.1.1)
47
- faraday (0.9.2)
48
- multipart-post (>= 1.2, < 3)
49
- faraday_middleware (0.10.0)
50
- faraday (>= 0.7.4, < 0.10)
51
- faraday_middleware-oauth2_refresh (0.0.3)
52
- faraday (~> 0.9, >= 0.9)
53
- faraday_middleware (~> 0, >= 0)
54
- hitimes (1.2.4)
55
- httpclient (2.8.2.2)
56
- json (1.8.3)
57
- jsondoc (0.1.3)
58
- jwt (1.5.4)
59
- logger (1.2.8)
60
- metaclass (0.0.4)
61
- mime (0.4.3)
62
- mime-types (3.1)
63
- mime-types-data (~> 3.2015)
64
- mime-types-data (3.2016.0521)
65
- mime_builder (0.0.3)
66
- mime
67
- mime-types (>= 1.25)
68
- mocha (1.1.0)
69
- metaclass (~> 0.0.1)
70
- multi_json (1.12.1)
71
- multi_xml (0.5.5)
72
- multipart-post (2.0.0)
73
- oauth2 (1.2.0)
74
- faraday (>= 0.8, < 0.10)
75
- jwt (~> 1.0)
76
- multi_json (~> 1.3)
77
- multi_xml (~> 0.5)
78
- rack (>= 1.2, < 3)
79
- power_assert (0.3.0)
80
- pubnub (3.8.2)
81
- celluloid (~> 0.17)
82
- httpclient (~> 2.6)
83
- json (~> 1.8)
84
- rack (2.0.1)
85
- rake (11.2.2)
86
- simplecov (0.12.0)
87
- docile (~> 1.1.0)
88
- json (>= 1.8, < 3)
89
- simplecov-html (~> 0.10.0)
90
- simplecov-html (0.10.0)
91
- term-ansicolor (1.3.2)
92
- tins (~> 1.0)
93
- test-unit (3.2.1)
94
- power_assert
95
- thor (0.19.1)
96
- timers (4.1.1)
97
- hitimes
98
- tins (1.12.0)
99
-
100
- PLATFORMS
101
- ruby
102
-
103
- DEPENDENCIES
104
- coveralls
105
- mocha
106
- rake
107
- ringcentral_sdk!
108
- simplecov
109
- test-unit
110
-
111
- BUNDLED WITH
112
- 1.12.5