Class: LanguageDownloader
- Inherits:
-
Object
- Object
- LanguageDownloader
- Defined in:
- lib/cocoapods-aqara-localzedLoader/LanguageDownloader.rb
Constant Summary collapse
- HeaderString =
%Q{User-Agent: volc-sdk-python/v1.0.109 Accept-Encoding: gzip, deflate Accept: application/json Host: iam.volcengineapi.com X-Date: 20231017T062815Z X-Content-Sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 Authorization: HMAC-SHA256 Credential=AKLTZTFjNzFjYTczMzJjNGQyMjg0NTRkZjQ2ZTA4MTE1Mjc/20231017/cn-north-1/i18n_openapi/request, SignedHeaders=host;x-content-sha256;x-date, Signature=fb24f4211cf74f4e985cdd72f09156c288bd8e078d9867813327084204587b0a Connection: keep-alive }
Class Method Summary collapse
Class Method Details
.download ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cocoapods-aqara-localzedLoader/LanguageDownloader.rb', line 27 def self.download # puts makeHeader #下载文件 params = {"projectIdList":[5],"langIds":[1,2,3,9,10,11,12,13,14,15,16,17,18],"fileTypeList":["excel"],"auditState":1,"valueState":0,"userId":"","value":"","tagIds":nil,"bizUseTagIds":nil,"pkeys":[]} response = HTTParty.post('https://intl-lang.aqara.com/v1.0/lumi/language/file/export', body: JSON.generate(params), headers:LanguageDownloader.makeHeader) # puts response.body unless response.body["code"] == nil 3.times do puts "资源包下载失败了!!!!! code:#{response.body}".red end return end destation_path = "./localize.zip" if File.exist? destation_path FileUtils.rm_rf destation_path end File.open(destation_path,"w") do |io| io.binmode io.write response.body end # 解压缩文件到指定目录 f_path = '' Zip::File.open(destation_path) do |zip_file| zip_file.each do |f| f_path = File.join('./','hit_all.xls') File.delete f_path if File.exist? f_path # FileUtils.mkdir_p(File.dirname(f_path)) f.extract(f_path) end end if File.exist? destation_path FileUtils.rm_rf destation_path end f_path end |
.makeHeader ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/cocoapods-aqara-localzedLoader/LanguageDownloader.rb', line 19 def self.makeHeader headerArray = HeaderString.split("\n") header = {} headerArray.each do |str| header[str.split(":",2)[0].strip] = str.split(":",2)[1].strip end header end |