lhj-tools 0.2.83 → 0.2.84
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhj/helper/apple/analytics/apple_analytics_helper.rb +94 -0
- data/lib/lhj/lhj.rb +1 -0
- data/lib/lhj/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5099d017ea0c7cfff90a0f2a63084a5a1714c832246f10d3c7dcc34162c5072
|
4
|
+
data.tar.gz: f336ef00bff5aadfc71612f07100ff4a74012302b59a134b9bc6819bd9631e6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
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.
|
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-
|
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
|