Class: IAPServer::AppStoreConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/iap/appstore_config.rb

Class Method Summary collapse

Class Method Details

.add_config(add_name, config) ⇒ Object



41
42
43
44
45
# File 'lib/iap/appstore_config.rb', line 41

def self.add_config(add_name, config)
			add_path = config_path + add_name
			json = config.to_json
	File.write(add_path, json)
end

.all_configsObject



33
34
35
36
37
38
39
# File 'lib/iap/appstore_config.rb', line 33

def self.all_configs
	config_path.children().map do |child|
		next if File.basename(child) == '.DS_Store'
		next unless File.file?(child)
		JSON.parse(File.read(child))
	end.reject(&:nil?) || []
end

.clear_all_configsObject



62
63
64
# File 'lib/iap/appstore_config.rb', line 62

def self.clear_all_configs
	config_path.rmtree if config_path.exist?
end

.clear_config(name) ⇒ Object



66
67
68
69
# File 'lib/iap/appstore_config.rb', line 66

def self.clear_config(name)
	path = config_path + name
	path.rmtree if path.exist?
end

.config_pathObject



6
7
8
9
10
11
12
13
# File 'lib/iap/appstore_config.rb', line 6

def self.config_path
	@config_path ||= begin
		path = Pathname.new(File.expand_path('~/.iapserver_config'))
		path.mkpath unless path.exist?
		path
	end
	@config_path
end

.default_configObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/iap/appstore_config.rb', line 15

def self.default_config
	configs = all_configs
	return configs.first if configs.size == 1
	raise "你还没有配置AppStore Connect的密钥参数,执行`iapserver config -a 'xxx'`添加。".red if configs.size == 0

	list_configs
			num = input("有多个配置,请输入序号选择合适的配置:")
			raise "序号输入有误".red if num.empty?

			raise "序号输入有误".red unless (0...configs.size) === num.to_i - 1
			return configs[(num.to_i - 1)]
end

.input(message) ⇒ Object



28
29
30
31
# File 'lib/iap/appstore_config.rb', line 28

def self.input(message)
    print "#{message}".red
    STDIN.gets.chomp.strip
end

.list_configs(show_more = false) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/iap/appstore_config.rb', line 47

def self.list_configs(show_more=false)
	configs = all_configs
	index = 1
	configs.each do |config|
		name, key, kid, iss, bid = config['name'], config['key'], config['kid'], config['iss'], config['bid']
		puts "#{index}) #{name}"
		puts "  key: #{key}" if show_more
		puts "  kid: #{kid}" if show_more
		puts "  iss: #{iss}" if show_more
		puts "  bid: #{bid}" if show_more
		index += 1
	end
	return configs
end