lhj-tools 0.2.82 → 0.2.84

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5cb532b2f91d92e8575f55aa8f46251351fe6cf8497732c9436344d41c3f10b
4
- data.tar.gz: 9e90fce95487eb3185ffad60b9840cefa94e4defff4dab3355a809ad524acc45
3
+ metadata.gz: b5099d017ea0c7cfff90a0f2a63084a5a1714c832246f10d3c7dcc34162c5072
4
+ data.tar.gz: f336ef00bff5aadfc71612f07100ff4a74012302b59a134b9bc6819bd9631e6a
5
5
  SHA512:
6
- metadata.gz: 60613b6d94a186e14a6c06d62e46277658c90804b37d3d62185bc94edba554463ef426de55e687e74338c9617ebaaf09342a7ed21eecb14053ae4068f1d4539a
7
- data.tar.gz: 96297521dbf1c255087ae94accee5f04de60ea533c6bb46c7ca537c0cc7ceee4ea0269c9b6f7df983821cf676006b071e49f044993ee48fb04395383b2934ff1
6
+ metadata.gz: ac9b2e52461c0d8b85bfb3b27ecf0472b3b6a6b910e8071ac1716b3f27254ba50d06cd070a2f7123208a343e0eb87b81cd6c39db4bb6b756c5158f95ba407d0a
7
+ data.tar.gz: 41d174583980d1b6eb72598259e2dbef709c4834c211c904126017677d4869ee0baeb1ac898192a6b5f83afee595817d8b9be85be84cab621a673b7ed2808043
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+ require 'jenkins_api_client'
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+
6
+ module Lhj
7
+ class AppleAnalyticsHelper
8
+
9
+ # @param [String] id: the app resource ID from the List Apps response.
10
+ # @param [String] date: format YYYY-MM-DD
11
+ # @param [String] conversation_id: robot conversation id
12
+ def self.read_all_report(id, date, conversation_id)
13
+ keys = []
14
+ url = "https://api.appstoreconnect.apple.com/v1/apps/#{id}/analyticsReportRequests"
15
+ reports_res = Lhj::ConnectAPI.get(url)
16
+ reports_res_body = JSON.parse(reports_res.body)
17
+ reports_res_body['data'].each do |json|
18
+ if json['attributes']['accessType'] == 'ONGOING'
19
+ keys += read_reports(id, json['relationships']['reports']['links']['related'], date)
20
+ end
21
+ end
22
+ notify(keys, conversation_id) if keys.length.positive?
23
+ end
24
+
25
+ # @return [Array]
26
+ # @param [String] id
27
+ # @param [String] url
28
+ # @param [String] date
29
+ def self.read_reports(id, url, date)
30
+ keys = []
31
+ reports_res = Lhj::ConnectAPI.get(url)
32
+ reports_res_body = JSON.parse(reports_res.body)
33
+ reports_res_body['data'].each do |json|
34
+ name = json['attributes']['name'].gsub(/\s/, '_')
35
+ path = "analytics/#{id}/#{json['attributes']['category']}/#{name}/#{date}"
36
+ keys += read_instances(json['relationships']['instances']['links']['related'], date, path)
37
+ end
38
+ keys
39
+ end
40
+
41
+ def self.read_instances(url, date, path)
42
+ keys = []
43
+ req_url = "#{url}?filter%5BprocessingDate%5D=#{date}&filter%5Bgranularity%5D=DAILY"
44
+ instances_res = Lhj::ConnectAPI.get(req_url)
45
+ instances_res_body = JSON.parse(instances_res.body)
46
+ instances_res_body['data'].each do |json|
47
+ keys += read_segments(json['relationships']['segments']['links']['related'], path)
48
+ end
49
+ keys
50
+ end
51
+
52
+ def self.read_segments(url, path)
53
+ keys = []
54
+ segment_res = Lhj::ConnectAPI.get(url)
55
+ segment_res_body = JSON.parse(segment_res.body)
56
+ segment_res_body['data'].each do |json|
57
+ keys << download_csv(json['attributes']['url'], path)
58
+ end
59
+ keys
60
+ end
61
+
62
+ def self.download_csv(url, path)
63
+ name = "#{rand(36 ** 8).to_s(36)}.csv.gz"
64
+ key = "#{path}/#{name}"
65
+ file = File.join(Lhj::Config.instance.home_dir, key)
66
+ save_file(url, file)
67
+ Lhj::OSS::Helper.instance.upload(key, file)
68
+ File.delete(file) if File.exist?(file)
69
+ key
70
+ end
71
+
72
+ def self.save_file(url, file)
73
+ http_client = Faraday.new
74
+ response = http_client.get(url) do |req|
75
+ req.options[:timeout] = 300
76
+ req.options[:open_timeout] = 20
77
+ end
78
+ FileUtils.mkdir_p(File.dirname(file)) unless File.directory?(File.dirname(file))
79
+ File.open(file, 'wb') { |fp| fp.write(response.body) }
80
+ end
81
+
82
+ def self.notify(keys, conversation_id)
83
+ title = 'AppStore数据分析'
84
+ markdown = "### 数据来源于App Store \n"
85
+ keys.each do |k|
86
+ a = k.split('/')
87
+ name = a[3].gsub('_', ' ')
88
+ markdown += "- [#{name}](#{Lhj::OSS::Helper.instance.object_url(k)}) \n"
89
+ end
90
+ Lhj::Dingtalk.send_markdown_message_with_api(conversation_id, title, markdown, '')
91
+ end
92
+
93
+ end
94
+ end
@@ -40,6 +40,7 @@ module Lhj
40
40
  block_lines = []
