Class: Wework::Api::Suite

Inherits:
Base
  • Object
show all
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

Attributes inherited from Base

#corp_id, #options, #secret

Instance Method Summary collapse

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(options={})
  @suite_id = options.delete(:suite_id)
  @suite_secret = options.delete(:suite_secret)
  @suite_token = options.delete(:suite_token)
  @encoding_aes_key = options.delete(:encoding_aes_key)
  super(options)
end

Instance Attribute Details

#encoding_aes_keyObject (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_idObject (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_secretObject (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_tokenObject (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, timestamp, nonce)
  encrypt = msg_encrypt(msg)
  {
    Encrypt: encrypt,
    MsgSignature: signature(timestamp, nonce, encrypt),
    TimeStamp: 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 message
  unpack(decrypt(Base64.decode64(message), encoding_aes_key))[0]
end

#msg_encrypt(message) ⇒ Object



24
25
26
# File 'lib/wework/api/suite.rb', line 24

def msg_encrypt message
  Base64.strict_encode64(encrypt(pack(message, 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(timestamp, nonce, encrypt)
  array = [suite_token, timestamp, nonce]
  array << encrypt unless encrypt.nil?
  Digest::SHA1.hexdigest array.compact.collect(&:to_s).sort.join
end

#suite_ticketObject



48
49
50
# File 'lib/wework/api/suite.rb', line 48

def suite_ticket
  Wework.redis.get ticket_key
end

#suite_ticket=(ticket) ⇒ Object



44
45
46
# File 'lib/wework/api/suite.rb', line 44

def suite_ticket= ticket
  Wework.redis.set ticket_key, ticket
end