wework 0.3.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/README.md +7 -0
- data/lib/wework.rb +15 -10
- data/lib/wework/api/agent.rb +15 -79
- data/lib/wework/api/base.rb +24 -32
- data/lib/wework/api/contact.rb +1 -75
- data/lib/wework/api/corp.rb +29 -0
- data/lib/wework/api/methods/agent.rb +49 -0
- data/lib/wework/api/methods/approval.rb +16 -0
- data/lib/wework/api/methods/batch.rb +34 -0
- data/lib/wework/api/methods/checkin.rb +19 -0
- data/lib/wework/api/methods/department.rb +27 -0
- data/lib/wework/api/methods/media.rb +20 -0
- data/lib/wework/api/methods/menu.rb +21 -0
- data/lib/wework/api/methods/message.rb +52 -0
- data/lib/wework/api/methods/provider.rb +16 -0
- data/lib/wework/api/methods/suite.rb +53 -0
- data/lib/wework/api/methods/user.rb +35 -0
- data/lib/wework/api/provider.rb +13 -0
- data/lib/wework/api/suite.rb +72 -0
- data/lib/wework/cipher.rb +3 -0
- data/lib/wework/mock_api.rb +34 -0
- data/lib/wework/request.rb +3 -1
- data/lib/wework/token/app_token.rb +21 -0
- data/lib/wework/token/base.rb +59 -0
- data/lib/wework/token/corp_token.rb +20 -0
- data/lib/wework/token/js_ticket.rb +25 -0
- data/lib/wework/token/provider_token.rb +21 -0
- data/lib/wework/token/suite_token.rb +21 -0
- data/lib/wework/version.rb +1 -1
- data/mock_responses/agent/get.json +29 -0
- data/mock_responses/agent/list.json +16 -0
- data/mock_responses/agent/set.json +4 -0
- data/mock_responses/batch/getresult.json +8 -0
- data/mock_responses/department/list.json +24 -0
- data/mock_responses/error.json +4 -0
- data/mock_responses/files/party.csv +12 -0
- data/mock_responses/files/sample.amr +0 -0
- data/mock_responses/files/sample.mp4 +0 -0
- data/mock_responses/files/sample.txt +1 -0
- data/mock_responses/files/user.csv +2 -0
- data/mock_responses/files/zhiren.png +0 -0
- data/mock_responses/get_jsapi_ticket.json +6 -0
- data/mock_responses/gettoken.json +6 -0
- data/mock_responses/menu/get.json +24 -0
- data/mock_responses/service/get.json +0 -0
- data/mock_responses/service/get_corp_token.json +4 -0
- data/mock_responses/service/get_login_info.json +34 -0
- data/mock_responses/service/get_permanent_code.json +54 -0
- data/mock_responses/service/get_pre_auth_code.json +6 -0
- data/mock_responses/service/get_provider_token.json +4 -0
- data/mock_responses/service/get_suite_token.json +4 -0
- data/mock_responses/success.json +4 -0
- data/mock_responses/user/convert_to_openid.json +6 -0
- data/mock_responses/user/convert_to_userid.json +5 -0
- data/mock_responses/user/get.json +18 -0
- data/mock_responses/user/getuserdetail.json +10 -0
- data/mock_responses/user/getuserinfo.json +8 -0
- data/mock_responses/user/list.json +22 -0
- data/mock_responses/user/simplelist.json +11 -0
- data/wework.gemspec +6 -2
- metadata +114 -19
- data/lib/wework/engine.rb +0 -31
- data/lib/wework/js_ticket/redis_store.rb +0 -41
- data/lib/wework/js_ticket/store.rb +0 -36
- data/lib/wework/provider.rb +0 -39
- data/lib/wework/token/redis_store.rb +0 -41
- data/lib/wework/token/store.rb +0 -36
data/lib/wework/provider.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module Wework
|
2
|
-
class Provider
|
3
|
-
include Wework::Cipher
|
4
|
-
|
5
|
-
attr_accessor :corp_id, :provider_secret, :encoding_aes_key, :token
|
6
|
-
|
7
|
-
def initialize(options={})
|
8
|
-
@corp_id = options[:corp_id]
|
9
|
-
@provider_secret = options[:provider_secret]
|
10
|
-
@encoding_aes_key = options[:encoding_aes_key]
|
11
|
-
@token = options[:token]
|
12
|
-
end
|
13
|
-
|
14
|
-
def msg_decrypt msg
|
15
|
-
unpack(decrypt(Base64.decode64(msg), self.encoding_aes_key))[0]
|
16
|
-
end
|
17
|
-
|
18
|
-
def msg_encrypt msg
|
19
|
-
Base64.strict_encode64(encrypt(pack(msg, self.corp_id), self.encoding_aes_key))
|
20
|
-
end
|
21
|
-
|
22
|
-
def signature(timestamp, nonce, encrypt)
|
23
|
-
array = [self.token, timestamp, nonce]
|
24
|
-
array << encrypt unless encrypt.nil?
|
25
|
-
dev_msg_signature = array.compact.collect(&:to_s).sort.join
|
26
|
-
Digest::SHA1.hexdigest(dev_msg_signature)
|
27
|
-
end
|
28
|
-
|
29
|
-
def generate_xml(msg, timestamp, nonce)
|
30
|
-
encrypt = msg_encrypt(msg)
|
31
|
-
{
|
32
|
-
Encrypt: encrypt,
|
33
|
-
MsgSignature: signature(timestamp, nonce, encrypt),
|
34
|
-
TimeStamp: timestamp,
|
35
|
-
Nonce: nonce
|
36
|
-
}.to_xml(root: 'xml', children: 'item', skip_instruct: true, skip_types: true)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Wework
|
2
|
-
module Token
|
3
|
-
class RedisStore < Store
|
4
|
-
|
5
|
-
def initialize(agent)
|
6
|
-
raise RedisNotConfigException if redis.nil?
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def access_token
|
11
|
-
super
|
12
|
-
redis.hget(key, "access_token")
|
13
|
-
end
|
14
|
-
|
15
|
-
def expired?
|
16
|
-
redis.hvals(key).empty? || redis.hget(key, "expires_at").to_i <= Time.now.to_i
|
17
|
-
end
|
18
|
-
|
19
|
-
def refresh_token
|
20
|
-
result = super
|
21
|
-
unless result.access_token.nil?
|
22
|
-
expires_at = Time.now.to_i + result.expires_in.to_i - Wework.expired_shift_seconds
|
23
|
-
redis.hmset(
|
24
|
-
key,
|
25
|
-
"access_token", result.access_token,
|
26
|
-
"expires_at", expires_at
|
27
|
-
)
|
28
|
-
|
29
|
-
redis.expireat(key, expires_at)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def redis
|
36
|
-
Wework.redis
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/lib/wework/token/store.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module Wework
|
2
|
-
module Token
|
3
|
-
class Store
|
4
|
-
|
5
|
-
attr_accessor :app
|
6
|
-
|
7
|
-
def initialize(app)
|
8
|
-
@app = app
|
9
|
-
end
|
10
|
-
|
11
|
-
def access_token
|
12
|
-
refresh_token if expired?
|
13
|
-
end
|
14
|
-
|
15
|
-
def expired?
|
16
|
-
raise NotImplementedError, "Subclasses must implement a token_expired? method"
|
17
|
-
end
|
18
|
-
|
19
|
-
def refresh_token
|
20
|
-
result = app.request.get 'gettoken', params: {corpid: app.corp_id, corpsecret: app.app_secret}
|
21
|
-
if defined?(Rails)
|
22
|
-
Rails.logger.warn "[WEWORK] refresh Token(#{app.corp_id}): #{result.inspect}"
|
23
|
-
end
|
24
|
-
|
25
|
-
result
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def key
|
31
|
-
@key ||= Digest::MD5.hexdigest("#{ACCESS_TOKEN_PREFIX}_#{app.app_id}_#{app.app_secret}")
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|