Class: Wework::Provider
- Inherits:
-
Object
- Object
- Wework::Provider
- Includes:
- Cipher
- Defined in:
- lib/wework/provider.rb
Constant Summary
Constants included from Cipher
Cipher::BLOCK_SIZE, Cipher::CIPHER
Instance Attribute Summary collapse
-
#corp_id ⇒ Object
Returns the value of attribute corp_id.
-
#encoding_aes_key ⇒ Object
Returns the value of attribute encoding_aes_key.
-
#provider_secret ⇒ Object
Returns the value of attribute provider_secret.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #generate_xml(msg, timestamp, nonce) ⇒ Object
-
#initialize(options = {}) ⇒ Provider
constructor
A new instance of Provider.
- #msg_decrypt(msg) ⇒ Object
- #msg_encrypt(msg) ⇒ Object
- #signature(timestamp, nonce, encrypt) ⇒ Object
Methods included from Cipher
#decrypt, #encrypt, #pack, #unpack
Constructor Details
#initialize(options = {}) ⇒ Provider
7 8 9 10 11 12 |
# File 'lib/wework/provider.rb', line 7 def initialize(={}) @corp_id = [:corp_id] @provider_secret = [:provider_secret] @encoding_aes_key = [:encoding_aes_key] @token = [:token] end |
Instance Attribute Details
#corp_id ⇒ Object
Returns the value of attribute corp_id.
5 6 7 |
# File 'lib/wework/provider.rb', line 5 def corp_id @corp_id end |
#encoding_aes_key ⇒ Object
Returns the value of attribute encoding_aes_key.
5 6 7 |
# File 'lib/wework/provider.rb', line 5 def encoding_aes_key @encoding_aes_key end |
#provider_secret ⇒ Object
Returns the value of attribute provider_secret.
5 6 7 |
# File 'lib/wework/provider.rb', line 5 def provider_secret @provider_secret end |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/wework/provider.rb', line 5 def token @token end |
Instance Method Details
#generate_xml(msg, timestamp, nonce) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/wework/provider.rb', line 29 def generate_xml(msg, , nonce) encrypt = msg_encrypt(msg) { Encrypt: encrypt, MsgSignature: signature(, nonce, encrypt), TimeStamp: , Nonce: nonce }.to_xml(root: 'xml', children: 'item', skip_instruct: true, skip_types: true) end |
#msg_decrypt(msg) ⇒ Object
14 15 16 |
# File 'lib/wework/provider.rb', line 14 def msg_decrypt msg unpack(decrypt(Base64.decode64(msg), self.encoding_aes_key))[0] end |
#msg_encrypt(msg) ⇒ Object
18 19 20 |
# File 'lib/wework/provider.rb', line 18 def msg_encrypt msg Base64.strict_encode64(encrypt(pack(msg, self.corp_id), self.encoding_aes_key)) end |
#signature(timestamp, nonce, encrypt) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/wework/provider.rb', line 22 def signature(, nonce, encrypt) array = [self.token, , nonce] array << encrypt unless encrypt.nil? dev_msg_signature = array.compact.collect(&:to_s).sort.join Digest::SHA1.hexdigest(dev_msg_signature) end |