ringcentral-sdk 0.2.1 → 0.2.2

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: f05987bc7911b539c714d03db8541a64f9952875
4
- data.tar.gz: af9b7d5e38f3d7c639f5d872b01e5a8367183c37
3
+ metadata.gz: 74403294f6706daa698a0dc6e079c8f32786eb3a
4
+ data.tar.gz: ca292de945b064added3734ca38c861d1f22bbe1
5
5
  SHA512:
6
- metadata.gz: c64088595d4936f4714dac813a8eba9fb5614a44d2f9e19a7533e6ff4b5f0f88998fcac2aa2f21420b62d76eb2efb218f4138008743d87e442b1ba466ed390f0
7
- data.tar.gz: ef5e6248621cc31bdc8607d1d3cfcdcddd7bfa49bcc09c0b91f2e144275e4c508aed061cd71813e7d68883b78dee5ee2c0d468a5cdb6ece18e5d4231add7a31c
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: ->(envelope) {
12
- # todo: decrypt the message
13
- message_callback(envelope)
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: ->(envelope) { presence_callback != nil && presence_callback(presence) },
16
- status: ->(envelope) { status_callback != nil && status_callback(envelope) }
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(channel: @subscription['deliveryMode']['address'])
53
+ @pubnub.subscribe(channels: @subscription['deliveryMode']['address'])
42
54
  end
43
55
 
44
56
  def refresh
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'ringcentral-sdk'
3
- gem.version = '0.2.1'
3
+ gem.version = '0.2.2'
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.'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ringcentral-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Liu