Class: FeishuHelper
- Includes:
- FIR::Config
- Defined in:
- lib/fir/util/feishu_helper.rb
Overview
require ‘byebug’
Constant Summary
Constants included from FIR::Config
FIR::Config::API_YML_PATH, FIR::Config::APP_FILE_TYPE, FIR::Config::APP_INFO_PATH, FIR::Config::CONFIG_PATH, FIR::Config::XCODE_WRAPPER_PATH
Instance Attribute Summary collapse
-
#app_info ⇒ Object
Returns the value of attribute app_info.
-
#download_url ⇒ Object
Returns the value of attribute download_url.
-
#feishu_access_token ⇒ Object
Returns the value of attribute feishu_access_token.
-
#image_key ⇒ Object
Returns the value of attribute image_key.
-
#options ⇒ Object
Returns the value of attribute options.
-
#qrcode_path ⇒ Object
Returns the value of attribute qrcode_path.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(app_info, options, qrcode_path, download_url) ⇒ FeishuHelper
constructor
A new instance of FeishuHelper.
- #send_msg ⇒ Object
- #v1_request ⇒ Object
- #v2_request ⇒ Object
Methods included from FIR::Config
#bughd_api, #config, #current_token, #fir_api, #reload_config, #write_app_info, #write_config
Constructor Details
#initialize(app_info, options, qrcode_path, download_url) ⇒ FeishuHelper
Returns a new instance of FeishuHelper.
7 8 9 10 11 12 13 14 15 |
# File 'lib/fir/util/feishu_helper.rb', line 7 def initialize(app_info, , qrcode_path, download_url) @app_info = app_info @options = @feishu_access_token = @options[:feishu_access_token] @qrcode_path = qrcode_path @download_url = download_url @title = "#{@app_info[:name]}-#{@app_info[:version]}(Build #{@app_info[:build]}) #{@app_info[:type]}" end |
Instance Attribute Details
#app_info ⇒ Object
Returns the value of attribute app_info.
4 5 6 |
# File 'lib/fir/util/feishu_helper.rb', line 4 def app_info @app_info end |
#download_url ⇒ Object
Returns the value of attribute download_url.
4 5 6 |
# File 'lib/fir/util/feishu_helper.rb', line 4 def download_url @download_url end |
#feishu_access_token ⇒ Object
Returns the value of attribute feishu_access_token.
4 5 6 |
# File 'lib/fir/util/feishu_helper.rb', line 4 def feishu_access_token @feishu_access_token end |
#image_key ⇒ Object
Returns the value of attribute image_key.
4 5 6 |
# File 'lib/fir/util/feishu_helper.rb', line 4 def image_key @image_key end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/fir/util/feishu_helper.rb', line 4 def @options end |
#qrcode_path ⇒ Object
Returns the value of attribute qrcode_path.
4 5 6 |
# File 'lib/fir/util/feishu_helper.rb', line 4 def qrcode_path @qrcode_path end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/fir/util/feishu_helper.rb', line 4 def title @title end |
Instance Method Details
#send_msg ⇒ Object
17 18 19 20 21 22 |
# File 'lib/fir/util/feishu_helper.rb', line 17 def send_msg return if feishu_access_token.blank? answer = v2_request v1_request if answer.dig('ok') == 'false' end |
#v1_request ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/fir/util/feishu_helper.rb', line 30 def v1_request url = "https://open.feishu.cn/open-apis/bot/hook/#{feishu_access_token}" payload = { "title": "#{title} uploaded", "text": "#{title} uploaded at #{Time.now}\nurl: #{download_url}\n#{[:feishu_custom_message]}\n" } DefaultRest.post(url, payload, {timeout: ENV['FEISHU_TIMEOUT'] ? ENV['FEISHU_TIMEOUT'].to_i : 30 }) end |
#v2_request ⇒ Object
24 25 26 27 28 |
# File 'lib/fir/util/feishu_helper.rb', line 24 def v2_request url = "https://open.feishu.cn/open-apis/bot/v2/hook/#{feishu_access_token}" x = build_v2_info DefaultRest.post(url, x, {timeout: ENV['FEISHU_TIMEOUT'] ? ENV['FEISHU_TIMEOUT'].to_i : 30 }) end |