lhj-tools 0.2.83 → 0.2.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5d002932699d20e17f85d6c37b38bb6450b3ddbc1cbf7611d8e01fb28035465
4
- data.tar.gz: 04c53c4bdd4d245538c1e0f347153aa15a20d5a0497248c89acfc9040d550c56
3
+ metadata.gz: 7ac8d9de925c4a6004b4cf22f6cb14a895d871dd1c70bd9b6b4b88741ae314aa
4
+ data.tar.gz: 5db49d39898e4ba66a64d86d7a5bf13e19b568247db084faa1a2ce2b12232fac
5
5
  SHA512:
6
- metadata.gz: e31cccdb1e468653c14cd2e4fc370a6c445fbb22ed6f1c79c610821f8d04c5c2b7368ea0c2ebcefa0f049fff9c9480515ff303799637881a223076b64fb08443
7
- data.tar.gz: b72cae20a8095402304f1b3b62edfd042a6b330a7903986c52634671dc17285dedd9c221feaa5e96f66bffde9de7e25ac06023b7373ae77ef926a5561d4f9905
6
+ metadata.gz: 1c7cb5985e175caf4b7c7f7c7cdbc336d93f04d237914356473d26e75a7161f7d042f159b526bbfff3a28b5271ebbcd1fd5bd4f5e6690f27ea93724233fb4572
7
+ data.tar.gz: 230edcf280d2d03f08db2405b826d2e435e8694223a1d30e76d2c57244a5a508f6dda40a5869c94b078b4f0c0651826700c76666597878b91626c872d5dc0638
@@ -105,6 +105,10 @@ module Lhj
105
105
  vers.last[:value]
106
106
  end
107
107
 
108
+ def last_commit_id
109
+ Lhj::Actions.last_git_commit_hash(true)
110
+ end
111
+
108
112
  def build_app_version_no
109
113
  # xcode build version
110
114
  # ${BUILD_NUMBER} of jenkins
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+
5
+ module Lhj
6
+ class AppleAnalyticsHelper
7
+
8
+ # @param [String] id: the app resource ID from the List Apps response.
9
+ # @param [String] date: format YYYY-MM-DD
10
+ # @param [String] conversation_id: robot conversation id
11
+ def self.read_all_report(id, date, conversation_id)
12
+ keys = []
13
+ url = "https://api.appstoreconnect.apple.com/v1/apps/#{id}/analyticsReportRequests"
14
+ reports_res = Lhj::ConnectAPI.get(url)
15
+ reports_res_body = JSON.parse(reports_res.body)
16
+ reports_res_body['data'].each do |json|
17
+ if json['attributes']['accessType'] == 'ONGOING'
18
+ keys += read_reports(id, json['relationships']['reports']['links']['related'], date)
19
+ end
20
+ end
21
+ notify(keys, conversation_id) if keys.length.positive?
22
+ end
23
+
24
+ # @return [Array]
25
+ # @param [String] id
26
+ # @param [String] url
27
+ # @param [String] date
28
+ def self.read_reports(id, url, date)
29
+ keys = []
30
+ reports_res = Lhj::ConnectAPI.get(url)
31
+ reports_res_body = JSON.parse(reports_res.body)
32
+ reports_res_body['data'].each do |json|
33
+ name = json['attributes']['name'].gsub(/\s/, '_')
34
+ path = "analytics/#{id}/#{json['attributes']['category']}/#{name}/#{date}"
35
+ keys += read_instances(json['relationships']['instances']['links']['related'], date, path)
36
+ end
37
+ keys
38
+ end
39
+
40
+ def self.read_instances(url, date, path)
41
+ keys = []
42
+ req_url = "#{url}?filter%5BprocessingDate%5D=#{date}&filter%5Bgranularity%5D=DAILY"
43
+ instances_res = Lhj::ConnectAPI.get(req_url)
44
+ instances_res_body = JSON.parse(instances_res.body)
45
+ instances_res_body['data'].each do |json|
46
+ keys += read_segments(json['relationships']['segments']['links']['related'], path)
47
+ end
48
+ keys
49
+ end
50
+
51
+ def self.read_segments(url, path)
52
+ keys = []
53
+ segment_res = Lhj::ConnectAPI.get(url)
54
+ segment_res_body = JSON.parse(segment_res.body)
55
+ segment_res_body['data'].each do |json|
56
+ keys << download_csv(json['attributes']['url'], path)
57
+ end
58
+ keys
59
+ end
60
+
61
+ def self.download_csv(url, path)
62
+ name = "#{rand(36 ** 8).to_s(36)}.csv.gz"
63
+ key = "#{path}/#{name}"
64
+ file = File.join(Lhj::Config.instance.home_dir, key)
65
+ save_file(url, file)
66
+ Lhj::OSS::Helper.instance.upload(key, file)
67
+ File.delete(file) if File.exist?(file)
68
+ key
69
+ end
70
+
71
+ def self.save_file(url, file)
72
+ http_client = Faraday.new
73
+ response = http_client.get(url) do |req|
74
+ req.options[:timeout] = 300
75
+ req.options[:open_timeout] = 20
76
+ end
77
+ FileUtils.mkdir_p(File.dirname(file)) unless File.directory?(File.dirname(file))
78
+ File.open(file, 'wb') { |fp| fp.write(response.body) }
79
+ end
80
+
81
+ def self.notify(keys, conversation_id)
82
+ title = 'AppStore数据分析'
83
+ markdown = "### 数据来源于App Store \n"
84
+ keys.each do |k|
85
+ a = k.split('/')
86
+ name = a[3].gsub('_', ' ')
87
+ markdown += "- [#{name}](#{Lhj::OSS::Helper.instance.object_url(k)}) \n"
88
+ end
89
+ Lhj::Dingtalk.send_markdown_message_with_api(conversation_id, title, markdown, '')
90
+ end
91
+
92
+ end
93
+ end
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.83'
4
+ VERSION = '0.2.85'
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.83
4
+ version: 0.2.85
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-25 00:00:00.000000000 Z
11
+ date: 2024-12-18 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