lhj-tools 0.1.91 → 0.1.92
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhj/command/yapi/yapi_init.rb +18 -12
- data/lib/lhj/helper/dingtalk_helper.rb +25 -1
- data/lib/lhj/helper/pgyer_helper.rb +5 -1
- data/lib/lhj/tools/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e913a3b6a37362f81e34bae34ca1ccb2b03c830cf825ecc3af3d76482b34de3a
|
4
|
+
data.tar.gz: a294ea2f480cf906f80180ea3dfc351097c69f5a2f25725c858f0380b13f52a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4785975e8288571beccccee257c98f12d6ea88803c328c7df625d0bf0499ae2d7c6832d999553e39db9f82bbfe00238f732af749c1e1889af0ac53f58846517
|
7
|
+
data.tar.gz: 43834bc4842e447c6badab7de4ae9bb1854213be4041d0a2d38c240faad13bb4ae50c504b68538beb39afea1e2674e5cc81f94917964420c71b8e8dcee2386f6
|
@@ -7,7 +7,7 @@ module Lhj
|
|
7
7
|
self.summary = '更新yapi请求cookie'
|
8
8
|
self.description = '更新 ~/.lhj/yapi.yml 文件配置'
|
9
9
|
|
10
|
-
def request_cookie(url)
|
10
|
+
def request_cookie(url, qr_code_key)
|
11
11
|
options = Selenium::WebDriver::Chrome::Options.new(args: %w[start-maximized])
|
12
12
|
driver = Selenium::WebDriver.for(:chrome, capabilities: options)
|
13
13
|
driver.get url
|
@@ -31,25 +31,22 @@ module Lhj
|
|
31
31
|
res[:token] = cookie[:value] if cookie[:name] == '_yapi_token'
|
32
32
|
end
|
33
33
|
if need_notify
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
driver.save_screenshot(file)
|
39
|
-
callback_param = gen_http_body("#{Lhj::OSS::Helper.instance.url_path}/#{file_name}")
|
40
|
-
Lhj::OSS::Helper.instance.upload_file_callback(file_name, file, callback_param)
|
34
|
+
upload_file = File.join(Lhj::Config.instance.home_dir, qr_code_key)
|
35
|
+
driver.save_screenshot(upload_file)
|
36
|
+
callback_param = generate_callback_param("#{Lhj::OSS::Helper.instance.url_path}/#{qr_code_key}")
|
37
|
+
Lhj::OSS::Helper.instance.upload_file_callback(qr_code_key, upload_file, callback_param)
|
41
38
|
need_notify = false
|
42
39
|
end
|
43
40
|
return res if res.values.count == 3
|
44
41
|
end
|
45
42
|
end
|
46
43
|
|
47
|
-
def
|
44
|
+
def generate_callback_param(url)
|
48
45
|
template = Lhj::ErbTemplateHelper.load('yapi_qr_code_notify')
|
49
46
|
output = Lhj::ErbTemplateHelper.render(template, { url: url }, nil)
|
50
47
|
body = Lhj::Dingtalk.http_body_message('yapi qrcode', output)
|
51
48
|
{
|
52
|
-
url:
|
49
|
+
url: 'https://oapi.dingtalk.com/robot/send',
|
53
50
|
query: { access_token: 'fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807' },
|
54
51
|
body: body,
|
55
52
|
content_type: 'application/json'
|
@@ -57,7 +54,7 @@ module Lhj
|
|
57
54
|
end
|
58
55
|
|
59
56
|
def robot_url
|
60
|
-
'https://oapi.dingtalk.com/robot/send'
|
57
|
+
'https://oapi.dingtalk.com/robot/send?access_token=fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807'
|
61
58
|
end
|
62
59
|
|
63
60
|
def notify_robot(url)
|
@@ -94,17 +91,26 @@ module Lhj
|
|
94
91
|
end
|
95
92
|
|
96
93
|
def handle
|
94
|
+
time = Time.now
|
95
|
+
qr_code_name = "#{time.strftime('%Y%m%d%H%M%S')}.png"
|
97
96
|
config = load_config(config_file) if File.exist?(config_file)
|
98
97
|
# base_url: 'http://yapi.xx.com'
|
99
|
-
cookie = request_cookie(config['base_url'])
|
98
|
+
cookie = request_cookie(config['base_url'], qr_code_name)
|
100
99
|
if cookie && config
|
101
100
|
config['__wpkreporterwid_'] = cookie[:wid]
|
102
101
|
config['_yapi_uid'] = cookie[:uid].to_i
|
103
102
|
config['_yapi_token'] = cookie[:token]
|
103
|
+
# save user info
|
104
104
|
save_user({ '__wpkreporterwid_' => cookie[:wid], '_yapi_uid' => cookie[:uid].to_i, '_yapi_token' => cookie[:token] })
|
105
|
+
# save config
|
105
106
|
file_to_save = File.open(config_file, 'w+')
|
106
107
|
YAML.dump(config, file_to_save)
|
107
108
|
file_to_save.close
|
109
|
+
# remove temp file
|
110
|
+
qr_code_image = File.join(Lhj::Config.instance.home_dir, qr_code_name)
|
111
|
+
FileUtils.rm qr_code_image if File.exist?(qr_code_image)
|
112
|
+
# remove oss
|
113
|
+
Lhj::OSS::Helper.instance.delete(qr_code_name)
|
108
114
|
end
|
109
115
|
end
|
110
116
|
end
|
@@ -29,8 +29,32 @@ module Lhj
|
|
29
29
|
Net::HTTP.post(URI(robot_url), http_body, 'Content-Type' => 'application/json')
|
30
30
|
end
|
31
31
|
|
32
|
+
def self.post_action_card_message_robot(robot_url, title, message, btns)
|
33
|
+
http_body = action_card_body_message(title, message, btns, :vertical)
|
34
|
+
Net::HTTP.post(URI(robot_url), http_body, 'Content-Type' => 'application/json')
|
35
|
+
end
|
36
|
+
|
32
37
|
def self.http_body_message(title, message)
|
33
|
-
|
38
|
+
markdown_body_message(title, message)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.markdown_body_message(title, message)
|
42
|
+
{
|
43
|
+
'msgtype' => 'markdown',
|
44
|
+
'markdown' => { 'title' => title, 'text' => message }
|
45
|
+
}.to_json
|
46
|
+
end
|
47
|
+
|
48
|
+
# btns: [{'title'=>'内容不错', 'actionURL'=>'https://www.baidu.com'}]
|
49
|
+
def self.action_card_body_message(title, message, btns, orientation = :vertical)
|
50
|
+
btn_orientation = orientation == :vertical ? '1' : '0'
|
51
|
+
{
|
52
|
+
'msgtype' => 'actionCard',
|
53
|
+
'actionCard' => { 'title' => title,
|
54
|
+
'text' => message },
|
55
|
+
'btnOrientation' => btn_orientation,
|
56
|
+
'btns' => btns
|
57
|
+
}.to_json
|
34
58
|
end
|
35
59
|
|
36
60
|
def self.fetch_branch
|
@@ -100,7 +100,7 @@ module Lhj
|
|
100
100
|
Actions.sh(update_cmd.join(' '), log: false, error_callback: nil)
|
101
101
|
end
|
102
102
|
|
103
|
-
def render_with_template(template_name
|
103
|
+
def render_with_template(template_name)
|
104
104
|
if @result.is_a? Hash
|
105
105
|
temp = Lhj::ErbTemplateHelper.load(template_name)
|
106
106
|
Lhj::ErbTemplateHelper.render(temp, @result, nil)
|
@@ -108,5 +108,9 @@ module Lhj
|
|
108
108
|
@result
|
109
109
|
end
|
110
110
|
end
|
111
|
+
|
112
|
+
def app_download_url
|
113
|
+
"https://www.pgyer.com/#{@result['appShortcutUrl']}"
|
114
|
+
end
|
111
115
|
end
|
112
116
|
end
|
data/lib/lhj/tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhj-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.92
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lihaijian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xcodeproj
|