Class: FeishuHelper

Inherits:
Object show all
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

Instance Method Summary collapse

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, options, qrcode_path, download_url)
  @app_info = app_info
  @options = 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_infoObject

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_urlObject

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_tokenObject

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_keyObject

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

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/fir/util/feishu_helper.rb', line 4

def options
  @options
end

#qrcode_pathObject

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

#titleObject

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_msgObject



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_requestObject



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#{options[:feishu_custom_message]}\n"
  }
  DefaultRest.post(url, payload, {timeout: ENV['FEISHU_TIMEOUT'] ? ENV['FEISHU_TIMEOUT'].to_i : 30 })
end

#v2_requestObject



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