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
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"errcode": 0,
|
3
|
+
"errmsg": "ok",
|
4
|
+
"userid": "zhangsan",
|
5
|
+
"name": "李四",
|
6
|
+
"department": [1, 2],
|
7
|
+
"order": [1, 2],
|
8
|
+
"position": "后台工程师",
|
9
|
+
"mobile": "15913215421",
|
10
|
+
"gender": "1",
|
11
|
+
"email": "zhangsan@gzdev.com",
|
12
|
+
"isleader": 1,
|
13
|
+
"avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0",
|
14
|
+
"telephone": "020-123456",
|
15
|
+
"english_name": "jackzhang",
|
16
|
+
"extattr": {"attrs":[{"name":"爱好","value":"旅游"},{"name":"卡号","value":"1234567234"}]},
|
17
|
+
"status": 1
|
18
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"errcode": 0,
|
3
|
+
"errmsg": "ok",
|
4
|
+
"userlist": [
|
5
|
+
{
|
6
|
+
"userid": "zhangsan",
|
7
|
+
"name": "李四",
|
8
|
+
"department": [1, 2],
|
9
|
+
"order": [1, 2],
|
10
|
+
"position": "后台工程师",
|
11
|
+
"mobile": "15913215421",
|
12
|
+
"gender": "1",
|
13
|
+
"email": "zhangsan@gzdev.com",
|
14
|
+
"isleader": 0,
|
15
|
+
"avatar": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0",
|
16
|
+
"telephone": "020-123456",
|
17
|
+
"english_name": "jackzhang",
|
18
|
+
"status": 1,
|
19
|
+
"extattr": {"attrs":[{"name":"爱好","value":"旅游"},{"name":"卡号","value":"1234567234"}]}
|
20
|
+
}
|
21
|
+
]
|
22
|
+
}
|
data/wework.gemspec
CHANGED
@@ -20,11 +20,15 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_dependency 'http', '>=
|
23
|
+
spec.add_dependency 'http', '>= 2.2'
|
24
24
|
spec.add_dependency 'activesupport', '~> 5.0'
|
25
|
-
spec.add_dependency 'redis', '~>3.
|
25
|
+
spec.add_dependency 'redis', '~>3.3'
|
26
|
+
spec.add_dependency 'builder', '~> 3.2.2'
|
27
|
+
spec.add_dependency 'sinatra', '~>2.0.0'
|
26
28
|
|
27
29
|
spec.add_development_dependency "bundler", "~> 1.13"
|
28
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
31
|
spec.add_development_dependency "minitest", "~> 5.10"
|
32
|
+
spec.add_development_dependency 'webmock', '~> 3.4.1'
|
33
|
+
spec.add_development_dependency 'mock_redis', '~>0.18.0'
|
30
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- seandong
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -16,20 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '3'
|
19
|
+
version: '2.2'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '3'
|
26
|
+
version: '2.2'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: activesupport
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,14 +44,42 @@ dependencies:
|
|
50
44
|
requirements:
|
51
45
|
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '3.
|
47
|
+
version: '3.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: builder
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.2.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.0
|
54
76
|
type: :runtime
|
55
77
|
prerelease: false
|
56
78
|
version_requirements: !ruby/object:Gem::Requirement
|
57
79
|
requirements:
|
58
80
|
- - "~>"
|
59
81
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
82
|
+
version: 2.0.0
|
61
83
|
- !ruby/object:Gem::Dependency
|
62
84
|
name: bundler
|
63
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,6 +122,34 @@ dependencies:
|
|
100
122
|
- - "~>"
|
101
123
|
- !ruby/object:Gem::Version
|
102
124
|
version: '5.10'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.4.1
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.4.1
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: mock_redis
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.18.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.18.0
|
103
153
|
description: Ruby API wrapper for work wechat.
|
104
154
|
email:
|
105
155
|
- sindon@gmail.com
|
@@ -120,17 +170,62 @@ files:
|
|
120
170
|
- lib/wework/api/agent.rb
|
121
171
|
- lib/wework/api/base.rb
|
122
172
|
- lib/wework/api/contact.rb
|
173
|
+
- lib/wework/api/corp.rb
|
174
|
+
- lib/wework/api/methods/agent.rb
|
175
|
+
- lib/wework/api/methods/approval.rb
|
176
|
+
- lib/wework/api/methods/batch.rb
|
177
|
+
- lib/wework/api/methods/checkin.rb
|
178
|
+
- lib/wework/api/methods/department.rb
|
179
|
+
- lib/wework/api/methods/media.rb
|
180
|
+
- lib/wework/api/methods/menu.rb
|
181
|
+
- lib/wework/api/methods/message.rb
|
182
|
+
- lib/wework/api/methods/provider.rb
|
183
|
+
- lib/wework/api/methods/suite.rb
|
184
|
+
- lib/wework/api/methods/user.rb
|
185
|
+
- lib/wework/api/provider.rb
|
186
|
+
- lib/wework/api/suite.rb
|
123
187
|
- lib/wework/cipher.rb
|
124
188
|
- lib/wework/config.rb
|
125
|
-
- lib/wework/engine.rb
|
126
189
|
- lib/wework/global_code.rb
|
127
|
-
- lib/wework/
|
128
|
-
- lib/wework/js_ticket/store.rb
|
129
|
-
- lib/wework/provider.rb
|
190
|
+
- lib/wework/mock_api.rb
|
130
191
|
- lib/wework/request.rb
|
131
|
-
- lib/wework/token/
|
132
|
-
- lib/wework/token/
|
192
|
+
- lib/wework/token/app_token.rb
|
193
|
+
- lib/wework/token/base.rb
|
194
|
+
- lib/wework/token/corp_token.rb
|
195
|
+
- lib/wework/token/js_ticket.rb
|
196
|
+
- lib/wework/token/provider_token.rb
|
197
|
+
- lib/wework/token/suite_token.rb
|
133
198
|
- lib/wework/version.rb
|
199
|
+
- mock_responses/agent/get.json
|
200
|
+
- mock_responses/agent/list.json
|
201
|
+
- mock_responses/agent/set.json
|
202
|
+
- mock_responses/batch/getresult.json
|
203
|
+
- mock_responses/department/list.json
|
204
|
+
- mock_responses/error.json
|
205
|
+
- mock_responses/files/party.csv
|
206
|
+
- mock_responses/files/sample.amr
|
207
|
+
- mock_responses/files/sample.mp4
|
208
|
+
- mock_responses/files/sample.txt
|
209
|
+
- mock_responses/files/user.csv
|
210
|
+
- mock_responses/files/zhiren.png
|
211
|
+
- mock_responses/get_jsapi_ticket.json
|
212
|
+
- mock_responses/gettoken.json
|
213
|
+
- mock_responses/menu/get.json
|
214
|
+
- mock_responses/service/get.json
|
215
|
+
- mock_responses/service/get_corp_token.json
|
216
|
+
- mock_responses/service/get_login_info.json
|
217
|
+
- mock_responses/service/get_permanent_code.json
|
218
|
+
- mock_responses/service/get_pre_auth_code.json
|
219
|
+
- mock_responses/service/get_provider_token.json
|
220
|
+
- mock_responses/service/get_suite_token.json
|
221
|
+
- mock_responses/success.json
|
222
|
+
- mock_responses/user/convert_to_openid.json
|
223
|
+
- mock_responses/user/convert_to_userid.json
|
224
|
+
- mock_responses/user/get.json
|
225
|
+
- mock_responses/user/getuserdetail.json
|
226
|
+
- mock_responses/user/getuserinfo.json
|
227
|
+
- mock_responses/user/list.json
|
228
|
+
- mock_responses/user/simplelist.json
|
134
229
|
- wework.gemspec
|
135
230
|
homepage: https://github.com/mycolorway/wework
|
136
231
|
licenses:
|
@@ -152,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
247
|
version: '0'
|
153
248
|
requirements: []
|
154
249
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
250
|
+
rubygems_version: 2.7.6
|
156
251
|
signing_key:
|
157
252
|
specification_version: 4
|
158
253
|
summary: Ruby API wrapper for work wechat.
|
data/lib/wework/engine.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Wework
|
2
|
-
class Engine
|
3
|
-
|
4
|
-
attr_reader :corp_id, :corp_secret, :app_id, :app_secret
|
5
|
-
|
6
|
-
def initialize(options={})
|
7
|
-
@corp_id = options[:corp_id]
|
8
|
-
@corp_secret = options[:corp_secret]
|
9
|
-
@app_id = options[:app_id]
|
10
|
-
@app_secret = options[:app_secret]
|
11
|
-
end
|
12
|
-
|
13
|
-
def contact
|
14
|
-
@contact ||= Wework::Api::Contact.new(corp_id, corp_secret) if contact?
|
15
|
-
end
|
16
|
-
|
17
|
-
def agent
|
18
|
-
@agent ||= Wework::Api::Agent.new(corp_id, app_id, app_secret) if agent?
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def agent?
|
24
|
-
corp_id.present? && app_id.present? && app_secret.present?
|
25
|
-
end
|
26
|
-
|
27
|
-
def contact?
|
28
|
-
corp_id.present? && corp_secret.present?
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Wework
|
2
|
-
module JsTicket
|
3
|
-
class RedisStore < Store
|
4
|
-
|
5
|
-
def initialize(agent)
|
6
|
-
raise RedisNotConfigException if redis.nil?
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def jsapi_ticket
|
11
|
-
super
|
12
|
-
redis.hget(key, "ticket")
|
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.ticket.nil?
|
22
|
-
expires_at = Time.now.to_i + result.expires_in.to_i - Wework.expired_shift_seconds
|
23
|
-
redis.hmset(
|
24
|
-
key,
|
25
|
-
"ticket", result.ticket,
|
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
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Wework
|
2
|
-
module JsTicket
|
3
|
-
class Store
|
4
|
-
|
5
|
-
attr_accessor :app
|
6
|
-
|
7
|
-
def initialize(app)
|
8
|
-
@app = app
|
9
|
-
end
|
10
|
-
|
11
|
-
def jsapi_ticket
|
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.get 'get_jsapi_ticket'
|
21
|
-
if defined?(Rails)
|
22
|
-
Rails.logger.warn "[WEWORK] refresh JsTicket(#{app.corp_id}): #{result.inspect}"
|
23
|
-
end
|
24
|
-
|
25
|
-
result
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def key
|
31
|
-
@key ||= Digest::MD5.hexdigest("#{JSAPI_TOKEN_PREFIX}_#{app.app_id}_#{app.app_secret}")
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|