ringcentral-sdk 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/subscription.rb +18 -6
- data/ringcentral-sdk.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74403294f6706daa698a0dc6e079c8f32786eb3a
|
4
|
+
data.tar.gz: ca292de945b064added3734ca38c861d1f22bbe1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 969e4771863da2fdedda6c518fa8cbd56d01a048b5eaa6e65ceb028572236a44c4f13b8e520b883d9f3ef3fd234c4f537e490bc8753e8bd18cc33a0f42d6f205
|
7
|
+
data.tar.gz: b1f1269490113051cf9eb88f770a8b7daf4abfdd90367a2328a9ca1c11585773ea809d36237fc216a47019404e62fd2c10ae98fdec017053c626a01529baf864
|
data/lib/subscription.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'pubnub'
|
2
2
|
require 'concurrent'
|
3
|
+
require 'openssl'
|
4
|
+
require 'base64'
|
3
5
|
|
4
6
|
class Subscription
|
5
7
|
attr_accessor :events
|
@@ -8,15 +10,25 @@ class Subscription
|
|
8
10
|
@rc = ringcentral
|
9
11
|
@events = events
|
10
12
|
@callback = Pubnub::SubscribeCallback.new(
|
11
|
-
message:
|
12
|
-
|
13
|
-
|
13
|
+
message: lambda { |envelope|
|
14
|
+
message = envelope.result[:data][:message]
|
15
|
+
cipher = OpenSSL::Cipher::AES.new(128, :ECB)
|
16
|
+
cipher.decrypt
|
17
|
+
cipher.key = Base64.decode64(@subscription['deliveryMode']['encryptionKey'])
|
18
|
+
ciphertext = Base64.decode64(message)
|
19
|
+
plaintext = cipher.update(ciphertext) + cipher.final
|
20
|
+
message_callback.call(JSON.parse(plaintext))
|
14
21
|
},
|
15
|
-
presence:
|
16
|
-
|
22
|
+
presence: lambda { |envelope|
|
23
|
+
presence_callback != nil && presence_callback.call(envelope)
|
24
|
+
},
|
25
|
+
status: lambda { |envelope|
|
26
|
+
status_callback != nil && status_callback.call(envelope)
|
27
|
+
}
|
17
28
|
)
|
18
29
|
@subscription = nil
|
19
30
|
@timer = nil
|
31
|
+
@pubnub = nil
|
20
32
|
end
|
21
33
|
|
22
34
|
def subscription=(value)
|
@@ -38,7 +50,7 @@ class Subscription
|
|
38
50
|
self.subscription = JSON.parse(r.body)
|
39
51
|
@pubnub = Pubnub.new(subscribe_key: @subscription['deliveryMode']['subscriberKey'])
|
40
52
|
@pubnub.add_listener(callback: @callback)
|
41
|
-
@pubnub.subscribe(
|
53
|
+
@pubnub.subscribe(channels: @subscription['deliveryMode']['address'])
|
42
54
|
end
|
43
55
|
|
44
56
|
def refresh
|
data/ringcentral-sdk.gemspec
CHANGED