Class: Pindo::Command::Appstore::Getitcinfo

Inherits:
Pindo::Command::Appstore show all
Includes:
AppstoreMetadataConnectApiHelper
Defined in:
lib/pindo/command/appstore/getitcinfo.rb

Constant Summary

Constants inherited from Pindo::Command

DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AppstoreMetadataConnectApiHelper

#all_languages, #camel_case_lower, #change_img_sort, #check_attributes, #display_type_dir_name, #download_screenshots_exe, #fastlane_download_app_info, #fastlane_download_app_screenshot_exe, #fastlane_download_app_screenshots, #fastlane_download_app_version_info, #fastlane_login, #fastlane_process_lang_screenshots, #fastlane_update_app_info_localizations, #fastlane_update_app_info_metadata, #fastlane_update_app_metadata, #fastlane_update_app_version_info_metadata, #update_age_rating, #update_app_categories, #update_app_info_localizations, #update_privacy_useagedata, #update_review_info, #update_version_info_localizations, #verify_app_info_localizations, #verify_app_version_info_localizations, #write_app_version_info_localization_to_txt

Methods inherited from Pindo::Command

command_name, #initialize_options, run, use_cache?, #validate!

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Methods included from Githelper

#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #git_root_directory, #is_git_directory?, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag

Methods included from Executable

capture_command, #executable, execute_command, popen3, reader, which, which!

Constructor Details

#initialize(argv) ⇒ Getitcinfo

Returns a new instance of Getitcinfo.



42
43
44
45
46
47
48
# File 'lib/pindo/command/appstore/getitcinfo.rb', line 42

def initialize(argv)
    @upload_metadata_flag = argv.flag?('metadata', false)
    @upload_screenshots_flag = argv.flag?('screenshots', false)
    @over_write = argv.flag?('overwrite', false)

    super
end

Class Method Details

.optionsObject



34
35
36
37
38
39
40
# File 'lib/pindo/command/appstore/getitcinfo.rb', line 34

def self.options
    [
        ['--metadata', '获取metadata信息'],
        ['--screenshots', '下载商店截屏'],
        ['--overwrite', '覆盖已存在的文件'],
    ].concat(super)
end

Instance Method Details

#download_iap_info(temp_bundle_id: nil) ⇒ Object



236
237
238
# File 'lib/pindo/command/appstore/getitcinfo.rb', line 236

def download_iap_info(temp_bundle_id: nil)

end

#fastlane_download_metadata(temp_bundle_id: nil) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/pindo/command/appstore/getitcinfo.rb', line 96

def (temp_bundle_id: nil)

    app_itunes_dir = File.join(@app_config_dir, "fastlane")
    app_itunes_file = File.join(app_itunes_dir, "app_itunes.json")

    app_itunes_json = {}

    app = Spaceship::ConnectAPI::App.find(temp_bundle_id)

    app_itunes_json["primary_locale"] = app.primary_locale
    app_itunes_json["content_rights_declaration"] = app.content_rights_declaration

    all_usages = Spaceship::ConnectAPI::AppDataUsage.all(app_id: app.id, includes: "category,grouping,purpose,dataProtection", limit: 500)
    if !all_usages.nil? && all_usages.size > 0
        app_itunes_json["privacy_data"] = []

        all_usages_config = {}

        all_usages.each do |privacy_usage|

            if !privacy_usage.category.nil?
                category = privacy_usage.category.id
                all_usages_config[category] = all_usages_config[category] || {}
                all_usages_config[category]["category"] = category

                if !privacy_usage.purpose.nil?
                    all_usages_config[category]["purposes"] = all_usages_config[category]["purposes"] || []
                    all_usages_config[category]["purposes"] << privacy_usage.purpose.id

                end

                if !privacy_usage.data_protection.nil?
                    all_usages_config[category]["data_protections"] = all_usages_config[category]["data_protections"] || []
                    all_usages_config[category]["data_protections"] << privacy_usage.data_protection.id
                end

            else
                usages_config = {}
                usages_config["data_protections"] = usages_config["data_protections"] || []
                if !privacy_usage.data_protection.nil?
                    usages_config["data_protections"] = usages_config["data_protections"] || []
                    usages_config["data_protections"] << privacy_usage.data_protection.id
                end
                app_itunes_json["privacy_data"] << usages_config
            end
        end

        all_usages_config.each do |k, item|
            app_itunes_json["privacy_data"] << item
        end

    end

    app_itunes_json["app_info"] = app_itunes_json["app_info"] || {}

    platforms = ["IOS", "MAC_OS", "TV_OS", "XR_OS"]

    platforms.each do |platform|

        app_itunes_json["app_edit_version_info"] = app_itunes_json["app_edit_version_info"] || {}

        app_edit_version_info = app.get_edit_app_store_version(platform: platform, includes: 'appStoreVersionSubmission,build,appStoreVersionPhasedRelease,appStoreVersionLocalizations')

        if app_edit_version_info.nil?

            if File.exist?(File.join(app_itunes_dir, platform.downcase))
                FileUtils.rm_rf(File.join(app_itunes_dir, platform.downcase))
            end

            app_itunes_json["app_edit_version_info"].delete(platform)
            app_itunes_json["app_edit_version_info"].delete(platform.downcase)

        else

            fastlane_download_app_version_info(app_version_info: app_edit_version_info, platform: platform, app_itunes_json: app_itunes_json, app_itunes_dir: app_itunes_dir)

        end

    end

    app_itunes_json["app_info"]["app_info_localization"] = {}
    fastlane_download_app_info(app: app, app_itunes_json: app_itunes_json, app_itunes_dir: app_itunes_dir)

    File.open(app_itunes_file, "w") do |file|
        file.write(JSON.pretty_generate(app_itunes_json))
        file.close
    end

