feishu-api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +42 -0
- data/Rakefile +4 -0
- data/lib/feishu-api/api.rb +134 -0
- data/lib/feishu-api/config.rb +13 -0
- data/lib/feishu-api/engine.rb +13 -0
- data/lib/feishu-api/version.rb +5 -0
- data/lib/feishu-api.rb +16 -0
- metadata +69 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 13d0624f83504106d2aea9ab11e7f46ace5279b941b7c96d3b7079d46aa5192e
|
|
4
|
+
data.tar.gz: 4cebc28b90e6dc24064b173e84f7b2ed4828c16ad88d662f3a80b3e54ccbd982
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f3712e077e07abd86249f8e61743e849ffd07d0c8bf00e38c0f54d3603218888fc8e1ef5ff0a4d29b3f4836a27e19363d3e810f5dc80e4b15a5276e49ef4fe9b
|
|
7
|
+
data.tar.gz: 24bfd38c27a267a439b912ebb313567695403396da4a71f07475509ee8faa220b3117fd1fc2b169942ca2bed558818f57a88e86f8b5abaa9e31290cc3ab78ac6
|
data/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# FeishuApi
|
|
2
|
+
|
|
3
|
+
FeishuApi is a integration of commonly used feishu open platform's APIs, easy to call.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
8
|
+
|
|
9
|
+
$ bundle add feishu-api
|
|
10
|
+
|
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
12
|
+
|
|
13
|
+
$ gem install feishu-api
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
Add feishu-api.rb in config/initializers
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
FeishuApi.configure do |config|
|
|
21
|
+
config.app_id = ''
|
|
22
|
+
config.app_secret = ''
|
|
23
|
+
end
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Example:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
FeishuApi.send_text_by_group('oc_xxx', 'hello')
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Contributing
|
|
33
|
+
|
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ruilisi/feishu-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ruilisi/feishu-api/blob/master/CODE_OF_CONDUCT.md).
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
39
|
+
|
|
40
|
+
## Code of Conduct
|
|
41
|
+
|
|
42
|
+
Everyone interacting in the FeishuApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ruilisi/feishu-api/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module FeishuApi
|
|
4
|
+
class << self
|
|
5
|
+
API_HOST = 'https://open.feishu.cn/open-apis'
|
|
6
|
+
|
|
7
|
+
API_TENANT_ACCESS_TOKEN = '/auth/v3/tenant_access_token/internal'
|
|
8
|
+
API_APP_ACCESS_TOKEN = '/auth/v3/app_access_token/internal'
|
|
9
|
+
API_SEND_MESSAGES = '/im/v1/messages'
|
|
10
|
+
API_CUSTOM_BOT_SEND = '/bot/v2/hook'
|
|
11
|
+
|
|
12
|
+
def api(interface)
|
|
13
|
+
"#{API_HOST}#{interface}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def post(url, data, headers = {}, timeout = 30)
|
|
17
|
+
HTTParty.post(api(url),
|
|
18
|
+
body: data.to_json,
|
|
19
|
+
headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }.merge(headers),
|
|
20
|
+
timeout: timeout,
|
|
21
|
+
verify: false)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def post_with_token(url, data, _timeout = 30)
|
|
25
|
+
headers = { Authorization: "Bearer #{tenant_access_token}" }
|
|
26
|
+
post(url,
|
|
27
|
+
data,
|
|
28
|
+
headers)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def tenant_access_token
|
|
32
|
+
Rails.cache.fetch('tenant_access_token', expires_in: 2.hours) do
|
|
33
|
+
res = post(API_TENANT_ACCESS_TOKEN, {
|
|
34
|
+
app_id: Config.app_id,
|
|
35
|
+
app_secret: Config.app_secret
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
return nil if res.code != 200
|
|
39
|
+
|
|
40
|
+
body = JSON.parse(res.body)
|
|
41
|
+
token = (body['code']).zero? ? body['tenant_access_token'] : nil
|
|
42
|
+
token
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def app_access_token
|
|
47
|
+
Rails.cache.fetch('app_access_token', expires_in: 2.hours) do
|
|
48
|
+
res = post(API_APP_ACCESS_TOKEN, {
|
|
49
|
+
app_id: Config.app_id,
|
|
50
|
+
app_secret: Config.app_secret
|
|
51
|
+
})
|
|
52
|
+
return nil if res.code != 200
|
|
53
|
+
|
|
54
|
+
body = JSON.parse(res.body)
|
|
55
|
+
token = (body['code']).zero? ? body['app_access_token'] : nil
|
|
56
|
+
token
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# 发送消息
|
|
61
|
+
def send_message(receive_type, receive_id, msg_type, content)
|
|
62
|
+
res = post_with_token("#{API_SEND_MESSAGES}?receive_id_type=#{receive_type}",
|
|
63
|
+
{ receive_id: receive_id, msg_type: msg_type, content: content })
|
|
64
|
+
return nil if res.code != 200
|
|
65
|
+
|
|
66
|
+
JSON.parse(res.body)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# 发消息到指定群聊
|
|
70
|
+
def send_message_by_group(receive_id, msg_type, content)
|
|
71
|
+
send_message('chat_id', receive_id, msg_type, content)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# 发文本消息到指定群聊
|
|
75
|
+
def send_text_by_group(receive_id, text)
|
|
76
|
+
send_message_by_group(receive_id, 'text', JSON.generate({ text: text }))
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# 通过邮箱识别用户, 发消息到指定用户
|
|
80
|
+
def send_message_by_email(receive_id, msg_type, content)
|
|
81
|
+
send_message('email', receive_id, msg_type, content)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# 自定义机器人接口 发送消息
|
|
85
|
+
def custom_robot_send(data, hook_id)
|
|
86
|
+
post("#{API_CUSTOM_BOT_SEND}/#{hook_id}", data)
|
|
87
|
+
return nil if res.code != 200
|
|
88
|
+
|
|
89
|
+
JSON.parse(res.body)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# 自定义机器人接口 发送文本消息
|
|
93
|
+
def custom_robot_send_text(text, hook_id)
|
|
94
|
+
custom_robot_send({
|
|
95
|
+
msg_type: 'post',
|
|
96
|
+
content: {
|
|
97
|
+
post: {
|
|
98
|
+
'zh-CN': {
|
|
99
|
+
title: '',
|
|
100
|
+
content: [
|
|
101
|
+
[
|
|
102
|
+
{
|
|
103
|
+
tag: 'text',
|
|
104
|
+
text: text
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}, hook_id)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# 自定义机器人接口 发送卡片消息
|
|
115
|
+
def custom_robot_send_card(title = '标题', theme = 'blue', elements = [], hook_id = '')
|
|
116
|
+
custom_robot_send({
|
|
117
|
+
msg_type: 'interactive',
|
|
118
|
+
card: {
|
|
119
|
+
config: {
|
|
120
|
+
wide_screen_mode: true
|
|
121
|
+
},
|
|
122
|
+
header: {
|
|
123
|
+
title: {
|
|
124
|
+
tag: 'plain_text',
|
|
125
|
+
content: title
|
|
126
|
+
},
|
|
127
|
+
template: theme
|
|
128
|
+
},
|
|
129
|
+
elements: elements
|
|
130
|
+
}
|
|
131
|
+
}, hook_id)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module FeishuApi
|
|
4
|
+
class Engine < ::Rails::Engine
|
|
5
|
+
isolate_namespace FeishuApi
|
|
6
|
+
|
|
7
|
+
initializer('feishu-api', after: :load_config_initializers) do |_app|
|
|
8
|
+
Rails.application.routes.prepend do
|
|
9
|
+
mount FeishuApi::Engine, at: '/feishu-api'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/feishu-api.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'feishu-api/engine'
|
|
4
|
+
require 'feishu-api/config'
|
|
5
|
+
require 'feishu-api/api'
|
|
6
|
+
|
|
7
|
+
require 'httparty'
|
|
8
|
+
|
|
9
|
+
module FeishuApi
|
|
10
|
+
# Your code goes here...
|
|
11
|
+
class << self
|
|
12
|
+
def configure(&block)
|
|
13
|
+
Config.configure(&block)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: feishu-api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- msk
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2022-08-15 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httparty
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: FeishuApi is a integration of commonly used feishu open platform's APIs,
|
|
28
|
+
easy to call.
|
|
29
|
+
email:
|
|
30
|
+
- msk1143667241@outlook.com
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- README.md
|
|
36
|
+
- Rakefile
|
|
37
|
+
- lib/feishu-api.rb
|
|
38
|
+
- lib/feishu-api/api.rb
|
|
39
|
+
- lib/feishu-api/config.rb
|
|
40
|
+
- lib/feishu-api/engine.rb
|
|
41
|
+
- lib/feishu-api/version.rb
|
|
42
|
+
homepage: https://github.com/ruilisi/feishu-api
|
|
43
|
+
licenses:
|
|
44
|
+
- MIT
|
|
45
|
+
metadata:
|
|
46
|
+
rubygems_mfa_required: 'false'
|
|
47
|
+
homepage_uri: https://github.com/ruilisi/feishu-api
|
|
48
|
+
source_code_uri: https://github.com/ruilisi/feishu-api.git
|
|
49
|
+
changelog_uri: https://github.com/ruilisi/feishu-api/blob/master/CHANGELOG.md
|
|
50
|
+
post_install_message:
|
|
51
|
+
rdoc_options: []
|
|
52
|
+
require_paths:
|
|
53
|
+
- lib
|
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: 2.6.0
|
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '0'
|
|
64
|
+
requirements: []
|
|
65
|
+
rubygems_version: 3.3.7
|
|
66
|
+
signing_key:
|
|
67
|
+
specification_version: 4
|
|
68
|
+
summary: feishu open api
|
|
69
|
+
test_files: []
|