wework 1.1.5 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -27
- data/lib/wework/request.rb +4 -2
- data/lib/wework/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f64f0d8436c00eabc6bccec0ec06674b344c683af83c289d5bbab600efddeed0
|
4
|
+
data.tar.gz: afb5f5ac2ad3d80b1e5b22738ef2c77445e9a1c89bc54bceaaeb9ec88a349583
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1961367ffc18e715cd434df2b9e7928ab9894a5f53ee6d40f3b9df7224803461a928457cd756db90cc7068c3237c8e26029206fb504f46e512dedd6096a6d212
|
7
|
+
data.tar.gz: f50251f9823dbcd33c0076107533667590b010da0d83624a262c5784a1a0f565eb7dd2321a456de248ef43764a346b6a8103aabed24c8c92c263248a59b752cc
|
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# Wechat Work
|
1
|
+
# Wechat Work 「企业微信」
|
2
2
|
|
3
3
|
Wework is a ruby API wrapper for wechat work「企业微信」.
|
4
4
|
|
5
|
+
[企业微信 API 文档](https://work.weixin.qq.com/api/doc)
|
6
|
+
|
5
7
|
[![CircleCI](https://circleci.com/gh/mycolorway/wework/tree/suite.svg?style=svg)](https://circleci.com/gh/mycolorway/wework/tree/suite) [![Gem Version](https://badge.fury.io/rb/wework.svg)](https://badge.fury.io/rb/wework)
|
6
8
|
|
7
9
|
## Installation
|
@@ -22,9 +24,19 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
### 初始化
|
28
|
+
|
29
|
+
```
|
30
|
+
Wework.configure do |config|
|
31
|
+
config.redis = Redis.new(host: ENV['REDIS_HOST'], port: ENV['REDIS_PORT'], db: ENV['REDIS_CACHE_DB']) # redis
|
32
|
+
config.http_timeout_options = {write: 15, read: 15, connect: 10} # 请求超时
|
33
|
+
config.expired_shift_seconds = 180 # access token 有效期偏移量 (时间有效期 - 偏移量)
|
34
|
+
end
|
35
|
+
```
|
26
36
|
|
27
|
-
|
37
|
+
### 第三方应用
|
38
|
+
|
39
|
+
1). 初始化套件接口 [Wework::Api::Suite](https://github.com/mycolorway/wework/blob/master/lib/wework/api/suite.rb)
|
28
40
|
|
29
41
|
```ruby
|
30
42
|
$wework_suite = Wework::Api::Suite.new(
|
@@ -35,15 +47,15 @@ $wework_suite = Wework::Api::Suite.new(
|
|
35
47
|
suite_secret: ENV['WEWORK_SUITE_SECRET'] # Secret
|
36
48
|
)
|
37
49
|
```
|
38
|
-
[套件接口列表](https://github.com/mycolorway/wework/blob/suite/lib/wework/api/methods/suite.rb)
|
39
50
|
|
40
|
-
|
51
|
+
|
52
|
+
2). 获取第三方应用接口 [Wework::Api::Agent](https://github.com/mycolorway/wework/blob/master/lib/wework/api/agent.rb)
|
41
53
|
|
42
54
|
```ruby
|
43
55
|
agent_api = $wework_suite.corp(
|
44
|
-
|
45
|
-
|
46
|
-
)
|
56
|
+
corp_id, # 授权企业 CorpID
|
57
|
+
permanent_code # 永久授权码
|
58
|
+
).agent(agent_id)
|
47
59
|
```
|
48
60
|
|
49
61
|
3). 第三方应用回调协议
|
@@ -73,9 +85,9 @@ $wework_suite.signature(timestamp, nonce, encrypt_str)
|
|
73
85
|
```
|
74
86
|
|
75
87
|
|
76
|
-
|
88
|
+
### 自建应用
|
77
89
|
|
78
|
-
初始化接口 [Wework::Api::Agent](https://github.com/mycolorway/wework/blob/
|
90
|
+
初始化接口 [Wework::Api::Agent](https://github.com/mycolorway/wework/blob/master/lib/wework/api/agent.rb)
|
79
91
|
|
80
92
|
``` ruby
|
81
93
|
$agent_api = Wework::Api::Agent.new(
|
@@ -85,9 +97,9 @@ $agent_api = Wework::Api::Agent.new(
|
|
85
97
|
)
|
86
98
|
```
|
87
99
|
|
88
|
-
|
100
|
+
### 通讯录同步
|
89
101
|
|
90
|
-
初始化接口 [Wework::Api::Contact](https://github.com/mycolorway/wework/blob/
|
102
|
+
初始化接口 [Wework::Api::Contact](https://github.com/mycolorway/wework/blob/master/lib/wework/api/contact.rb)
|
91
103
|
|
92
104
|
``` ruby
|
93
105
|
$contact_api = Wework::Api::Contact.new(
|
@@ -96,7 +108,7 @@ $contact_api = Wework::Api::Contact.new(
|
|
96
108
|
)
|
97
109
|
```
|
98
110
|
|
99
|
-
|
111
|
+
### 应用服务商接口 (单点登录)
|
100
112
|
|
101
113
|
初始化
|
102
114
|
|
@@ -107,7 +119,7 @@ $provider_api = Wework::Api::Provider.new(
|
|
107
119
|
)
|
108
120
|
```
|
109
121
|
|
110
|
-
|
122
|
+
### 小程序 encryptedData 解密
|
111
123
|
|
112
124
|
```ruby
|
113
125
|
require "openssl"
|
@@ -123,31 +135,31 @@ values = JSON.parse data
|
|
123
135
|
```
|
124
136
|
|
125
137
|
|
126
|
-
##
|
138
|
+
## 已实现接口列表
|
127
139
|
|
128
|
-
[Wework::Api::Methods::Agent](https://github.com/mycolorway/wework/blob/
|
140
|
+
[Wework::Api::Methods::Agent](https://github.com/mycolorway/wework/blob/master/lib/wework/api/methods/agent.rb)
|
129
141
|
|
130
|
-
[Wework::Api::Methods::User](https://github.com/mycolorway/wework/blob/
|
142
|
+
[Wework::Api::Methods::User](https://github.com/mycolorway/wework/blob/master/lib/wework/api/methods/user.rb)
|
131
143
|
|
132
|
-
[Wework::Api::Methods::Tag](https://github.com/mycolorway/wework/blob/
|
144
|
+
[Wework::Api::Methods::Tag](https://github.com/mycolorway/wework/blob/master/lib/wework/api/methods/tag.rb)
|
133
145
|
|
134
|
-
[Wework::Api::Methods::Department](https://github.com/mycolorway/wework/blob/
|
146
|
+
[Wework::Api::Methods::Department](https://github.com/mycolorway/wework/blob/master/lib/wework/api/methods/department.rb)
|
135
147
|
|
136
|
-
[Wework::Api::Methods::Message](https://github.com/mycolorway/wework/blob/
|
148
|
+
[Wework::Api::Methods::Message](https://github.com/mycolorway/wework/blob/master/lib/wework/api/methods/message.rb)
|
137
149
|
|
138
|
-
[Wework::Api::Methods::Media](https://github.com/mycolorway/wework/blob/
|
150
|
+
[Wework::Api::Methods::Media](https://github.com/mycolorway/wework/blob/master/lib/wework/api/methods/media.rb)
|
139
151
|
|
140
|
-
[Wework::Api::Methods::Menu](https://github.com/mycolorway/wework/blob/
|
152
|
+
[Wework::Api::Methods::Menu](https://github.com/mycolorway/wework/blob/master/lib/wework/api/methods/menu.rb)
|
141
153
|
|
142
|
-
[Wework::Api::Methods::Approval](https://github.com/mycolorway/wework/blob/
|
154
|
+
[Wework::Api::Methods::Approval](https://github.com/mycolorway/wework/blob/master/lib/wework/api/methods/approval.rb)
|
143
155
|
|
144
|
-
[Wework::Api::Methods::Checkin](https://github.com/mycolorway/wework/blob/
|
156
|
+
[Wework::Api::Methods::Checkin](https://github.com/mycolorway/wework/blob/master/lib/wework/api/methods/checkin.rb)
|
145
157
|
|
146
|
-
[Wework::Api::Methods::Batch](https://github.com/mycolorway/wework/blob/
|
158
|
+
[Wework::Api::Methods::Batch](https://github.com/mycolorway/wework/blob/master/lib/wework/api/methods/batch.rb)
|
147
159
|
|
148
|
-
[Wework::Api::Methods::Provider](https://github.com/mycolorway/wework/blob/
|
160
|
+
[Wework::Api::Methods::Provider](https://github.com/mycolorway/wework/blob/master/lib/wework/api/methods/provider.rb)
|
149
161
|
|
150
|
-
[Wework::Api::Methods::Service](https://github.com/mycolorway/wework/blob/
|
162
|
+
[Wework::Api::Methods::Service](https://github.com/mycolorway/wework/blob/master/lib/wework/api/methods/service.rb)
|
151
163
|
|
152
164
|
|
153
165
|
## Contributing
|
data/lib/wework/request.rb
CHANGED
@@ -45,14 +45,16 @@ module Wework
|
|
45
45
|
url_base = header.delete(:base) || base
|
46
46
|
as = header.delete(:as)
|
47
47
|
header['Accept'] = 'application/json'
|
48
|
+
dup_header = header.dup
|
48
49
|
response = yield("#{url_base}#{path}", header)
|
49
|
-
|
50
50
|
raise ResponseError.new(response.status) unless HTTP_OK_STATUS.include?(response.status)
|
51
51
|
|
52
52
|
parse_response(response, as || :json) do |parse_as, data|
|
53
53
|
break data unless parse_as == :json
|
54
54
|
result = Wework::Result.new(data)
|
55
|
-
|
55
|
+
if defined?(Rails.logger) && Rails.logger
|
56
|
+
Rails.logger.debug "[WEWORK] request path(#{url_base}#{path}); request params: #{dup_header.inspect}; response: #{result.inspect}"
|
57
|
+
end
|
56
58
|
raise AccessTokenExpiredError if result.token_expired?
|
57
59
|
result
|
58
60
|
end
|
data/lib/wework/version.rb
CHANGED