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/request.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Reference this: https://github.com/Eric-Guo/wechat/blob/master/lib/wechat/http_client.rb
|
2
2
|
require 'http'
|
3
|
+
require 'wework/global_code'
|
3
4
|
|
4
5
|
module Wework
|
5
6
|
class Request
|
@@ -51,6 +52,7 @@ module Wework
|
|
51
52
|
parse_response(response, as || :json) do |parse_as, data|
|
52
53
|
break data unless parse_as == :json
|
53
54
|
result = Wework::Result.new(data)
|
55
|
+
Rails.logger.info "[WEWORK] request path(#{url_base}#{path}): #{result.inspect}" if defined?(Rails)
|
54
56
|
raise AccessTokenExpiredError if result.token_expired?
|
55
57
|
result
|
56
58
|
end
|
@@ -96,7 +98,7 @@ module Wework
|
|
96
98
|
end
|
97
99
|
|
98
100
|
def throw_error
|
99
|
-
raise ResultErrorException.new(
|
101
|
+
raise ResultErrorException.new(full_message) unless success?
|
100
102
|
end
|
101
103
|
|
102
104
|
def success?
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'wework/token/base'
|
2
|
+
|
3
|
+
module Wework
|
4
|
+
module Token
|
5
|
+
class AppToken < Base
|
6
|
+
|
7
|
+
def redis_key
|
8
|
+
@redis_key ||= Digest::MD5.hexdigest "WX_APP_TOKEN_#{client.corp_id}_#{client.secret}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def token_key
|
12
|
+
'access_token'
|
13
|
+
end
|
14
|
+
|
15
|
+
def refresh_token
|
16
|
+
client.request.get 'gettoken', params: {corpid: client.corp_id, corpsecret: client.secret}
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Wework
|
2
|
+
module Token
|
3
|
+
class Base
|
4
|
+
attr_accessor :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
raise RedisNotConfigException if redis.nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
def token
|
12
|
+
update_token if expired?
|
13
|
+
redis.hget(redis_key, token_key)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_token
|
17
|
+
result = refresh_token
|
18
|
+
value = result.send(token_key)
|
19
|
+
if value.nil?
|
20
|
+
puts "#{self.class.name} refresh token error: #{result.inspect}"
|
21
|
+
else
|
22
|
+
expires_at = Time.now.to_i + result.expires_in.to_i - Wework.expired_shift_seconds
|
23
|
+
|
24
|
+
redis.hmset(
|
25
|
+
redis_key,
|
26
|
+
token_key, value,
|
27
|
+
"expires_at", expires_at
|
28
|
+
)
|
29
|
+
|
30
|
+
redis.expireat(redis_key, expires_at)
|
31
|
+
end
|
32
|
+
|
33
|
+
value
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def redis
|
39
|
+
Wework.redis
|
40
|
+
end
|
41
|
+
|
42
|
+
def redis_key
|
43
|
+
raise NotImplementedError
|
44
|
+
end
|
45
|
+
|
46
|
+
def token_key
|
47
|
+
raise NotImplementedError
|
48
|
+
end
|
49
|
+
|
50
|
+
def refresh_token
|
51
|
+
raise NotImplementedError
|
52
|
+
end
|
53
|
+
|
54
|
+
def expired?
|
55
|
+
redis.hvals(redis_key).empty? || redis.hget(redis_key, 'expires_at').to_i <= Time.now.to_i
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'wework/token/base'
|
2
|
+
|
3
|
+
module Wework
|
4
|
+
module Token
|
5
|
+
class CorpToken < Base
|
6
|
+
|
7
|
+
def redis_key
|
8
|
+
@redis_key ||= Digest::MD5.hexdigest "WX_CORP_TOKEN_#{client.corp_id}_#{client.permanent_code}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def token_key
|
12
|
+
'access_token'
|
13
|
+
end
|
14
|
+
|
15
|
+
def refresh_token
|
16
|
+
client.suite.get_corp_token(client.corp_id, client.permanent_code)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'wework/token/base'
|
2
|
+
|
3
|
+
require 'wework/token/base'
|
4
|
+
|
5
|
+
module Wework
|
6
|
+
module Token
|
7
|
+
class JsTicket < Base
|
8
|
+
|
9
|
+
alias_method :ticket, :token
|
10
|
+
|
11
|
+
def redis_key
|
12
|
+
@redis_key ||= Digest::MD5.hexdigest "WX_JS_TICKET_#{client.corp_id}_#{client.agent_id}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def token_key
|
16
|
+
'ticket'
|
17
|
+
end
|
18
|
+
|
19
|
+
def refresh_token
|
20
|
+
client.get 'get_jsapi_ticket'
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'wework/token/base'
|
2
|
+
|
3
|
+
module Wework
|
4
|
+
module Token
|
5
|
+
class ProviderToken < Base
|
6
|
+
|
7
|
+
def redis_key
|
8
|
+
@redis_key ||= Digest::MD5.hexdigest "WX_PROVIDER_TOKEN_#{client.corp_id}_#{client.secret}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def token_key
|
12
|
+
'provider_access_token'
|
13
|
+
end
|
14
|
+
|
15
|
+
def refresh_token
|
16
|
+
client.request.post 'service/get_provider_token', {corpid: client.corp_id, provider_secret: client.secret}
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'wework/token/base'
|
2
|
+
|
3
|
+
module Wework
|
4
|
+
module Token
|
5
|
+
class SuiteToken < Base
|
6
|
+
|
7
|
+
def redis_key
|
8
|
+
@redis_key ||= Digest::MD5.hexdigest "WX_SUITE_TOKEN_#{client.suite_id}_#{client.suite_secret}_#{client.suite_token}"
|
9
|
+
end
|
10
|
+
|
11
|
+
def token_key
|
12
|
+
'suite_access_token'
|
13
|
+
end
|
14
|
+
|
15
|
+
def refresh_token
|
16
|
+
client.request.post 'service/get_suite_token', {suite_id: client.suite_id, suite_secret: client.suite_secret, suite_ticket: client.suite_ticket}
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/wework/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"errcode":0,
|
3
|
+
"errmsg": "ok",
|
4
|
+
"agentid": "1",
|
5
|
+
"name": "NAME",
|
6
|
+
"square_logo_url": "xxxxxxxx",
|
7
|
+
"description": "desc",
|
8
|
+
"allow_userinfos": {
|
9
|
+
"user":[
|
10
|
+
{
|
11
|
+
"userid":"id2"
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"userid":"id3"
|
15
|
+
}
|
16
|
+
]
|
17
|
+
},
|
18
|
+
"allow_partys":{
|
19
|
+
"partyid": [1]
|
20
|
+
},
|
21
|
+
"allow_tags":{
|
22
|
+
"tagid": [1,2,3]
|
23
|
+
},
|
24
|
+
"close": 0,
|
25
|
+
"redirect_domain": "www.qq.com",
|
26
|
+
"report_location_flag": 0,
|
27
|
+
"isreportenter": 0,
|
28
|
+
"home_url": "http://www.qq.com"
|
29
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
"errcode": 0,
|
3
|
+
"errmsg": "ok",
|
4
|
+
"department": [
|
5
|
+
{
|
6
|
+
"id": 1,
|
7
|
+
"name": "杭州知人",
|
8
|
+
"parentid": 0,
|
9
|
+
"order": 10
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"id": 2,
|
13
|
+
"name": "广州研发中心",
|
14
|
+
"parentid": 1,
|
15
|
+
"order": 11
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"id": 3,
|
19
|
+
"name": "邮箱产品部",
|
20
|
+
"parentid": 2,
|
21
|
+
"order": 12
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
Wework is a ruby API wrapper for work wechat
|
Binary file
|
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
"button":[
|
3
|
+
{
|
4
|
+
"type":"click",
|
5
|
+
"name":"今日歌曲",
|
6
|
+
"key":"V1001_TODAY_MUSIC"
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"name":"菜单",
|
10
|
+
"sub_button":[
|
11
|
+
{
|
12
|
+
"type":"view",
|
13
|
+
"name":"搜索",
|
14
|
+
"url":"http://www.soso.com/"
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"type":"click",
|
18
|
+
"name":"赞一下我们",
|
19
|
+
"key":"V1001_GOOD"
|
20
|
+
}
|
21
|
+
]
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}
|
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
{
|
2
|
+
"usertype": 1,
|
3
|
+
"user_info": {
|
4
|
+
"userid": "xxxx",
|
5
|
+
"name": "xxxx",
|
6
|
+
"avatar": "xxxx",
|
7
|
+
"email": "xxxx"
|
8
|
+
},
|
9
|
+
"corp_info": {
|
10
|
+
"corpid": "wx6c698d13f7a409a4"
|
11
|
+
},
|
12
|
+
"agent": [
|
13
|
+
{
|
14
|
+
"agentid": 0,
|
15
|
+
"auth_type": 1
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"agentid": 1,
|
19
|
+
"auth_type": 1
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"agentid": 2,
|
23
|
+
"auth_type": 1
|
24
|
+
}
|
25
|
+
],
|
26
|
+
"auth_info": {
|
27
|
+
"department": [
|
28
|
+
{
|
29
|
+
"id": "2",
|
30
|
+
"writable": "true"
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
{
|
2
|
+
"access_token": "xxxxxx",
|
3
|
+
"expires_in": 7200,
|
4
|
+
"permanent_code": "xxxx",
|
5
|
+
"auth_corp_info":
|
6
|
+
{
|
7
|
+
"corpid": "xxxx",
|
8
|
+
"corp_name": "name",
|
9
|
+
"corp_type": "verified",
|
10
|
+
"corp_square_logo_url": "yyyyy",
|
11
|
+
"corp_user_max": 50,
|
12
|
+
"corp_agent_max": 30,
|
13
|
+
"corp_full_name":"full_name",
|
14
|
+
"verified_end_time":1431775834,
|
15
|
+
"subject_type": 1,
|
16
|
+
"corp_wxqrcode": "zzzzz"
|
17
|
+
},
|
18
|
+
"auth_info":
|
19
|
+
{
|
20
|
+
"agent" :
|
21
|
+
[
|
22
|
+
{
|
23
|
+
"agentid":1,
|
24
|
+
"name":"NAME",
|
25
|
+
"round_logo_url":"xxxxxx",
|
26
|
+
"square_logo_url":"yyyyyy",
|
27
|
+
"appid":1,
|
28
|
+
"privilege":
|
29
|
+
{
|
30
|
+
"level":1,
|
31
|
+
"allow_party":[1,2,3],
|
32
|
+
"allow_user":["zhansan","lisi"],
|
33
|
+
"allow_tag":[1,2,3],
|
34
|
+
"extra_party":[4,5,6],
|
35
|
+
"extra_user":["wangwu"],
|
36
|
+
"extra_tag":[4,5,6]
|
37
|
+
}
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"agentid":2,
|
41
|
+
"name":"NAME2",
|
42
|
+
"round_logo_url":"xxxxxx",
|
43
|
+
"square_logo_url":"yyyyyy",
|
44
|
+
"appid":5
|
45
|
+
}
|
46
|
+
]
|
47
|
+
},
|
48
|
+
"auth_user_info":
|
49
|
+
{
|
50
|
+
"email":"xxxx@aaa.com",
|
51
|
+
"mobile":"1234567890",
|
52
|
+
"userid":"aa"
|
53
|
+
}
|
54
|
+
}
|