Class: Keen::ScopedKey

Inherits:
Object
  • Object
show all
Defined in:
lib/keen/scoped_key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, data) ⇒ ScopedKey

Returns a new instance of ScopedKey.



23
24
25
26
# File 'lib/keen/scoped_key.rb', line 23

def initialize(api_key, data)
  self.api_key = api_key
  self.data = data
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/keen/scoped_key.rb', line 8

def api_key
  @api_key
end

#dataObject

Returns the value of attribute data.



9
10
11
# File 'lib/keen/scoped_key.rb', line 9

def data
  @data
end

Class Method Details

.decrypt!(api_key, scoped_key) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/keen/scoped_key.rb', line 12

def decrypt!(api_key, scoped_key)
  if api_key.length == 64
    decrypted = Keen::AESHelper.aes256_decrypt(api_key, scoped_key)
  else
    decrypted = Keen::AESHelperOld.aes256_decrypt(api_key, scoped_key)
  end
  data = MultiJson.load(decrypted)
  self.new(api_key, data)
end

Instance Method Details

#encrypt!(iv = nil) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/keen/scoped_key.rb', line 28

def encrypt!(iv = nil)
  json_str = MultiJson.dump(self.data)
  if self.api_key.length == 64
    Keen::AESHelper.aes256_encrypt(self.api_key, json_str, iv)
  else
    Keen::AESHelperOld.aes256_encrypt(self.api_key, json_str, iv)
  end
end