41
41
  File.open(file, 'r') do |f|
42
42
  multi_comment = false
43
+ strong_key = false
43
44
  available_idx = 0
44
45
  block_idx = 0
45
46
  f.readlines.each_with_index do |line, idx|
@@ -60,10 +61,13 @@ module Lhj
60
61
  # 此行包含^符号,且不是方法声明,且不是主线程方法
61
62
  if (line =~ BLOCK_KEY_BEGIN_REGEX && line !~ /^\s*[+-]/ && line !~ /dispatch_get_main_queue/) || block_idx.positive?
62
63
  line_position = block_idx.zero? ? :start : :process
64
+ strong_key = false if block_idx.zero?
65
+ strong_key = true if line =~ /@strongify/
63
66
  block_idx += 1 if line =~ /\{/
64
67
  block_idx -= 1 if line =~ /\}/
65
68
  line_position = :end if block_idx.zero?
66
- block_lines << { idx: idx, line: line, position: line_position }
69
+ strong_key = false if block_idx.zero?
70
+ block_lines << { idx: idx, line: line, position: line_position, strong: strong_key }
67
71
  end
68
72
  end
69
73
  end
@@ -73,6 +77,7 @@ module Lhj
73
77
  def self.handle_block_notify(file_name, wrapper_lines)
74
78
  arr = wrapper_lines.filter { |l| l[:position] != :start }
75
79
  arr.filter! { |l| l[:position] != :end }
80
+ arr.filter! { |l| !l[:strong] }
76
81
  arr.filter! { |l| l[:line] =~ /\W+self\W+/ || l[:line] =~ /\W+_/ }
77
82
  arr.filter! { |l| l[:line] !~ /\^/ }
78
83
  arr.filter! { |l| l[:line] !~ /__weak/ }
data/lib/lhj/lhj.rb CHANGED
@@ -11,6 +11,7 @@ module Lhj
11
11
  require 'lhj/helper/jenkins_config'
12
12
  require 'lhj/helper/apple/apple_jwt_config'
13
13
  require 'lhj/helper/apple/apple_connect_api'
14
+ require 'lhj/helper/apple/analytics/apple_analytics_helper'
14
15
  require 'lhj/helper/ios_robot_config'
15
16
  require 'lhj/helper/chat_gpt_config'
16
17
  require 'lhj/helper/pod_repo_config'
data/lib/lhj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lhj
4
- VERSION = '0.2.82'
4
+ VERSION = '0.2.84'
5
5
  end
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.2.82
4
+ version: 0.2.84
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-22 00:00:00.000000000 Z
11
+ date: 2024-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj
@@ -382,6 +382,7 @@ files:
382
382
  - lib/lhj/config.rb
383
383
  - lib/lhj/env.rb
384
384
  - lib/lhj/helper/app_version_info.rb
385
+ - lib/lhj/helper/apple/analytics/apple_analytics_helper.rb
385
386
  - lib/lhj/helper/apple/apple_connect_api.rb
386
387
  - lib/lhj/helper/apple/apple_jwt_config.rb
387
388
  - lib/lhj/helper/bugly_helper.rb