Class: Wework::Api::Suite
- Includes:
- Methods::Suite, Cipher
- Defined in:
- lib/wework/api/suite.rb
Constant Summary
Constants included from Cipher
Cipher::BLOCK_SIZE, Cipher::CIPHER
Instance Attribute Summary collapse
-
#encoding_aes_key ⇒ Object
readonly
Returns the value of attribute encoding_aes_key.
-
#suite_id ⇒ Object
readonly
Returns the value of attribute suite_id.
-
#suite_secret ⇒ Object
readonly
Returns the value of attribute suite_secret.
-
#suite_token ⇒ Object
readonly
Returns the value of attribute suite_token.
Attributes inherited from Base
Instance Method Summary collapse
- #corp(corp_id, permanent_code) ⇒ Object
- #generate_xml(msg, timestamp, nonce) ⇒ Object
-
#initialize(options = {}) ⇒ Suite
constructor
A new instance of Suite.
- #msg_decrypt(message) ⇒ Object
- #msg_encrypt(message) ⇒ Object
- #signature(timestamp, nonce, encrypt) ⇒ Object
- #suite_ticket ⇒ Object
- #suite_ticket=(ticket) ⇒ Object
Methods included from Methods::Suite
#authorize_url, #corp_authorize_url, #get_admin_list, #get_auth_info, #get_corp_token, #get_oauth_userinfo, #get_permanent_code, #get_pre_auth_code, #get_session_with_jscode, #get_user_detail, #set_session_info
Methods included from Cipher
#decrypt, #encrypt, #pack, #unpack
Methods inherited from Base
#access_token, #get, #post, #post_file, #request, #valid?
Methods included from Methods::Department
#department_create, #department_delete, #department_list, #department_update
Methods included from Methods::User
#user_batchdelete, #user_create, #user_delete, #user_get, #user_list, #user_simplelist, #user_update
Methods included from Methods::Media
#get_media_url, #media_get, #media_upload
Constructor Details
#initialize(options = {}) ⇒ Suite
Returns a new instance of Suite.
12 13 14 15 16 17 18 |
# File 'lib/wework/api/suite.rb', line 12 def initialize(={}) @suite_id = .delete(:suite_id) @suite_secret = .delete(:suite_secret) @suite_token = .delete(:suite_token) @encoding_aes_key = .delete(:encoding_aes_key) super() end |
Instance Attribute Details
#encoding_aes_key ⇒ Object (readonly)
Returns the value of attribute encoding_aes_key.
10 11 12 |
# File 'lib/wework/api/suite.rb', line 10 def encoding_aes_key @encoding_aes_key end |
#suite_id ⇒ Object (readonly)
Returns the value of attribute suite_id.
10 11 12 |
# File 'lib/wework/api/suite.rb', line 10 def suite_id @suite_id end |
#suite_secret ⇒ Object (readonly)
Returns the value of attribute suite_secret.
10 11 12 |
# File 'lib/wework/api/suite.rb', line 10 def suite_secret @suite_secret end |
#suite_token ⇒ Object (readonly)
Returns the value of attribute suite_token.
10 11 12 |
# File 'lib/wework/api/suite.rb', line 10 def suite_token @suite_token end |
Instance Method Details
#corp(corp_id, permanent_code) ⇒ Object
52 53 54 |
# File 'lib/wework/api/suite.rb', line 52 def corp(corp_id, permanent_code) Wework::Api::Corp.new(suite: self, corp_id: corp_id, permanent_code: permanent_code) end |
#generate_xml(msg, timestamp, nonce) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/wework/api/suite.rb', line 34 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(message) ⇒ Object
20 21 22 |
# File 'lib/wework/api/suite.rb', line 20 def msg_decrypt unpack(decrypt(Base64.decode64(), encoding_aes_key))[0] end |
#msg_encrypt(message) ⇒ Object
24 25 26 |
# File 'lib/wework/api/suite.rb', line 24 def msg_encrypt Base64.strict_encode64(encrypt(pack(, corp_id), encoding_aes_key)) end |
#signature(timestamp, nonce, encrypt) ⇒ Object
28 29 30 31 32 |
# File 'lib/wework/api/suite.rb', line 28 def signature(, nonce, encrypt) array = [suite_token, , nonce] array << encrypt unless encrypt.nil? Digest::SHA1.hexdigest array.compact.collect(&:to_s).sort.join end |