end

#fastlane_download_screenshots(temp_bundle_id: nil) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/pindo/command/appstore/getitcinfo.rb', line 186

def fastlane_download_screenshots(temp_bundle_id: nil)

    app_screenshots_dir = File.join(@app_config_dir, "fastlane/screenshots")
    app = Spaceship::ConnectAPI::App.find(temp_bundle_id)
    platforms = ["IOS", "MAC_OS", "TV_OS", "XR_OS"]

    if !File.exist?(app_screenshots_dir)
        FileUtils.rm_rf(app_screenshots_dir)
    end
    platforms.each do |platform|

        app_edit_version_info = app.get_edit_app_store_version(platform: platform)

        if app_edit_version_info.nil?

            if File.exist?(File.join(app_screenshots_dir, platform.downcase))
                FileUtils.rm_rf(File.join(app_screenshots_dir, platform.downcase))
            end
        else
            fastlane_download_app_screenshots(app_version_info: app_edit_version_info, platform: platform, app_screenshots_dir: app_screenshots_dir, over_write: @over_write)
        end

    end

end

#runObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/pindo/command/appstore/getitcinfo.rb', line 50

def run
    current_project_dir = Dir.pwd
    config_file = File.join(current_project_dir, "config.json")

    # 加载配置
    config_parser = Pindo::IosConfigParser.instance
    config_parser.load_config(config_file: config_file)
    @config_json = config_parser.config_json
    @bundle_id = config_parser.bundle_id
    @apple_id = config_parser.apple_id

    if @config_json.nil? || @config_json.empty?
        raise Informative, "配置未加载,请检查配置文件: #{config_file}"
    end

    if @bundle_id.nil? || @bundle_id.empty?
        raise Informative, "无法从配置文件中获取 Bundle ID"
    end

    if @apple_id.nil? || @apple_id.empty?
        raise Informative, "无法从配置文件中获取 Apple ID"
    end

    pindo_dir = File.expand_path(pindo_single_config.pindo_dir)
    @app_config_dir = File.join(pindo_dir, @bundle_id)
    app_itunes_dir = File.join(@app_config_dir, "fastlane")
    begin
        FileUtils.mkdir_p(File.join(app_itunes_dir))
    rescue
        # if it's already there
    end

    (apple_id: @apple_id)

    if @upload_metadata_flag
        (temp_bundle_id: @bundle_id)
    end

    if @upload_screenshots_flag
        fastlane_download_screenshots(temp_bundle_id: @bundle_id)
        valid_screenshots_html
    end

    puts "Done !!!"
end

#valid_screenshots_htmlObject



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/pindo/command/appstore/getitcinfo.rb', line 212

def valid_screenshots_html()

    app_screenshots_dir = File.join(@app_config_dir, "fastlane/screenshots")
    screenshots_path = File.join(app_screenshots_dir, "ios")
    screenshots = Deliver::Loader.load_app_screenshots(screenshots_path, true)

    app_itunes_dir = File.join(@app_config_dir, "fastlane")
    app_itunes_file = File.join(app_itunes_dir, "app_itunes.json")
    app_itunes_json = JSON.parse(File.read(app_itunes_file))

    # Validate
    options = {}
    options[:name] = {}
    options[:name]["en-US"] = app_itunes_json["app_info"]["app_info_localization"]["en-US"]["name"]
    options[:description] = {}

    app_itunes_json["app_info"]["app_info_localization"].each do |lang, data|
        options[:description][lang] = ""
    end

    html_path = Deliver::HtmlGenerator.new.render(options, screenshots, app_itunes_dir)
    system("open '#{html_path}'")
end